Skip to content

Instantly share code, notes, and snippets.

@mjrulesamrat
Last active June 11, 2024 21:09
Show Gist options
  • Save mjrulesamrat/d054630303563a3a286c3f996b9f132f to your computer and use it in GitHub Desktop.
Save mjrulesamrat/d054630303563a3a286c3f996b9f132f to your computer and use it in GitHub Desktop.
How to Setup Multiple Ssh Keys for Multiple Github/Bitbucket accounts

How to Setup Multiple Ssh Keys for Multiple Github/Bitbucket accounts

create the SSH keys.

ssh-keygen -t rsa -b 4096 -C "[email protected]"

Add the SSH Keys to the SSH-Agent

ssh-add id_rsa_mjrulesamrat

Configuration

Create config file and add multiple hosts to accomodate different accounts of github, bitbucket or gitlab.

vim ~/.ssh/config
Host github.com
  HostName github.com
  IdentityFile ~/.ssh/id_rsa

Host mjrulesamrat.github.com
  HostName github.com
  IdentityFile ~/.ssh/id_rsa_mjrulesamrat

Other examples of different accounts:

  • mjrulesamrat.gitlab.com

  • mjrulesamrat.bitbucket.org

Add the Keys to your Repositories Accounts

Add id_rsa_mjrulesamrat.pub to github account ssh keys

cat ~/.ssh/id_rsa_mjrulesamrat.pub

Clone repo and start working..

git clone [email protected]:mjrulesamrat/docker-commands.git
@mjrulesamrat
Copy link
Author

@ritik-agrawal Can you share the clone command which uses your config?

@ritik-agrawal
Copy link

  • Get the ssh url from the git repository
  • Use command as given below
git clone <ssh-url>

This should work.
Currently this is working for me.

cc @mjrulesamrat

@mrkhoa99
Copy link

mrkhoa99 commented Oct 1, 2023

Thanks for the article.
For the Bitbucket, there is a guide here. More information can be found in this guide.

@medichops1
Copy link

The instructions on the bitbucket article didnt help me either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment