Text to Search... About Author Email address... Submit Name Email Adress Message About Me page ##1## of ##2## Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec



6/newsticker//recent

404

Sorry, this page is not avalable
Home

Latest Articles

How To Set Up an SSH Key For Secure Connections

 

You can use a secure key for SSH, instead of a password.


The Secure Shell Protocol (SSH) is perhaps the most well-known means to make a secure connection between a client machine (your laptop, phone or desktop) and a remote server in an office, data center or in your home network. You’ll likely use SSH if you want to get to the command line on your web hosting service or a headless Raspberry Pi. SSH is available in some form for nearly every operating system, and often it is integrated into the OS.


Most servers give you a choice of connecting to SSH via a password or via SSH keys, which are more secure. The SSH key method uses cryptographically-generated public and private keys to create an encrypted connection between devices.


Our public key is stored on the remote machine and a private key is stored on our machine. The two SSH keys are required to make a secure connection. Keys can also be used with passphrases to add another level of security, but they can also be used without, for example in automated processes.


Preparing the Remote Server for SSH Keys

Our remote machine can be in a data center run by a web hosting service, our office or home. Typically Linux servers such as VPS and cloud hosting will have SSH running by default, using passwords for secure logins. If this is not the case, you will need to enable SSH via the control panel for your VPS / cloud service. If you are using a home server, then it is possible that it may not be installed. If that is the case, follow these steps before moving onwards.


1. Open a terminal and check for a running SSH service on the machine. If the SSH service is running it will return Active: active (running).


sudo service ssh status

2. On the physical server, open a terminal and install OpenSSH Server. You will need to be sat in front of the machine to issue these commands.

sudo apt update

sudo apt install openssh-server


3. Start the SSH service.

sudo service ssh start


4. In your home directory create a hidden directory called .ssh.

mkdir .ssh


5. Close the connection by pressing CTRL+D or typing exit and pressing Enter.


Copying the Public Key to the Remote Server

The public key is stored on our remote server, and it interacts with the private key on our trusted machine to form a secure connection. In order to get the public key to our server we need to securely copy (scp) the file across.


1. In a Command Prompt use the scp command to securely copy the id_rsa.pub to your home directory on the remote server. You will need to know the IP address or hostname of the remote computer. In our example we copied the file to [email protected]:/home/testuser/

scp id_rsa.pub user@hostname:/home/username


2. SSH into the remote computer.

ssh user@hostname


3. Verify that the id_rsa.pub file is present in your home directory.

ls *.pub


4. Copy the contents of the file into a new file in the .ssh directory. Using the cat command we send the contents to the file, authorized_keys using a pipe that appends the data to the file (>>).

cat id_rsa.pub >> .ssh/authorized_keys


5. Close the SSH connection by pressing CTRL + D or by typing exit.


6. Reconnect via SSH to the remote computer. If you created a passphrase for your SSH key, you will be prompted for it.


via tomshardware

unixlegion.com uses cookies to improve your experience. I agree