SSH login without password

Are you are tired of entering the password every time you log in? Or your script needs to perform tasks on another machine? Then this tutorial is for you, for only $99. But wait... j/k

Create RSA key

For this purpose you will need to use the ssh-keygen command without any parameters:

# ssh-keygen

You will be asked to enter a file for the key and a passphrase. The defaul file is id_rsa, so if you want you can hit enter to leave it as is. Do the same for the passphrase. At the end you should get an output similar to this one:

# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ana/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/ana/.ssh/id_rsa.
Your public key has been saved in /home/ana/.ssh/id_rsa.pub.
The key fingerprint is:
87:5a:f3:43:d6:ad:cc:55:57:8b:ca:e9:25:22:a9:12 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|  .oo... ..      |
|  o.  o.o. .     |
| oo.  o.oo .     |
|.  o. o-= .      |
|  . ..*.E +      |
|   . o.. +       |
|      .....      |
+-----------------+

As you can see, a new file called 'id_rsa.pub' has been created. This is the file that we need to transfer to the other machine. We can achieve this by using the ssh-copy-id command:

# ssh-copy-id -i ~/.ssh/id_rsa.pub machine-b

This will append the keys from 'id_rsa.pub' to the '/home/marija/.ssh/authorized_keys' on machine-b. You can do the same thing with just copying the file to the other machine with scp command:

# scp /home/ana/.ssh/id_rsa.pub [email protected]:/home/marija/.ssh/authorized_keys

That's it. Now, next time when you login you wont be asked for password.

Note: If above configuration don't work for you, try this:

  • Change the 'authorized_keys' to 'authorized_keys2' - Because of different SSH versions
  • Check if '.ssh' directory has 700 permission.
  • Check if 'authorized_keys2' file has 640 permission.

- Posted by Eva to Linux