Saturday, 13 February 2016

How to connect via SSH without a password?


Most of the people still uses passwords when connecting via SSH. It's far from the optimal way to do it. In general, passwords are insecure and easy to forget. But there is an easier and more secure way of connecting via SSH to remote sites. This method also allows you to configure a bootstrap SSH connection, very useful for example for backup. What am I thinking about? RSA keys of course. How to use them? It's very simple!



First, generate the new RSA key on your local system:

ssh-keygen -t RSA

Now, you have two files in ~/.ssh directory: id_rsa and id_rsa.pub. The first contains your private key that should stay in this directory. And the second contains your public key that you should place on the remote sites in the ~/.ssh/authorized_keys.

Note, that if you've never used RSA keys you should propably do mkdir ~/.ssh on the remote site and that authorized_keys file could contain several different RSA keys.