首页 > 解决方案 > Windows ssh:权限被拒绝(公钥)

问题描述

我正在尝试使用公钥 ssh 到远程客户端,但我不断收到权限被拒绝(公钥)错误并且无法解决它。我已经尝试了所有其他在线解决方案,但仍然无法正常工作。我用 * 和 ip_add 替换了一些信息。我该如何解决这个问题?

    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).

标签: ssh

解决方案


这是一个迟到的答案,但我有同样的问题

Windows 看不到隐藏的东西

第一件事(但与问题无关):避免使用 Power Shell(它太强大),使用简单的 CMD 或最好使用 Git Bash(https://gitforwindows.org/

其次,您的语法几乎没问题,但是您将密钥放在隐藏文件夹中 C:\Users\yourname\.ssh\id_rsa,并且应该将其放置在没有像这样隐藏的文件夹中 C:\Users\yourname\ssh\id_rsa,然后您可以像这样访问它:

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

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

你知道在哪里?

debug1: No more authentication methods to try.

绝对意味着您的主机和远程上没有相同的密钥,或者这里有一个密钥而那里没有密钥(或这些的组合)它已经检查了所有密钥并说“没有更多的密钥可以尝试”。您必须以系统可以读取的方式在两个位置放置相同的密钥。你注意这 2 行:

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

他无法读取本地隐藏文件夹中的密钥。所以......通过将它移动到一个未隐藏的文件夹中它会起作用。


推荐阅读