Chantal
Chantal

Reputation: 101

Multiple users successfully authenticated, but SSH keys not working on Windows 11

I'm trying to set multiple GitHub accounts for multiple projects I'm working on. It just won't work.

First of all, I'm on Windows 11.

Last thing I tried is 'ssh -vvv github-user1' to see whether it could connect, it did. But, this rule was in the output:

debug1: Will attempt key: [email protected] RSA SHA256:blahblahblah agent

So appearantly it tries to connect with the wrong user. Also, if I prompt for this:

ssh -T [email protected]

The same wrong user comes up. So, where does this come from? I did not configure this anywhere. Before I started to configure ssh keys, I logged in and out of both accounts a few times, so I guess something got saved somewhere, but I haven't been able to find it anywhere. Anyone any idea where to look?

Also, I noticed that on github, it says the key as never been used: Screenshot github ssh key

I did delete the git user in the Windows References, so that is not the problem.

Upvotes: 0

Views: 59

Answers (1)

Chantal
Chantal

Reputation: 101

Ok, so here's my solution. As I already mentioned, when I tested ssh -T [email protected] I got the wrong user authenticated. I did not define [email protected] as a host anywhere. So I decided to set user1 as a default github.com host like so:

Host github.com
   HostName github.com
   User git
   IdentityFile ~/.ssh/github-user1

Host github-user2
   HostName github.com
   User git
   IdentityFile ~/.ssh/github-user2

The local repository git config file now looks like this:

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    sshCommand = ssh -i ~/.ssh/github-user1
[user]
    name = user1
    email = [email protected]
[remote "origin"]
    url = [email protected]:user1/repositoryName.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

Also, I forgot to add the line sshCommand = ssh -i ~/.ssh/github-user2 in the local repository git config file for user2, so I added that as well. The config for user2 now looks like this:

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    sshCommand = ssh -i ~/.ssh/github-user2
[user]
    name = user2
    email = [email protected]
[remote "origin"]
    url = git@github-user2:user2/repositoryName.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

These steps fixed the problem for me. I can now fetch from git on both remote repositories and I can see in both github accounts that my keys are being used.

Screenshot github used key

Upvotes: 0

Related Questions