Well, to be “correct” the title of this should have been “how to add your key to the list of authorized public keys on a remote or local linux machine”, but being a newbie like myself, I would not have known to search for it. If I wanted to find out about logging in automatically to a remote machine using a generated public key, I myself would have used “Passwordless SSH” – so there you go.
To get started, I’ll assume that you have OpenSSH set up (it’s setup by default… well usually) and that your remote machine has OpenSSH-server set up.
If not, then do the following on the remote machine:
$ sudo aptitude install openssh-server
The guide
This is just a quick guide because there really isn’t anything to it.
Step 1: Create your public OpenSSH key with:
$ ssh-keygen -t dsa
Step 2: Transfer the generated key to the machine you want Passwordless SSH access to with scp (in this example your home directory on the remote machine)
$ scp /home/<username/.ssh/id_dsa.pub remote address:/home/<username>/
Step 3: Connect through SSH to the remote machine and enter your password.
$ ssh <remote address>
Step 4: Append the key you have just transfered to the authorized public keys called “authorized_keys” file in the hidden ssh directory for the account you want access to.
$ cat /home/<username>/id_dsa.pub >> /home/<username>/.ssh/authorized_keys
Step 5: Remove the source public key from the remote machine. So people don’t stumble upon your public key.
$ rm /home/<username>/id_dsa.pub
And that’s it. Your public SSH key is stored in the authorized_keys file so the next time you log in
$ ssh <remote address>
It will not ask you for a password but automatically log you in.

