3

I want to Push changes via SSH to my git repo.

[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I have my ssh-agent up and running. I have my key loaded via ssh-add. It is the right key, I checked a bunch of times. It is also registered in my github.

When I try to git push origin I get the error from the above. It is the correct origin.

I also looked into this a lot and someone said that if you have multiple keys to the same git, it gets confused or something, but I have only one key loaded.

I cloned the repo via ssh aswell.

What should I do? I'm stuck on this for over 4 hours and I can't figure it out.

UPDATE

I've ran ssh -v -T [email protected] and the output is:

OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
debug1: Connecting to github.com [140.82.121.3] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.ssh/id_ed25519-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.ssh/id_xmss type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.7
debug1: Remote protocol version 2.0, remote software version babeld-b5f98373
debug1: no match: babeld-b5f98373
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:foobar
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in C:\\Users\\foobar/.ssh/known_hosts:1
Warning: Permanently added the RSA host key for IP address 'foobar' to the list of known hosts.
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
[email protected],[email protected],[email protected],[email protected],ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:Ae2CCQzd33Dczv8gPiRiYEWJ7xwBVOU+719JTJ/5fjQ C:\\Users\\foobar\\.ssh\\foobar\\open_ssh-agent
debug1: Server accepts key: pkalg ssh-rsa blen 279
warning: agent returned different signature type ssh-rsa (expected rsa-sha2-512)
debug1: Authentication succeeded (publickey).
Authenticated to github.com (foobar).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi vivere! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2560, received 2468 bytes, in 0.2 seconds
Bytes per second: sent 10852.5, received 10462.5
debug1: Exit status 1
3
  • Try running ssh -v -T [email protected]. The "-v" option will cause ssh to print debugging output. Then edit your question to show the ssh command that you ran and the output.
    – Kenster
    Commented Feb 25, 2021 at 18:23
  • @Kenster I ran it and apparently it authenticates me, but the exit code is still 1? I don't understand what's happening
    – Vivere
    Commented Feb 25, 2021 at 18:45
  • @phd Can't run that, I'm on windows, but I've run: '~' | Resolve-Path in powershell and it shows: C:\Users\s. Also, $env:HOMEPATH in ps shows \Users\s
    – Vivere
    Commented Feb 25, 2021 at 19:31

2 Answers 2

2

If ssh -Tv [email protected] does work, then check if you can contact the remote repo SSH URL with:

git ls-remote [email protected]:<me>/<myRepo>

Then compare that URL with the one registered in your local repository (git remote -v)
And if it is the same, check the output of git config -l: look for any directive with insteadOf in it, in case that URL would be changed by something else.

The OP Vivere reports in the comments:

  • Having to name the key as id_rsa and save it exactly in ~/.ssh, following this gist;
  • Using the wrong ssh-add.exe (the one from OpenSSH)

Basically:

  • don't use Powershell
  • use a CMD session where the PATH does not reference C:\Windows\System32\OpenSSH\
6
  • I tried what you recommended but nothing unusual showed up. I managed to make it somehow work by following these instructions: link. Basically, the only thing that I did differently was having the key named id_rsa and saved exactly in ~/.ssh. I wanted to have multiple keys and have them in different directories inside the ~/.ssh dir because I want to split my keys, each with their own purpose. I want to have one for Jenkins for example. From what I've encountered, that is not possible? It must be named id_rsa?
    – Vivere
    Commented Feb 26, 2021 at 15:20
  • I believe this has to do something with the Windows OpenSSH. where ssh-add | C:\Program Files\Git\usr\bin\ssh-add.exe | C:\Windows\System32\OpenSSH\ssh-add.exe Until now I've worked in Powershell and cmd and I kept writing ssh-add to add my custom-named keys and it didn't work. Then I tried with id_rsa naming, and that worked but I had to write the passphrase every single time which was annoying even though it was in ssh-add. Apparently, in git bash, everything works as expected. I also found this thread: github.com/PowerShell/Win32-OpenSSH/issues/1263 which looks promising.
    – Vivere
    Commented Feb 26, 2021 at 16:31
  • 1
    @Vivere You can have multiple keys: you need a ~/.ssh/config to differentiate them. See stackoverflow.com/a/66269477/6309 for example.
    – VonC
    Commented Feb 26, 2021 at 16:35
  • 1
    @Vivere I have included your comment in the answer, but my take is: don't use Powershell, use a CMD where the PATH does not reference C:\Windows\System32\OpenSSH
    – VonC
    Commented Feb 26, 2021 at 16:39
  • I have to do two things. One, create some script that starts the agent and adds the keys and two, move to Linux. It's so hard to do anything on Windows it's driving me crazy
    – Vivere
    Commented Feb 26, 2021 at 16:56
0

If you are getting these errors from VsCode, follow these steps.

  1. enter image description here

    from these images, check the bottom-left account button (git-hub), Logout from there, and log in again. It will work

  2. If it's not working, take the keychain access

enter image description here

delete the accounts which are showing there retry step.1

Thank you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.