# How to Access Both Company and Personal GitHub Repositories On The Same Machine

How to Use Separate SSH Keys for Company and Personal GitHub Accounts

Managing multiple GitHub accounts is a common challenge for developers who juggle both personal and professional projects. It becomes even more complex when you want to use different accounts for AI tools like Lovable AI or Bolt AI to access free credits and keep your repositories synchronized.

Pushing code to the right account without mix-ups requires careful setup. Instead of generating a new SSH key and adding it to your GitHub account every time you switch from a personal project to a company project,

In this article, you will learn how to create separate SSH RSA keys and configure your system to match each key with the appropriate GitHub profile.

By following these steps, you’ll be able to switch seamlessly between accounts and streamline your workflow.

A best practice is to use **separate SSH keys** for each account. This not only improves security but also ensures your commits are correctly attributed and your repositories stay organized.

---

## **Step 1: Generate Two SSH Key Pairs**

Open your terminal and run the following command to create two unique RSA key pairs - one for your company GitHub account and another for your personal GitHub account.

### **For your company account:**

```bash
ssh-keygen -t rsa -b 4096 -C "your-company-email@example.com" -f ~/.ssh/id_rsa_company
```

For example,

```bash
ssh-keygen -t rsa -b 4096 -C "mike123@amazon.com" -f ~/.ssh/id_rsa_company
```

* `-C` adds a comment (usually your email) to identify the key.
    
* `-f` specifies the filename to avoid overwriting default keys.
    

You’ll be prompted to set a **password** - highly recommended for added security.

This creates two different files: `~/.ssh/id_rsa_company` and `~/.ssh/id_rsa_company.pub`

### **For your personal account:**

```bash
ssh-keygen -t rsa -b 4096 -C "your-personal-email@example.com" -f ~/.ssh/id_rsa_personal
```

For example,

```bash
ssh-keygen -t rsa -b 4096 -C "mike123@gmail.com" -f ~/.ssh/id_rsa_personal
```

This creates two different files: `~/.ssh/id_rsa_personal` and `~/.ssh/id_rsa_personal.pub`

## **Step 2: Configure SSH to Use The Right Key**

Create or edit the SSH config file to tell your system which key to use for which GitHub account.

Execute the following command from your terminal/command prompt:

```bash
vi ~/.ssh/config
```

and add the following configuration inside that file:

```bash
# Company GitHub Account
Host github-company
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_company
  IdentitiesOnly yes

# Personal GitHub Account
Host github-personal
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_personal
  IdentitiesOnly yes
```

Save the file and close it.

> You can create as many SSH keys as you want depending on the number of GitHub accounts you want to manage.

## **Step 3: Add Public Keys to Your GitHub Account**

Execute the following command to see the generated public key for your company's GitHub account:

```javascript
cat ~/.ssh/id_rsa_company.pub
```

You will see output something like this:

```bash
ssh-rsa AAAAB3kXU3onx6Qp8J5LL0noFecbBPyGiTPk6KarqLGKl5MIZ2KDMA+UFMEQ== mike123@amazon.com
```

Now copy the complete text starting from `ssh-rsa` and ending with your email `mike123@amazon.com`.

> Make sure to not select any extra space or extra character while copying the text.

### **Adding Copied Key To Company GitHub Account:**

Now open your company GitHub account and navigate to [https://github.com/settings/profile](https://github.com/settings/profile). You will see the following navigation menus:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1765344864106/800785bb-9f86-485c-a982-5d3cbfff75bb.png align="center")

* Now, click on the `SSH and GPG keys` submenu under `Access` menu.
    
* Click on the `New SSH Key` button displayed on the top right corner. You will see the following screen.
    

![Add SSH Key](https://cdn.hashnode.com/res/hashnode/image/upload/v1765345072024/24ba5818-441d-4688-bec5-5de8b0ff491f.png align="center")

* Give any title you want and paste the copied key in the `Key` textarea, and click on the `Add SSH key` button.
    

Similarly, you can execute the following command to see the generated public key for your personal GitHub account:

```javascript
cat ~/.ssh/id_rsa_personal.pub
```

Now copy the complete text starting from `ssh-rsa` and ending with your email `mike123@gmail.com`.

Now log in to your personal GitHub account and follow the same steps above of `Adding Copied Key To Company GitHub Account` to add this key to your GitHub account.

Congratulations! With this, we’re done with the setup.

---

Let's try to clone a repository to see if it works.

Go to any of your own GitHub repositories from your personal GitHub account and copy the SSH key from `SSH` tab by clicking on the green `Code` button as shown below:

![Clone Repository](https://cdn.hashnode.com/res/hashnode/image/upload/v1765345670308/e74cd189-3940-40e2-9d3b-5cd177dbae6d.png align="center")

Now, open your terminal and execute the following command to clone the repository:

```bash
git clone your_copied_url
```

For example,

```bash
git clone git@github.com:myogeshchavan97/unsplash_image_search.git
```

Note that, in the above copied URL, you need to replace `git@github.com` with `git@github-personal` keeping everything else as it is. If you want to clone your personal GitHub repository like this:

```bash
git clone git@github-personal:myogeshchavan97/unsplash_image_search.git
```

If you want to clone your company's GitHub repository code, you need to use `git@github-company` like this:

```bash
git clone git@github-company:myogeshchavan97/unsplash_image_search.git
```

This is because, if you remember, in step 2 above `Step 2: Configure SSH to Use The Right Key`, we have named it `github-company` as the `Host` inside the `~/.ssh/config` file for the `Company GitHub Account` and `github-personal` as the `Host` for `Personal GitHub Account`.

Similarly, if you want to connect your local GitHub repository on your machine to your personal GitHub account, you need to execute the following command from the terminal:

```bash
git remote add origin your_remote_git_url
```

For example,

```bash
git remote add origin git@github-personal:myogeshchavan97/test_repo.git
```

Note that here, we have used `git@github-personal` instead of `git@github.com`.

Similarly, if you want to connect your local GitHub repository to your company's GitHub account, you need to execute the following command from the terminal:

```bash
git remote add origin git@github-company:myogeshchavan97/test_repo.git
```

Note that here, we have replaced `git@github.com` with `git@github-company`.

That’s it! You now have isolated SSH keys for company and personal GitHub accounts.

**Access The Ultimate React Ebooks Collection By Clicking The Image Below👇**

[Download The Complete Redux Toolkit Ebook Here](https://www.dropbox.com/scl/fi/vnszyiunuk62xkspjf09k/12_Redux-Toolkit_Getting_Started.pdf?rlkey=yqrxqjfsqo7wbz8p7vka4ub63&st=s024jf7j&dl=0)

[Download The useReducer Hook Ebook He](https://www.dropbox.com/scl/fi/xdmakhu6sxc2np4wkw8yv/React_Fundamentals_useReducer_Hook.pdf?rlkey=ygyt0febc580j3d3guvyifnpy&st=5zb2mpr2&dl=0)

[![React Ebooks Collection](https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdt00waa0e5sb77xdckwz.png align="left")](https://courses.yogeshchavan.dev/the-ultimate-react-ebooks-components-hooks-redux-routing-and-more)

* [**Check Out All My Courses**](https://courses.yogeshchavan.dev/)
    
* [**Follow Me On LinkedIn For Regular Updates**](https://www.linkedin.com/in/yogesh-chavan97/)
    
* [**GitHub**](https://github.com/myogeshchavan97)
