Sometimes it’s a little bit of a pain to constantly type your password every time you log in to a server. If you are pushing code, moving files, backing up data, typing your password at each step of the way can be annoying. By setting up public/private keys between your local machine and the remote server you can eliminate that step.

Type the following on the local machine:

ssh-keygen -t dsa

You will see the following after typing the command above. You can press enter and skip the question when you’re asked for a file name, but for the passphrase try not to leave it blank:

Generating public/private dsa key pair.
Enter file in which to save the key (/Users/amitsamtani/.ssh/id_dsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/amitsamtani/.ssh/id_dsa.
Your public key has been saved in /Users/amitsamtani/.ssh/id_dsa.pub.

If you did not change the file name copy the contents of ~/.ssh/id_dsa.pub to the remote servers ~/.ssh/authorized_keys file. Append the contents to the end of the file.

After this is complete, on your first attempt to ssh into the remote server you will be presented with a prompt by OS X to type the id_dsa.pub passphrase. Type the passphrase into the prompt and save it in your keychain.

Now you can log in to the server without the need of the password.