Linux / RedHat /CentOS / Ubuntu / Debian /Solaris : Quick Howto SSH login without password (SSH Keys)

2

I do it on a regular base but everytime need to go back to my cheat sheet to jumpstart my memory.

Whenever I need to reach one system from another without asking me for a password:

First login on Server Alpha as the user desired to have the password free ssh and generate a pair of authentication keys. I would advise not to enter a passphrase but I leave that to you:

user@Alpha:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
Created directory '/home/user/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:

xx:xx:xx:xx:xx:xx:xx:xx:... user@Alpha
The key's randomart image is:
.....xxxxxx.x.x.x..x.xx.whatever

We need to create on the Server Bravo a user’s home subdirectory .ssh. (The directory may already exist, which is ok):

user@Bravo:~> mkdir -p ~/.ssh

We now copy the key over from Alpha to Bravo

user@Alpha:~> scp ~/.ssh/id_rsa.pub user@Bravo:~/.ssh/

Finally we append the new public key

user@Bravo:~> cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

From now on you can log into Bravo from Alpha without any password:

user@Alpha:~> ssh user@Bravo

Sidenote: please make sure of the following

  • Change the permissions of .ssh to 700
    # chmod –r 700 ~/.ssh

 

Leave a Reply