Skip to content

Instantly share code, notes, and snippets.

@sinedied
Last active February 28, 2023 16:11
Show Gist options
  • Save sinedied/3d8c62bbbf95c5914bf9fd0920822262 to your computer and use it in GitHub Desktop.
Save sinedied/3d8c62bbbf95c5914bf9fd0920822262 to your computer and use it in GitHub Desktop.
Setup multiple SSH keys for GitHub EMU accounts

Setup multiple SSH keys for GitHub EMU accounts

1. Create a new SSH key

We'll first generate a new SSH key, by running:

ssh-keygen -t rsa -b 4096 -C "my.email@microsoft.com"`

Name the key emu_rsa so it doesn't overwrite your default id_rsa key.

2. Create or modify the ssh config

Open ~/.ssh/config in a code editor and add this:

# Personal GitHub account
Host github.com
  HostName github.com
  User git
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa

# EMU GitHub account
Host github.com-emu
  HostName github.com
  User git
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/emu_rsa

3. Update SSH agent cached keys

Run:

# Delete cached keys
ssh-add -D

# Add keys
ssh-add ~/.ssh/id_rsa
ssh-add ~/.ssh/emu_rsa

4. Add SSH key to your EMU GitHub account

Go to https://github.com/settings/keys with your EMU profile and add a new SSH key with the content of emu_rsa.pub:

cat ~/.ssh/emu_rsa.pub

Don't forget to also enable SSO for this for the organizations you plan to work on.

5. Work with an EMU repository

When working on an internal GitHub project, when cloning the repo replace the github.com part with github.com-emu, for example:

git@github.com-emu:my-org/my-project.git

For working on personal project with your regular GitHub account, nothing changes.

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