Skip to content

Instantly share code, notes, and snippets.

@j1g54w1337
Last active November 11, 2022 10:19
Show Gist options
  • Select an option

  • Save j1g54w1337/a94020336f216e3d071a7c964db3f716 to your computer and use it in GitHub Desktop.

Select an option

Save j1g54w1337/a94020336f216e3d071a7c964db3f716 to your computer and use it in GitHub Desktop.
Use multiple SSH keys for multiple Github Accounts

Multiple SSH Keys settings for different github account

Create different public keys for each Github/Gitlab account

for example, 2 keys created at:

~/.ssh/id_rsa-j1g54w
~/.ssh/id_rsa-itmagix

then, add these two keys as following

$ ssh-add ~/.ssh/id_rsa-j1g54w
$ ssh-add ~/.ssh/id_rsa-itmagix

you can delete all cached keys before

$ ssh-add -D

finally, you can check your saved keys

$ ssh-add -l

Modify the ssh config

$ cd ~/.ssh/
$ touch config
$ subl -a config

Then added

#j1g54w account
Host github.com-j1g54w
	HostName github.com
	User git
	IdentityFile ~/.ssh/id_rsa-j1g54w

#itmagix account
Host github.com-itmagix
	HostName github.com
	User git
	IdentityFile ~/.ssh/id_rsa-itmagix

Clone you repo and modify your Git config

clone your repo

cd and modify git config

$ git config user.name "j1g54w"
$ git config user.email "[email protected]" 

$ git config user.name "itmagix"
$ git config user.email "[email protected]"

or you can have global git config

	$ git config --global user.name "j1g54w"
	$ git config --global user.email "[email protected]"

then use normal flow to push your code

	$ git add .
	$ git commit -m "your comments"
	$ git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment