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:
ssh-keygen -t rsa -b 4096 -C "your-company-email@example.com" -f ~/.ssh/id_rsa_company
For example,
ssh-keygen -t rsa -b 4096 -C "mike123@amazon.com" -f ~/.ssh/id_rsa_company
-Cadds a comment (usually your email) to identify the key.-fspecifies 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:
ssh-keygen -t rsa -b 4096 -C "your-personal-email@example.com" -f ~/.ssh/id_rsa_personal
For example,
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:
vi ~/.ssh/config
and add the following configuration inside that file:
# 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:
cat ~/.ssh/id_rsa_company.pub
You will see output something like this:
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 not to select any extra space or extra characters 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, you will see the following navigation menus:
Now click on the
SSH and GPG keyssubmenu under theAccessmenu.Click on the
New SSH Keybutton displayed in the top right corner. You will see the following screen.
- Give any title you want and paste the copied key in the
Keytextarea and click on theAdd SSH keybutton.
Similarly, you can execute the following command to see the generated public key for your personal GitHub account:
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 above steps 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 the SSH tab by clicking on the green Code button, as shown below:
Now, open your terminal and execute the following command to clone the repository:
git clone your_copied_url
For example,
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:
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:
git clone git@github-company:myogeshchavan97/unsplash_image_search.git
This is because, if you remember, in the 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:
git remote add origin your_remote_git_url
For example,
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:
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
Download The useReducer Hook Ebook Here




Top comments (1)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.