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 …


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.

Create githubx environment

Similarly, Create another environment for our another github account githuby.

$ ssh-keyman -c githuby

Create githuby environment

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

Switch githubx environment

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.

Github add key

Repeat the above process for githuby account.
I.e

  1. Switch to githuby environment
$ ssh-keyman -s githuby


sh

  1. Generate key for githuby environment.
$ ssh-keygen -t rsa
  1. 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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Easy way to manage multiple git accounts using ssh." Shahid Ullah Khan | Sciencx - Saturday July 3, 2021, https://www.scien.cx/2021/07/03/easy-way-to-manage-multiple-git-accounts-using-ssh/
HARVARD
Shahid Ullah Khan | Sciencx Saturday July 3, 2021 » Easy way to manage multiple git accounts using ssh., viewed ,<https://www.scien.cx/2021/07/03/easy-way-to-manage-multiple-git-accounts-using-ssh/>
VANCOUVER
Shahid Ullah Khan | Sciencx - » Easy way to manage multiple git accounts using ssh. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/07/03/easy-way-to-manage-multiple-git-accounts-using-ssh/
CHICAGO
" » Easy way to manage multiple git accounts using ssh." Shahid Ullah Khan | Sciencx - Accessed . https://www.scien.cx/2021/07/03/easy-way-to-manage-multiple-git-accounts-using-ssh/
IEEE
" » Easy way to manage multiple git accounts using ssh." Shahid Ullah Khan | Sciencx [Online]. Available: https://www.scien.cx/2021/07/03/easy-way-to-manage-multiple-git-accounts-using-ssh/. [Accessed: ]
rf:citation
» Easy way to manage multiple git accounts using ssh | Shahid Ullah Khan | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.