How to use multiple github accounts in a single system using SSH key in LINUX/UBUNTU
Published: 2023-02-03 06:40:15

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qvjsmgzgnnphj1f4mahj.png)


## 2. Generating the SSH keys

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



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fwehgk34cbjtqj52j9dv.png)


- After that command it should look like this:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yzaollqcsc4dawe91lxo.png)


**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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a9te9u1b25bsdn0xp17x.png)

- 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5p1p9ji1d903rjvdehpx.png)


- Now, go to the .ssh folder.

- Run the below command: `cat youraccount.pub`



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cwbm9791i2zaryt25zwk.png)

- 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3amvw4z1hp914cqk91p4.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ksjp82nrrmeprfwjua6c.png)

- Click on **New SSH key** button
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ioopcijuh13n6p3g5l69.png)

- 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6jrk8mhirsg4hxwx0d5a.png)

- Open the config file which is present in the .ssh folder in your preferred code editor.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1gr1gq3oz33x5kuoq41c.png)

- 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
```

## 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.. :blush: