sobota, 20 sierpnia 2011

SSH login using keys

If you login on some remote ssh server often, you should consider using ssh keys to login without authorizing with password every each time. To achieve that goal server you want to login to need to know your local account and then let you in without asking for password. So first of all we need to generate key to identify local account:

ssh-keygen -t rsa

You should not enter any passphrase. Now you should have ~/.ssh/id_rsa.pub file (it's a default file, you could change the path of course) that is your public key that will be seen from the outside (kind of security passage ;)). So you need to put that key on the server, so it could identify your account. To do it you should place content of your local id_rsa.pub to the ~/.ssh/authorized_keys on the server (if this file does not exists - create it, f it exists do not erase it, just append your key on the end of the file - you can access you server's account via public keys from many remote accounts if you want to).
To copy your key to the server you can use copy & paste if you use some gui or use "oldschool" method:

cat .ssh/id_rsa.pub | ssh server_login@server_address 'cat >> .ssh/authorized_keys'

After that you should be able to login on the server without any password. It is also very useful if you have some other services on the server that use ssh protocol - git is a good example.