Click here to Skip to main content
13,089,504 members (78,273 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

3.5K views
2 bookmarked
Posted 30 Jan 2014

Convenient Way to Manage Multiple SSH Keys

, 30 Jan 2014
Rate this:
Please Sign up or sign in to vote.
This is a convenient way to manage multiple SSH keys

I used to specify per-host entries in ~/.ssh/config file, but I recently found an excellent and automatic solution:

Place each key in a directory named after its host and user, like:

~/.ssh/ids/github.com/git/id_rsa
~/.ssh/ids/myhost/me/id_rsa
~/.ssh/ids/myhost/mygf/id_rsa

Then set up ~/.ssh/config file this way:

IdentityFile ~/.ssh/ids/%h/%r/id_rsa
IdentityFile ~/.ssh/id_rsa

Now once you ssh me@myhost (or ssh mygf@myhost), the correct key will be used. Adding a new key can now be done by simply creating appropriate folders and copying the keys there.

While it works "out of the box" on Linux, things get a bit harder (but also a bit more secure) on Mac OS X: if your key requires a passphrase (which it should), then ssh client won't prompt for it, expecting to get it from ssh-agent (this is described in detail here).

For some reason which I considered not worth investigating, OS X's ssh-agent did not want to pop up its nice and very secure message box. I worked around this by adding the needed keys manually via ssh-add (like, ssh-add <path-to-key>). However, I'm not satisfied with this solution and will probably need to take a second look at it, especially if agent doesn't start to work after I reboot the Mac.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

RCL_SPD
United States United States
No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170813.1 | Last Updated 30 Jan 2014
Article Copyright 2014 by RCL_SPD
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid