~1 min read

Tags

The basis of using ssh without typing your password is public key based authentication. You need to generate a pair of public/private keys for this.

Firstly, generate your public/private keys using ssh-keygen

% ssh-keygen -t rsa

You must use the -t option to specify that you are producing keys for SSH using RSA. This will generate your id_rsa and id_rsa.pub in the .ssh directory in your home directory.

Copy ~/.ssh/id_rsa.pub to the server.

% scp ~/.ssh/id_rsa.pub user@host:.

On the server run the following commands:

% cat id_rsa.pub >> ~/.ssh/authorized_keys
% chmod 644 ~/.ssh/authorized_keys

Thats it! Easy as 1,2,3.

Now you should be able connect to the server via ssh without being challenged for a password.

If for some reason, it is not working for you, you may also need to do one of the following things to get it working:

  • Put the public key in .ssh/authorized_keys2
  • Change the permissions of .ssh to 700
  • Change the permissions of .ssh/authorized_keys2 to 640