Matt
Matt

Reputation: 119

Using multiple Github accounts with SSH keys

I have recently been given access to a Github repository that I'll call work for this question, access to this repository has been given to my via SSH keys.

I use SSH keys for my account (that I'll call me) which hasn't given me a problem and continues to act normally for any repository that is under this account.

I have my config file set up like this

Host me.github.com
      HostName github.com
      User git
      IdentityFile ~/.ssh/me

Host work.github.com
     HostName github.com
     User git
     IdentityFile ~/.ssh/work

When I try to use ssh-add -l both keys show up, and both accounts have the correct public key added to them.

Sending the command ssh -T [email protected] returns Hi me! You've successfully authenticated, but GitHub does not provide shell access., although if I send the command ssh -T [email protected] it responds in the correct way.

Both origins for fetch and push are set to the ssh link as verified by git remote -v

I have tried following this gist, this Medium article, and this StackOverflow question, along with a few others with no success.

I should probably also include that I'm running on Windows 10 LTSB build 14393, Powershell 5.1, git version 2.19.1.windows.1, and posh-git 0.7.3.1 installed through Chocolatey.

Upvotes: 2

Views: 288

Answers (1)

VonC
VonC

Reputation: 1329072

First, check your two SSH keys with:

ssh -Tv me.github.com
ssh -Tv work.github.com

Second, you can add for testing in a repo both URLs:

git remote set-url origin me.github.com:<auser>/<arepo>
git remote origin originWork work.github.com:<auser>/<arepo>

(no need for git@ in the URL)

From there, you can use one or the other origin to pull/push.

Upvotes: 3

Related Questions