Friday, February 25, 2011

Quickly add your public key to an authorized keys file

This will add your public ssh key to an authorized keys file on a remote server for passwordless login.
1. Generate key on local machine:
ssh-keygen -t dsa
In your local machine:
$cd .ssh
$ls
authorized_keys id_dsa id_dsa.pub id_rsa id_rsa.pub known_hosts
$more id_dsa.pub

2. Ensure that the remote server has a .ssh directory
$ cd ~/.ssh
$ ls
authorized_keys id_rsa id_rsa.pub known_hosts
$vi authorized_keys

3. Add your public key into remote server.
Now you can ssh to the remote server without entering your password.
Keep in mind that all someone needs to login to the remote server, is the file on your local machine ~/.ssh/id_rsa, so make sure it is secure.