Can I have multiple ssh keys in my .ssh folder?

You can modify the file ~/.ssh/config to use different identity file for different servers. Edit the ~/.ssh/config in your favorite editor and add an entry that is appropriate for your situation like so:

Host *
IdentityFile ~/.ssh/id_rsa

Host *.github.*
IdentityFile ~/.ssh/github_id.rsa

Host *.someother.com
IdentityFile ~/.ssh/someother_id.rsa

The first part above sets the defaults for all hosts and the other sections overrides what should be used for each of the hosts matching the patterns. If you have a different username for each of the hosts, then you can add a User key followed by the username on the remote to the section.


Yes you can have different ssh keys. There's very good documentation on the GitHub Help site at Help.GitHub - Multiple SSH Keys. Essentially you will be using ssh-add to add the extra keys so that the agent can utilize them. Then you set up the ssh hosts config so that any ssh connections to different domains will be looked up here and the appropriate key will be used. good luck!


You can set up multiple ssh keys for any site having multiple user accounts

Below is the example I used to follow in my development for GitHub.com

Config file example

#Personal account
 Host github.com-<personal-account-name>
 HostName github.com
 User git
 IdentityFile ~/.ssh/id_rsa_personal
 IdentitiesOnly yes



#Organization account
 Host github.com-<organization-name>
 HostName github.com
 User git
 IdentityFile ~/.ssh/id_rsa_work
 IdentitiesOnly yes

At the time of adding a new origin

For Personal account

git remote add origin [email protected]<personal-account-name>:<personal-account-name>/<repo-name>.git

For Organisation account

git remote add origin [email protected]<organization-name>:<organization-name>/<repo-name>.git

Hope it helps.

Tags:

Ssh

Mac