Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

git/ssh - Having trouble with ssh authentication with multiple users

$
0
0

I am having trouble getting git ssh authentication to work with multiple users.Initially, it would always try to authenticate with my home-key

~/.ssh/home-key,

untill I found this answer

https://gist.github.com/Jonalogy/54091c98946cfe4f8cdab2bea79430f9?permalink_comment_id=3700405#gistcomment-3700405

I ran that command and success. It worked, however now I have the opposite issue, and it always tries to autenticate with~/.ssh/work-01Despite having that and~/.ssh/home-01

I know the git config file is correct because in my work repo, when I run

gitconfig user.email

I get

rob@Robs-MBP test % git config user.emailwork@mywork.co.uk

and likewise when in my home-repo

I get

rob@Robs-MacBook-Pro ~ % git config user.emailhome@googlemail.com

As far as I am aware, my ~/.ssh/config file is correct

#Default GitHubHost github.com-home  HostName github.com  User git  IdentityFile /Users/rob/.ssh/home-01  IdentitiesOnly yes#wearenv-gitHost github.com-work  HostName github.com  User git  IdentityFile /Users/rob/.ssh/work-01  IdentitiesOnly yes

and my global git config file is this

[user]    name = home-username     email = home@googlemail.com [includeIf "gitdir:~/work-repos"]    path = /work-repos/.gitconfig[init]    defaultBranch = main[color]    ui = auto[core]    editor = code --wait

the includeIf points to this

[user]    name = work-username    email = work@work.co.uk[init]    defaultBranch = main[color]    ui = auto[core]    editor = code --wait

and even setting a local config file

[core]    repositoryformatversion = 0    filemode = true    bare = false    logallrefupdates = true    ignorecase = true    precomposeunicode = true[remote "origin"]    url = git@github.com:wearenv-digital/test.git    fetch = +refs/heads/*:refs/remotes/origin/*[branch "main"]    remote = origin    merge = refs/heads/main [user]    name = work-username    email = work@work.co.uk

I have checked, double checked and triple checked I have the correct key files uploaded to git.

Git can authenticate using work.key, as shown in this:

rob@Robs-MacBook-Pro ~ % ssh -i~/.ssh/work-01  git@github.com PTY allocation request failed on channel 0Hi work-username! You've successfully authenticated, but GitHub does not provide shell access.Connection to github.com closed.rob@Robs-MacBook-Pro ~ % 

It seems that when I only have work01 in ssh-agent, it always tries to authenticate with work@work.co.uk

Vice versa with home-01

Then when both keys are in the ssh-agent, it always tries to use the first one added.

EDITI can provide the verbose output of

ssh -i ~/.ssh/work-01 git@github.com

eg

ssh -i ~/.ssh/work-01 -v git@github.com

However StackOverflow detected it as spam in the original question :(


Viewing all articles
Browse latest Browse all 5049

Trending Articles