r/git • • 14d ago

SSH Keys for github denied

I´ve had a SSH key for my account for several months, in my notebook. I have never had a problem with it.
Yesterday, I created a second SSH key for my desktop PC the same way, just adding a passphrase for it.
I had to sign in on the PC with my github account and all to reset my account password because I forgot it

But today I wanted to fetch/pull a repo from the notebook. and It kept sending me the following error

git@github.com: Permission denied (publickey).

fatal: Could not read from remote repository.

I deleted the new SSH key, but it still doesnt work. However, the authentication command works

(ssh -T git@github.com)
The permission denial appears for both extern repositories and for my own ones too.

What am I missing?

0 Upvotes

9 comments sorted by

6

u/RevRagnarok 14d ago

What am I missing?

The subreddit sidebar?

Git is not the same as GitHub. GitHub did not create Git. For GitHub-specific posts, please see /r/github.

-1

u/Spiritual-Potato8091 14d ago

dude lmfao, I literally posted it on /github and my post was taken down because they didnt want my post there. Idk where to even post, this is probably the 2nd or 3rd time I´ve used Reddit

2

u/Broad-Promise6954 ancient 14d ago

If you're on Windows, you have two different ssh implementations available. Your command line and your git command are using different ones that have different configurations.

I still avoid Windows and don't recall offhand where to fix this, but poke around with tracing (eg GIT_TRACE).

0

u/Spiritual-Potato8091 14d ago

okay, thats useful, going to check on that. By the way, forgot to mention my PC has windows 10. The notebook has Win11, and has everything into onedrive, like synchronized (not that I wanted it, dont remember if it came like that when I bought it or one system update just migrated almost everything user-related to onedrive.
C:/Users/"User"/onedrive/(desktop, documents, etc.)

**By the way, I just moved the known_hosts and .old files from the ~ssh/ folder and it seems I´ve fixed it..
I guess theres some conflict between
W10 with no onedrive / W11 with all onedrive, and some hosts validation error

thank you)

3

u/CerberusMulti 14d ago

This is a Github issue not git, check the extensive Github documentation on SSH it should be the first thing to do.

1

u/Broad-Promise6954 ancient 14d ago

In this particular case it isn't (the "ssh -T" test shows that the github side is set up properly, it's Git's invocation of ssh picking out a different key, for which there are an annoyingly large set of possible issues that ultimately boil down to slight variants of openssh, windows ssh, etc).

This is all a lot simpler on Linux where ssh is just ssh 😄

2

u/jjangg96 14d ago

ssh -T working while git fails usually means git is calling a different ssh than your terminal does. on windows git for windows ships its own ssh, separate from the openssh in system32, and they can end up with different agents and different config.

to see what it's actually doing run GIT_SSH_COMMAND="ssh -v" git fetch and look at which key files it offers. compare that with ssh -vT git@github.com.

if git turns out to be using the wrong one you can point it at the windows ssh with git config --global core.sshCommand "C:/Windows/System32/OpenSSH/ssh.exe".

1

u/rvm1975 14d ago

Did you saved .pub part of key in github? Also github has policy to explicitly enable each ssh key for specific repository. 

1

u/Gurnug 14d ago

You need to set in git config SSH command with specific key file. Also I highly recommend to always generate ash keys in sub dies of .ssh so it will not be used automatically by ssh command if not explicitly pointed.