In this tutorial I will show you how to enable remote SSH with password-less login in Ubuntu using SSH keys.
INSTALL SSH
Once you are logged on to your Ubuntu instance, launch Terminal if in GUI or just issue the command below (server β without GUI):
sudo apt-get install openssh-server
Enter your password then press Enter
Verify the packages that will be installed, then type y for yes and press Enter
That is it! You now have a fully functional SSH server that will accept remote SSH logons with usernames and passwords.
Lets give it a quick shot. Here I have two instances (ubuntu – on the left / ubuntu-b on the right). Both instances have SSH installed on them following the same steps above. I will SSH from ubuntu-b (right) to ubuntu (left)
replace “hyperexpert” with your username and “10.0.1.29” with your host server IP address
ssh hyperexpert@10.0.1.29
ubuntu (left) has accepted my connection once I entered my user’s password.
Type exit then press Enter to logout from your SSH session.
Enable password-less logins with SSH keys
Now, in order to establish the same connection again without requiring a user’s password but instead use SSH Keys, we will need to generate a new key on our (ubuntu-b on the right) and copy it over to (ubuntu – on the left).
On the instance where you will be making the SSH connection from (ubuntu-b on the right), type
ssh-keygen
Press Enter leaving everything blank for all the prompts until the end. Once all done, assuming no errors, you have created your SSH key that needs to be copied over to the host instance where you will be making the connection to (ubuntu – on the left).
To copy your generated key to your host instance, type
replace “hyperexpert” with your username and “10.0.1.29” with your host server IP address
ssh-copy-id -i hyperexpert@10.0.1.29
Enter the user’s password for your host instance
If all goes well, you will get a confirmation saying that your key is added
Lets try our SSH login again and make sure this time we don’t get a password prompt. Type
replace “hyperexpert” with your username and “10.0.1.29” with your host server IP address
ssh hyperexpert@10.0.1.29
If your key copied successfully, you will not get a password prompt and will be connected to your host instance right away.
Type exit and press Enter to logout of your SSH session. Enjoy π