23
Easy way to manage multiple git accounts using ssh
If you’re having problems managing different ssh keys for your different git accounts, This article is for you! follow below steps to do it easily.
Requirements: Nodejs, Npm
You will need to install and use npm package called ssh-keyman. (Click here to view docs)
Run below command to install ssh-keyman package.
$ npm i -g ssh-keyman
Now initialise ssh-keyman using below command
$ ssh-keyman -i
By running above command, this package will setup everything up in your system. It will create a default environment in your system & copy your current ~/.ssh/ content to default environment.
Now let’s assume we‘ve two different repositories from two different github profiles githubx and githuby.
Now let’s create two environments, One for githubx and other for githuby.
$ ssh-keyman -c githubx
Above command will create a profile called githubx in your system.
![](https://res.cloudinary.com/practicaldev/image/fetch/s--35CA9ufq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/32dgjae4izx4vx61d1y6.png)
Similarly, Create another environment for our another github account githuby.
$ ssh-keyman -c githuby
![](https://res.cloudinary.com/practicaldev/image/fetch/s--Pe64cgI9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ec5am3x13batnbsl8ug9.png)
Now we’ve both environments setup for githubx and githuby.
Let’s now create ssh key for your githubx account. For that we need to switch to githubx environment.
To switch to githubx environment run:
$ ssh-keyman -s githubx
![](https://res.cloudinary.com/practicaldev/image/fetch/s--9MqHCaIG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tno94c3qwv1145wcj50h.png)
Now we’re in githubx environment, Let’s generate ssh keys for githubx.
$ ssh-keygen -t rsa
once the key is generated, use that key in your GitHub account, copy contents of ~/.ssh/id_rsa.pub and paste it in github’s ssh key section.
![](https://res.cloudinary.com/practicaldev/image/fetch/s--aWeqhMGc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lzdp2kn2x6wmzs7png1x.png)
Repeat the above process for githuby account.
I.e
- Switch to githuby environment
$ ssh-keyman -s githuby
- Generate key for githuby environment.
$ ssh-keygen -t rsa
- Similarly login to githuby account in the browser and add the contents of ~/.ssh/id_rsa.pub to github create key’s key section.
So, If you want to work in repos from githubx account, simply switch to githubx environment using
$ ssh-keyman -s githubx
Now when ever you push or pull the code from git, keys for githubx will be used.
Similarly if you want to work in repos from githuby account, simply switch to githuby environment using
$ ssh-keyman -s githuby
And when ever you push or pull code from git, keys for githuby will be used.
23