Generate SSH Keys / Passwordless SSH logins

In order to ssh to another machine you first need to generate ssh keys.  To do this follow the steps below:

All of our files will be located in your /home/.ssh.  By default, there you may only have a known_hosts file, which we will be using later.

Generate SSH Keys

As the user you want to generate keys for, run ssh-keygen.  This creates my public and private rsa keys as seen in the screenshot below.

SSH key creation
ssh-keygen creates rsa public and private in /home/.ssh

Passwordless SSH Login

In order to allow passwordless logins from another machine, we have to copy the contents of id_rsa.pub  on our host machine, into /home/.ssh/authorized_keys on the destination machine we want to login to.  In this example, I want to be able to login from the machine called “First”, into the machine called “Second”.

On the source machine, cat /home/.ssh/id_rsa.pub

On the destination machine, create authorized_keys in /home/.ssh.

copy the contents of the id_rsa.pub from the source machine into the authoized_keys file on the destination machine.  In the image below, the left window is the source machine, the right window is a vim of .ssh/authorized_keys

passwordless login using id_rsa.pub
Left: id_rsa.pub on source machine. Right: .ssh/authorized_keys on destination machine

Set the 640 permissions on authorized_keys using chmod 640 athorized_keys.  A summary of the things required to do on the destination host can be seen in the screenshot below:

using athorized_keys to allow passwordless logins
Creating authorized_keys, copying id_rsa.pub into it, and setting premissions

Now I can login without entering my password!

ssh without a password
no need to enter my password when ssh’ing into the destination server!

 

 

 

Sidebar