Using SSH Agent With Mac OS X

Using SSH Agent With Mac OS X

SSH agent allows a user to enter their passphrase(s) for unlocking various SSH keys once at the start of a session to unlock the keys and from then on for the duration of the session the user no longer has to enter the pass phrase(s).

Conventionally setting up SSH agent for use is a bit of a pain as it has to be run before the user session is started.

Mac OS X Leopard modifies SSH agent so that it is started via the Mac OS X launchd service on demand (i.e. it will be launched on first use).

Going even further, Mac OS X Leopard modifies the SSH tools to support storing the pass phrases in the user's Keychain. This means that if the user chooses to store their pass phrase(s) in the Keychain they never need to enter their pass phrase again once they have added it to their Keychain.

Enabling SSH Agent To Launch On Demand

This is important only if you're on Mac OS X Leopard 10.5.1 or below. If you're on anything newer, you no longer need to do this, so feel free to skip this step and go straight onto Storing Passphrases in the Keychain below.

To enable SSH agent starting automatically on demand (this happens by integrating SSH agent with launchd) you need to open a terminal and run:

$ sudo touch /var/db/useLS

Then you need to reboot. (Yes, you really need to reboot, there is no way around it!)

From now on, whenever you cause something needing the SSH agent to run, the SSH agent will automatically be launched if it is not running already.

Storing Passphrases in the Keychain

To store the passphrase for your default key in the Keychain open a Terminal and run:

$ ssh-add -K

And to store the passphrase for a different key run:

$ ssh-add -K /path/to/private/key/file

When prompted for your passphrase enter it and that is it.

You will never need to run ssh-add nor enter your passphrase again.

Rob Montero

Rob Montero, Drupal Association Individual Member

Roberto Montero Ortiz is an individual member of the Drupal Association, which fosters and supports the Drupal software project, the community and its growth. He also has an active role in the Drupal Community in Costa Rica and regularly contributes to Drupal Camps held in Latin America.

Rob Montero, Acquia Certified Developer 2014   Rob Montero, Certified Developer Back End Specialist 2015Rob Montero, Acquia Certified Developer Front End Specialist

Rob is also an Acquia Certified Developer, awarded with the Grand Masters title after completing his third certification within a year. 

Zend also certifies Rob's knowledge of PHP OOP skills, but at this point this block is getting a bit presumptious. Suffice it to say, Rob is competitive and competent. He's also a nice guy all around.

Drupal Latin America

Rob Montero is a proud sponsor and mentor of young Drupal talent of the Costa Rican Drupal Users Group and entrepreneur at Drupal Latin America


Get in touch

  • Rob Montero
    Ave Popocatepetl 435 B 504
    Sta Cruz Atoyac, Benito Juarez
    Ciudad de México, 03310 
  • (858) 952 0762
Signup to our newsletter: