SSH login without password using public key authentication

August 23, 2012

On Computer A
Create the public and private keys using the command ssh-keygen

[root@computerA .ssh]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/
The key fingerprint is:

Note: If you do not enter any passphrase by leaving the field blank, then you will not be prompted for the passphrase when login in to the remote computer.

Check to see if the files have been created.

[root@computerA .ssh]# ls -l /root/.ssh
total 16
-rw——- 1 root root 409 Aug 23 11:38 authorized_keys
-rw——- 1 root root 1679 Aug 23 11:40 id_rsa
-rw-r–r– 1 root root 409 Aug 23 11:40
-rw-r–r– 1 root root 1212 Dec 12 2011 known_hosts

Copy the contents of the file to the remote computer you wish to login to. This file is your puiblic key. Simply cut and paste the content of the file to the file /root/.ssh/authorized_keys on the remote computer. Append public key to the file authorized_keys, or create the file if it does not exits.

To simplyfy things you can also use the command ssh-copy-id to copy the public key to the remote computer. See example below.

[root@computerA .ssh]# ssh-copy-id -i ~/.ssh/ ComputerB
root@ComputerB’s password:
Now try logging into the machine, with “ssh ‘ComputerB’”, and check in:


to make sure we haven’t added extra keys that you weren’t expecting.

You are done. Try login in to the computerB from computerA.

Be Sociable, Share!

Tags: , ,

Leave a Reply