Permanently Add SSH key ssh-add

Recently on my Mac I wanted to add a second SSH key to my authentication agent. Using the ssh-add command I was able to do just that until I restarted my computer. To add the key each time I start up a new terminal session I just added

ssh-add ~/.ssh/ec2.pem > /dev/null 2>&1

to my .profile file located at ~/.profile

The last part of the command is to route the output of the command to dev null so I don’t see it when I open up terminal.

 > /dev/null 2>&1

MikeGrace: A 25 year old Geek that loves his wife and enjoys tech, photography, outdoors, and his motorcycle.

Discussion

  1. Krinkle says:

    Thanks!

    A while ago I added a key and couldn’t figure out what had changed. This did the trick.

    However I have since changed to a different technique that I like better. in the ~/.ssh/config file you can reference the key files you want to save permanently.

    See also:
    http://stackoverflow.com/questions/3466626/add-private-key-permanently-with-ssh-add-on-ubuntu

  2. deg0nz says:

    Sorry, I misspelled the command in the first post.. that one is right:

    You can add the keys (and their passphrases) to your keychain with the command

    ssh-add -K /path/to/your/keyfile/key

    The -K attribute adds your key permanently to the keychain and they are available after reboot. This is better for keys with passphrases, because you don’t have to enter the passphrases everytime you start a new terminal session. (I tested with osx 10.9.1)

Leave a Comment