HOWTO: SSH Seamlessly Between OS X and Remote Linux (No Password/phrase Prompt)

Posted on August 11, 2007

Note: security freaks, please do not read the following. It might make your eyes bleed. (or, feel free to propose an alternate solution in the comments)

The main potential security implication is:

If your mac is somehow compromised (an attacker gains access to your private keyfile located at ~/.ssh/id_dsa) then you will need to quickly kill access to that keypair on your remote servers.

Other than that, this setup is pretty slick if UR SSHN TO LOTS OF LEENUX BOXEN. Ahem.

Generate the Keypair Locally

On your OS X machine:

  ssh-keygen -b 1024 -t dsa

Just hit enter for all of the defaults, including a BLANK passphrase. (otherwise you would have to enter it each time you SSH’d to a remote box, thereby defeating this whole exercise, no?)

Ensure Remote Server has a ~/.ssh/ folder

  ssh deploy@remote.com
  mkdir ~/.ssh/

Next copy ~/.ssh/id_dsa.pub to the remote server. Example:

  scp ~/.ssh/id_dsa.pub deploy@remote.com:.ssh/authorized_keys

Try logging in sans password:

  ssh deploy@remote.com

It should now let you in without entering a password or passphrase!

Set .ssh Permissions on Remote Linux Server

On the remote linux box, do a:

  chmod 700 ~/.ssh
  chmod 600 ~/.ssh/*


Enabling this setup for other Linux Boxes

Do NOT overwrite your existing key pair (default locations) with ‘ssh-keygen’ on OS X because then all your other servers will not recognize the new key!

You can generate a new pair for each separate linux box you want to connect to, just follow the previous ssh-keygen instructions but place the output in a new location.

To use the same public/private keypair on each box (say it’s just you who’ll be admin’ing em):

  scp ~/.ssh/id_dsa.pub foo@another-server.com:.ssh/authorized_keys

Again, Try Logging in Sans Password

  ssh foo@another-server.com

Should now let you in without entering a password or passphrase!

You also might need to follow the directory setup/permissions guide as outlined above.