Ghost Letters 幽霊文字

Different GitHub Accounts

Problem Description

Since I try to keep some online identities separate, I often stumble into problems like “Which email alias did I use for this service?”

This time a new problem popped up when I created a second GitHub account. I want to git push via SSH key and each account should have its own key (not sure why, but it feels correct).

Solution

Gist: Create a ssh config file that references different keys for different hosts. One Host can just be the default github.com. The other Host must be matched in ~/clonedRepo/.git/config

So the resulting files on my local machine look like this:

~/.ssh/config

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Default GitHub
Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_ed25519

# ghostletters GitHub
Host ghostletters.github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_ed25519_ghostletters

~/clonedRepo/.git/config

1
2
3
4
[..]
[remote "origin"]
	url = git@ghostletters.github.com:ghostletters/clonedRepo.git
[..]

The part after the @ is the same as the Host in the ssh config. Note the user in front of the @ is always git.

Sources

Following resources helped me to figure it out

Boom, it works.