DEV Community

Shyam-Dadhaniya
Shyam-Dadhaniya

Posted on

How to use multiple github accounts in a single system using SSH key in LINUX/UBUNTU

The majority of developers could find it necessary to operate many GitHub accounts on a single computer. On the same machine, for instance, you might run both your personal projects' GitHub account and the account for your organization.

It only takes a fairly straightforward combination of ssh and git setup to implement this. For users of LINUX/UNIX, follow the instructions below.

1. Open Terminal

Image description

2. Generating the SSH keys

Step-1: Write the following command: $ ssh-keygen

Image description

  • After that command it should look like this:

Image description

Step-2: Write your folder path as show below image:

  • In the below image I've written youraccount for the path, in that you can write any name as per your requirement (yourname_work).

Image description

  • Now for passphrase we need to put it empty for now.

  • Once you enter empty passphrase then next step is Enter same passphrase again in that we put empty passphrase again

Image description

  • Now, go to the .ssh folder.

  • Run the below command: cat youraccount.pub

Image description

  • Copy the key starting with ssh-rsa

  • Go to the your github account in the web browser and then go to the settings tabs as shown in the figure below.

Image description

  • Now go to the SSH and GPG key tab as show in below image:

Image description

  • Click on New SSH key button
    Image description

  • You will be able to see the below screen:

    1. name: (as per your wish)
    2. key: paste the key which we've copied from the .ssh folder Image description
  • Open the config file which is present in the .ssh folder in your preferred code editor.

Image description

  • The above mentioned steps lets you generate and configure an ssh key.

  • You can follow these same steps as mentioned above to generate more ssh keys and configure it accordingly to set multiple ssh keys in the very same system.

  • Copy the below code and paste it in the config file. Make changes in your host, hostname and identity file as per your requirement.

#First generated and configured account with ssh key
Host github.com-shyam_work
 HostName github.com
 IdentityFile ~/.ssh/shyam-work


 #Further generated and configured account with ssh key
 Host github.com-shyam_personal
  HostName github.com
  IdentityFile ~/.ssh/shyam-personal
Enter fullscreen mode Exit fullscreen mode

3. Clone Repo

git clone git@github.com-shyam_work:git-account-name/git-ssh-testing.git

git clone git@github.com-shyam_personal:git-account-name/git-ssh-testing.git

Happy Coding.. 😊

Top comments (1)

Collapse
 
smeekas profile image
smeet-kachhadiya

awesome tutorial!!