This content originally appeared on DEV Community and was authored by Shahid Ullah Khan
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)
Step 1 — Installation
Run below command to install ssh-keyman package.
$ npm i -g ssh-keyman
Step 2 — Initialisation
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.
Step 3 — Create environment for your account.
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.
Similarly, Create another environment for our another github account githuby.
$ ssh-keyman -c githuby
Now we’ve both environments setup for githubx and githuby.
Step 4 — Setup SSH Keys.
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
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.
Repeat the above process for githuby account.
I.e
- Switch to githuby environment
$ ssh-keyman -s githuby
sh
- 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.
Step 5 — Start using and switching.
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.
This content originally appeared on DEV Community and was authored by Shahid Ullah Khan
Shahid Ullah Khan | Sciencx (2021-07-03T20:58:53+00:00) Easy way to manage multiple git accounts using ssh. Retrieved from https://www.scien.cx/2021/07/03/easy-way-to-manage-multiple-git-accounts-using-ssh/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.