Skip to content

Instantly share code, notes, and snippets.

@thebashpotato
Created May 11, 2022 22:32
Show Gist options
  • Save thebashpotato/3b9d17182b39afd98ecb5adc245ba7ed to your computer and use it in GitHub Desktop.
Save thebashpotato/3b9d17182b39afd98ecb5adc245ba7ed to your computer and use it in GitHub Desktop.
Setup seperate ssh keys for personal and work

Create your ~/.gitconfig

Here I use ~/Development/Github as my workspace, and create two sub folders for work and personal Note that if you want to use something different that ~/Development/Github, you must changed the paths in .gitconfig to match

# Contents of ~/.gitconfig
[includeIf "gitdir:~/Development/Github/personal/"]
    path = ~/Development/Github/personal/.gitconfig.pers
[includeIf "gitdir:~/Development/Github/work/"]
    path = ~/Development/Github/work/.gitconfig.work
[core]
    excludesfile = ~/.gitignore

Next create the two seperate gitconfig files

Personal

In ~/Development/Github/personal create the file .gitconfig.pers

# Contents of ~/Development/Github/personal/.gitconfig.pers
[user]
email = your_personal_email@you.com
name = Herbert West

[github]
user = "the_reanimator"

[core]
sshCommand = "ssh -i ~/.ssh/personal_ssh_key"

Work

In ~/Development/Github/work create the file .gitconfig.work

# Contents of ~/Development/Github/work/.gitconfig.work
[user]
email = your_work_email@company.com
name = Milton Dammers

[github]
user = "undercover_fbi"

[core]
sshCommand = "ssh -i ~/.ssh/work_ssh_key"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment