Multiple SSH keys for different GitHub accounts

Today we’ll show you how to set up multiple SSH keys for different GitHub accounts. When you need to work with the two different GitHub accounts and those accounts need to be set up with an SSH key then you might need to do some settings in config of the SSH to manage multiple GitHub accounts on a single machine.

Manage multiple SSH keys for different GitHub accounts

  1. Generating a new SSH key and adding it to the ssh-agent
  2. Adding a new SSH key to your GitHub account
  3. Modify the SSH config
  4. Manage the remote URL of the repository

1. Generating a new SSH key and adding it to the ssh-agent

To clone a repository using SSH URL then we have to first generate a new SSH key and add it to the ssh-agent. Refer to the link below for more information.

Generating a new SSH key and adding it to the ssh-agent

You can set up the configuration based on the installed OS.

Note: Please enter a different key name based on the repository name so you can identify it later.

Just assume that we have created two different keys that are listed below.

2. Adding a new SSH key to your GitHub account

Now, let’s link those keys with the GitHub account. For that you have to copy the SSH key and add it in your account settings. Refer to this link for step by step information.

Adding a new SSH key to your GitHub account

3. Modify the SSH config

So now the most important part is to modify the SSH config to manage multiple GitHub accounts using SSH on a single machine.

Jump into the .ssh folder to create/modify a config file. If you can’t see the config file in the folder then simply create it.

Check out the following lines that I have written into the config file.

config

In the above code, we have set the two different values (github.com-work for work repository and github.com-personal for personal repository) for Host to be used to add/update the remote origin of the GitHub repositories.

4. Manage the remote URL of the repository

At last, we have to clone a repository using SSH URL but we need to slightly update the repository host name as mentioned above.

To clone work repository:

To clone personal repository:

If you have already cloned the repositories then run the following command to update the remote URL.

To change remote URL for work repository:

To change remote URL for personal repository:

Check out more articles on Git.

That’s it for today.
Thank you for reading. Happy Coding..!!

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *