Git via SSH from Windows returns Permission Denied

I’m trying to setup my Windows 10 environment to pull down my repositories over SSH. I’ve followed all the instructions on Github to generate, add, and upload the public key to Github. I’ve verified that Github allows me to connect using the following command:

> ssh -T git@github.com
Hi parithon! You've successfully authenticated, but Github does not provide shell access.

However, when I try to clone any of my repositories I always receive a permission denied error.

> git clone git@github.com:parithon/CoreWiki.git
Cloning inti 'CorWiki'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

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

So I re-verified my public key is working:

> ssh -vT git@github.com
OpenSSH_for_Windows_7.6p1, LibreSSL 2.6.4
debug1: Connecting to github.com [192.30.255.112] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\.../.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\.../.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\.../.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\.../.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\.../.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\.../.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\.../.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\.../.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.6
debug1: Remote protocol version 2.0, remote software version libssh_0.7.0
debug1: no match: libssh_0.7.0
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:...
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in C:\\Users\\.../.ssh/known_hosts:1
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_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:... .\\id_rsa_github
debug1: Server accepts key: pkalg ssh-rsa blen 535
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([192.30.255.112]:22).
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 parithon! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1 Transferred: sent 3224, received 2024 bytes, in 0.6 seconds

Yet, cloning doesn’t work.

Has anybody seen this issue? Am I doing something wrong?

3 Likes

I’m also getting this issue with pushing to my orginsations private repository, and also cloning!

Glad it’s not just me!

2 Likes

Hi @parithon and @bufferoverno,

Because of the nature of what you’re experiencing, and the information we may need to gather in order to troubleshoot, I would recommend you both write to private support for help with this, if you haven’t already. They’ll be able to look at your specific accounts to get to the root of what is happening.

Cheers! 

Hi, I am also facing the same problem. Were you able to solve the issue?

1 Like

Same, issue is still present

Hi @dzheky and @praveenn81,

As mentioned above, because of the information we may need to gather in order to troubleshoot the issue, I would recommend you both write to private support for help with this, if you haven’t already. They’ll be able to look at your specific accounts to get to the root of what is happening. Thanks!

I’ve tested it a few times, it should work.
Basically, do the following

  1. open the terminal
  2. start ssh-agent  eval$(ssh-agent -s)
  3. add a key to the ssh-agent (if prompted, enter the password)

 ssh-add ~/.ssh/id_rsa
4. test connection ssh -T git@github.com
5. Clone the repo git clone git@github.com:antonykidis/Setup-ssh-for-github.git
6. Enjoy :slight_smile:
Important:
Every time you start a new Terminal instance:
1. You will have to call ssh-agent.
2. Add RSA key to the ssh-agent.
Loop through these steps every time you close/open the terminal.
Because the terminal “loses” ssh-agent with its keys on every session.

However, you might check this guide 

It shows how to change https repositories to ssh once.

 

10 Likes

I’ve got the same problem on Windows 10

My setup was: Git for windows + scoop openssh.
I can successfully run 

`ssh -T git@github.com`

but git clone or git push returned permission denied.

The problem come to be that git does not recognize openssh

I have openssh installed with scoop so I need to run 

`[environment]::setenvironmentvariable('GIT_SSH', (resolve-path (scoop which ssh)), 'USER')` 

to make it work.

Hope this could help someone else with this problem 

2 Likes

@parithon 

You might need to add your current PowerShell session to known hosts

ssh $ENV:USERNAME@$ENV:COMPUTERNAME

You should get the credential prompts to add the fingerprint.

Only needs to be done once. You don’t need to be in ssh to start cloning, and can exit once the addition to known_hosts is made.

https://github.com/microsoft/Git-Credential-Manager-for-Windows/issues/705#issuecomment-500082107

git clone git@github:USER/REPO.git LOCALPATH

img

ssh $ENV:USERNAME@$ENV:COMPUTERNAME

Imgur

or you can keep working within SSH (its confusing because its ssh, but you’re SSH’n to your own PowerShell window - not GitHub)
Imgur

Hi  @parithon I’m experiencing the same problem, were you able to solve it?

1 Like

I managed to finda solution. Looks like in Windows in the Git installation folder there’s an ssh_config file where you can specify the key to be used for authentications:

  1. Open  C:\Program Files\Git\etc\ssh\ssh_config (if that’s where you installed Git)

  2. Add lines

Host github.com

IdentityFile ~/.ssh/<your ssh key>

7 Likes

solved by adding the environment variable GIT_SSH as c:\Program Files\PuTTY\plink.exe (installed putty before)

as somebody mentioned here git have problem with openssh

3 Likes

This worked for me, although I had to specify the absolute path for the key file (~ is not evaluating the home directory of the user in this case)

Of course, you shouldn’t do this unless you’re the only user on the system. I’d rather figure a better way to have Git provide information about what is going on with the SSH agent in this case (ie git pull --verbose tells me nothing about what is happening with the SSH session.

OK, this actually works here, too. OpenSSH works fine on Windows (I’m on Win10) but for some reason the Git version of SSH was highjacking things, and wasn’t reading my identity file.

By adding this ENV (per user!) I was able to get it to look at my user’s SSH credentials without overriding the global config for the Git SSH executable.

1 Like

For The access Denied Issues And git username , password

I had this problem too but managed to solve it, the error is that ur computer has saved a git username and password so if you shift to another account the error 403 will appear. Below is the solution
For Windows you can find the keys here:

control panel > user accounts > credential manager > Windows credentials > Generic credentials

Next remove the Github keys.

1 Like

Thank you very much. It works for me.

Thanks, works for me also with setting env GIT_SSH to C:\Windows\System32\OpenSSH\ssh.exe (and enabling “OpenSSH Authentication Agent” in services which was disabled for some reason)

1 Like

Allright
I caught this problem too and investigated it.
I use OpenSSH and Git for Windows.
In my case error

git@github.com: Permission denied (publickey)

appeared because C:\Users\user.ssh\config file was:

Host gh
    HostName github.com
    User git
    IdentityFile C:\Users\user\.ssh\id_rsa

Host and HostName must be equal, i.e. github.com or HostName parameter must be missed. And then GIT correctly assigns GIT_SSH from user’s config file.
The examples that work for me are:

Host github.com
    HostName github.com
    User git
    IdentityFile C:\Users\user\.ssh\id_rsa
Host github.com
    User git
    IdentityFile C:\Users\user\.ssh\id_rsa

I was having a similar issue. It took me a while to realise that my problem was copy-pasta related:

Cloning into 'projectname'... \302\226git@github.com: Permission denied (publickey). fatal: Could not read from remote repository.

I copied the repository path from github.com had somehow ended up with a couple of invisible characters in front of the url. If all other steps haven’t helped, take a close look at your output and make sure that you aren’t having the same issue that I did.

1 Like