Votes: 0Posted On: Oct 10, 2017 09:42:58
SSH keys provide a secure way for connecting to a remote server. We know that SSH is one of the more important methods used to connect to a remote server. The SSH keys are used to establish a secure connection between the local and remote host. After setting up the SSH key, you can connect to the remote server without the password as the SSH key is secure enough and troublesome to decipher. In this article, we will discuss the setting up of SSH key pair on Ubuntu version 14.04.
Here are the steps to establish a secure connection through the SSH keys.
Create the RSA Key Pair
1. Use the following command to create an SSH key pair on your system which you will later copy onto the remote server.
ssh-keygen -t rsa
2. The system will then prompt you to enter the location in which you want to save the key. If you press enter without entering any location, it will store the key in the default path i.e "/home/current_user/.ssh/id_rsa".
3. Once the file is saved, a prompt will be displayed asking for a passphrase. The passphrase is another level of authentication and you will have to enter the passphrase every time you establish a connection. If you don't want a passphrase, leave the field empty.
The public key is now located in "/home/current_user/.ssh/id_rsa.pub" and the private key in "/home/current_user/.ssh/id_rsa".
Copying the SSH key to remote host
You know have to copy the SSH public key to the remote host. This can be achieved in multiple ways.
1. You can use the following command to copy the key to the remote host.
2. You can also use ssh to copy the key to the desired directory.
cat ~/.ssh/id_rsa.pub | ssh username@IP_address "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Disable Password for Root Login
1. The SSH configuration file is stored in "/etc/ssh/sshd_config". Please edit the file with any editor of your choice like nano, vi etc.
We are using the vi editor in this case.
sudo vi /etc/ssh/sshd_config
The file includes a line "PermitRootLogin". We have to modify it to ensure that users can only connect with their SSH key. Modify it as "PermitRootLogin without-password".
2. Restart the SSH services for the changes to take effect.