Skip to content

Instantly share code, notes, and snippets.

@mjrulesamrat
Last active March 5, 2024 19:04
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 "mjrulesamrat@gmail.com"

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 git@mjrulesamrat.github.com:mjrulesamrat/docker-commands.git
@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.

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