Reputation: 36391
I have a personal and a work accounts on github. I have SSH keys for both and this config
file in the ~/.ssh
Host github
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/work-rsa-key
When I work with the personal account all is fine but when I try to pull/push to the work account I get
$ git pull
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Of course I verified the address is correct.
When I do ssh -T [email protected]
I get Hi ilya! ...
which is the personal user name.
This is the config
for the work account:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = false
[branch "dev"]
[remote "origin"]
url = git@github-work:work/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "dev"]
remote = origin
merge = refs/heads/dev
[branch "unify"]
remote = origin
merge = refs/heads/unify
[user]
name = ilya-work
email = [email protected]
Upvotes: 0
Views: 68
Reputation: 1046
Add the following line to your SSH config section:
IdentitiesOnly yes
For example:
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/work-rsa-key
IdentitiesOnly yes
Alternatively, you might want to add your private key identitiy to the authentication agent, by running
$ ssh-add ~/.ssh/work-rsa-key
When executing git pull
, it will try every identities found in your authentication agent. That's why this method is not (much) recommended.
Upvotes: 0
Reputation: 1526
Have you done ssh-add ~/.ssh/work-rsa-key
?
Verifiy that all your keys are listed by doing ssh-add -l
.
Then, you can do the following:
git config user.name "ilya-work"
git config user.email "[email protected]"
Now, git pull
should work.
Upvotes: 1