ssh - 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).
解决方案
这是一个迟到的答案,但我有同样的问题
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
他无法读取本地隐藏文件夹中的密钥。所以......通过将它移动到一个未隐藏的文件夹中它会起作用。
推荐阅读
- c# - 使用 JsonConverter 在 C# 中自定义 JSON 反序列化
- javascript - 使用 NodeJS 和 Lambda 从变量调用函数
- ios - 没有按钮的 SwiftUI 安排本地通知?
- java - 为什么我的while循环在我输入一次分数后结束,而我想在它结束之前输入更多
- c++ - 使用带有部分专业化的 std::enable_if<> 与类型有什么区别?
- reactjs - 使用带有 firebase 身份验证的 react-router
- r - 有没有一种简单的方法可以通过 R 中的并行化一次运行多个循环试验?
- python - 根据位置数量可变的桌子上的位置分配变量
- node.js - 本地 Postgres 连接不返回任何内容
- php - 在 graphql-playground 中测试上传标量类型