Windows ssh: Permission denied (publickey)

Viewed 2622

I am trying to ssh to the remote client using a public key but I keep getting the permission denied (publickey) error and can't solve it. I have tried all the other solutions online, but it still won't work. I have replaced some information with * and ip_add. How do I resolve this issue?

    PS C:\WINDOWS\system32> ssh -v -i C:/Users/*/.ssh/id_rsa administrator@ip_add
    OpenSSH_for_Windows_7.6p1, LibreSSL 2.6.4
    debug1: Connecting to ip_add [ip_add] port 22.
    debug1: Connection established.
    debug1: identity file C:/Users/*/.ssh/id_rsa type 0
    debug1: key_load_public: No such file or directory
    debug1: identity file C:/Users/*/.ssh/id_rsa-cert type -1
    debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.6
    debug1: Remote protocol version 2.0, remote software version OpenSSH_for_Windows_8.1
    debug1: match: OpenSSH_for_Windows_8.1 pat OpenSSH* compat 0x04000000
    debug1: Authenticating to ip_add:22 as 'administrator'
    debug1: SSH2_MSG_KEXINIT sent
    debug1: SSH2_MSG_KEXINIT received
    debug1: kex: algorithm: curve25519-sha256
    debug1: kex: host key algorithm: ecdsa-sha2-nistp256
    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: ecdsa-sha2-nistp256 SHA256:qjxnj9GZZ6kvey+qvHsEoJYnLTz4N82DtnmFMjRlrq8
    debug1: Host '192.168.1.135' is known and matches the ECDSA host key.
    debug1: Found key in C:\\Users\\*/.ssh/known_hosts:2
    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: pubkey_prepare: ssh_get_authentication_socket: No such file or directory
    debug1: SSH2_MSG_EXT_INFO received
    debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
    debug1: SSH2_MSG_SERVICE_ACCEPT received
    debug1: Authentications that can continue: publickey
    debug1: Next authentication method: publickey
    debug1: Offering public key: RSA SHA256:+ymSxB9gd+AJe9wYj0WgW70Qk+x4fWxEQhk1JCQyKWE C:/Users/*/.ssh/id_rsa
    debug1: Authentications that can continue: publickey
    debug1: No more authentication methods to try.
    administrator@ip_add: Permission denied (publickey).
2 Answers

this is a late answer but I had the same issue

Windows can't see hidden things

First thing (but has nothing to do with the problem) : avoid the Power Shell(it is too powerful), use a simply CMD or best use the Git Bash (https://gitforwindows.org/)

Second, your syntax is almost OK, but you placed the keys in hidden folder C:\Users\yourname\.ssh\id_rsa and you should place it in a folder that is not hidden like this C:\Users\yourname\ssh\id_rsa and then you can access it like this :

C:\WINDOWS\system32> cd C:\Users\yourname\

C:\Users\yourname/> ssh <user>@<ssh_server> -p 22 -i ~/ssl/id_rsa

Where do you know?

debug1: No more authentication methods to try.

means definitively that you have not the same keys on your host and on remote , or there is a key here and no key there (or combinations of this) it has checked them all and says that "there are NO MORE keys to try". You must place the same keys on both places in a way the system can read them. You pay attention to this 2 lines:

debug1: identity file C:/Users/*/.ssh/id_rsa type 0 
debug1: key_load_public: No such file or directory

he was not able to read the key in the local hidden folder. So ... by moving it in a not hidden folder it will work.

I recently encountered a similar problem on Windows 10 and found the root cause (sort of) and the solution. My tool chain involved was: Visual Studio 2019 with git using ssh protocol and a key pair Sourcetree also using git A private bitbucket server.

My scenario was this: I installed Visual Studio 2019 with git using ssh protocol with my key pairs and was using it successfully, and then I installed Sourcetree (to get hunk commits instead of whole file commits) and Sourcetree worked but Visual Studio no longer could use git sync/commits.

The key to solving the problem was adding this environment variable: GIT_SSH_COMMAND=ssh -vvv

After restarting Visual Studio I could then get verbose information about the ssh failure using git.

The important debug output was this: debug1: send_pubkey_test: no mutual signature algorithm

This is when I realized that something was incompatible between my key pair and bitbucket server ssh algorithm. I did not diagnose the exact problem (which I believe is due to obsolete RSA keys) but instead I simply created a new key pair using: ssh-keygen -t ed25519 then uploaded to the bitbucket server and "bob's your uncle"

12 hours to find, 2 minutes to fix.

Related