Home Navigation

Monday, 16 March 2026

Multiple github account management with ssh

Sometimes it is hard to manage multiple GitHub accounts and deal with conflicts when cloning and pushing code. For example, if we have three accounts, we can follow these steps:

Example:

ssh-keygen -t ed25519 -C "personal@email.com" -f ~/.ssh/github_personal
ssh-keygen -t ed25519 -C "work@email.com" -f ~/.ssh/github_work
ssh-keygen -t ed25519 -C "school@email.com" -f ~/.ssh/github_school

You will get:

~/.ssh/github_personal
~/.ssh/github_personal.pub

~/.ssh/github_work
~/.ssh/github_work.pub

~/.ssh/github_school
~/.ssh/github_school.pub

Upload each .pub key to the correct GitHub account.

Clean SSH config

Edit:

nano ~/.ssh/config

Add:

Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/github_personal
IdentitiesOnly yes

Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/github_work
IdentitiesOnly yes

Host github.com-school
HostName github.com
User git
IdentityFile ~/.ssh/github_school
IdentitiesOnly yes

Create a repo folder structure

Example:

~/dev/personal/
~/dev/work/
~/dev/school/

Clone repos normally but change the host

Personal:

git clone git@github.com-personal:<owner>/<repo-name>.git

Work:

git clone git@github.com-work:<owner>/<repo-name>.git

School:

git clone git@github.com-school:<owner>/<repo-name>.git

Automatic Git identity (the magic part)

Edit your global git config:

nano ~/.gitconfig

Add:

[user]
name = Your Name
email = personal@email.com

[includeIf "gitdir:~/dev/work/"]
path = ~/.gitconfig-work

[includeIf "gitdir:~/dev/school/"]
path = ~/.gitconfig-school

Work Git config

Create:

nano ~/.gitconfig-work
[user]
name = Your Work Name
email = work@email.com

School Git config

nano ~/.gitconfig-school
[user]
name = Your Name
email = school@email.com

Result

FolderGitHub account used
~/dev/personalpersonal
~/dev/workwork
~/dev/schoolschool

So when you:

cd ~/dev/work/project
git commit

Git automatically uses your work email + SSH key.

No switching accounts. No confusion.

Test SSH connections:

ssh -T git@github.com-personal
ssh -T git@github.com-work
ssh -T git@github.com-school