Skip to content

Instantly share code, notes, and snippets.

@modulsx
Forked from suryabigapp/multiple_ssh_setting.md
Created August 17, 2021 08:07
Show Gist options
  • Save modulsx/87552ead6034883c791c73f3b60895cb to your computer and use it in GitHub Desktop.
Save modulsx/87552ead6034883c791c73f3b60895cb to your computer and use it in GitHub Desktop.
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key for different github accounts (must give filename while creating, else it'll overwrite - ex: ~/.ssh/id_ed25519_suryabigapp)

$ ssh-keygen -t ed25519 -C "[email protected]"
$ ssh-keygen -t ed25519 -C "[email protected]"

for example, 2 keys created at:

~/.ssh/id_ed25519_suryabigapp
~/.ssh/id_ed25519_suryatct

Modify the ssh config

$ cd ~/.ssh/
$ touch config
$ nano config

Then add config for different accounts

#suryabigapp account
Host github.com-suryabigapp
	HostName github.com
	User git
	IdentityFile ~/.ssh/id_ed25519_suryabigapp

#suryatct account
Host github.com-suryatct
	HostName github.com
	User git
	IdentityFile ~/.ssh/id_ed25519_suryatct

Change repo url from HTTPS to SSH Reference and modify your Git config

cd to your project repo folder ex: bigapp-repo

git remote set-url origin [email protected]:bigappcompany/bigapp-repo.git

modify git config for bigapp-repo

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

cd to different project repo folder ex: curio-repo

git remote set-url origin [email protected]:curio-com/curio-repo.git

modify git config for curio-repo

$ git config user.name "suryatct"
$ git config 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