Multiple SSH Keys on GitHub

Multiple SSH Keys on GitHub

Do you have multiple GitHub accounts you need to access from one computer via SSH? Learn how to set up multiple ssh keys for GitHub. Recently I ran into an issue I’d never had before. I wanted to access more than one GitHub account from the same machine using SSH. I needed to figure out how to use multiple SSH keys on GitHub from one computer

Recently I ran into an issue I’d never had before. I wanted to access more than one GitHub account from the same machine using SSH. I needed to figure out how to use multiple SSH keys on GitHub from one computer.

In this case it was due to my new job having our code hosted on GitHub and wanting to still access my personal account. This problem isn’t isolated to GitHub, of course. Pretty much any cloud-based system with SSH support could suffer this same issue.

Generating the SSH Pair

Presumably, you already know how to generate a key. Here’s GitHub’s documentation on generating ssh key pairs. In this case, however, since you probably already have one called id_rsa, just make sure you give the new one a different filename. For my example let’s pretend I’m creating one for work and calling it id_rsa_work.

Once you’ve generated the new pair you can associate it to the GitHub account you don’t already have a key associated with. See GitHub’s documentation on doing that in case you’ve forgotten.

Now before I go any farther on my post, I want to call out kudos to Oanh Nguyen and his gist. It’s what got me 99% of the way there.

Edit (or create) ssh config

Navigate to your ~/.ssh folder. In Windows, this is found within c:\Users\[username]\.ssh. From bash you can simply access it via cd ~/.ssh. If you don’t have a config file, you can issue the touch config command (or Windows command prompt, simply copy NUL config).

Within this config file you’ll need a couple host mappings. One for each account. Something like the following:

## Default github account: personal
Host github.com
   HostName github.com
   IdentityFile ~/.ssh/id_rsa
   IdentitiesOnly yes

## Other github account: work
Host github-work
   HostName github.com
   IdentityFile ~/.ssh/id_rsa_work
   IdentitiesOnly yes

Depending on the computer, you may want “work” to be your default instead of personal. Totally personal preference here.

Now I have multiple SSH keys I can use on GitHub!

Add ssh private keys to agent

In the examples I found, I actually was able to skip this step. I’m uncertain if it is because it automatically added it to my ssh-agent or what. All I know is that I could skip it. I’m including it for good measure anyway.

programming git ssh

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Best Practices for Using Git

Git has become ubiquitous as the preferred version control system (VCS) used by developers. Using Git adds immense value especially for engineering teams where several developers work together since it becomes critical to have a system of integrating everyone's code reliably.

How to Get Started with Parallel Programming in Git in Under 2 Minutes

There are many Git tips and best practices available on the internet that can help you in your day to day activities. You can save you valuable time, and stay productive with best practices and you can improve your workflow. One of the cool things in the Git is to do parallel programming.

Do You Know the Difference Between Git Merge and Git Rebase

In this article we’ll be discussing git merge and git rebasecommands and when we should use them. git rebasedoes the same job as a git mergethat is merging the changes from one branch to another branch. The difference is that they do it very differently.

7 Best Practices in GIT for Your Code Quality

Git plays a significant role in software development. It allows developers to work on the same code base at the same time. Check out 7 best practices for Git.There is no doubt that Git plays a significant role in software development. It allows developers to work on the same code base at the same time. Still, developers struggle for code quality.

Git Rebase Tutorial and Comparison with Git Merge

In this article, I will explain to you a few differences between git merge, git rebase, and the git interactive rebase.I will tell a bit about what pros...