无法通过 SSH 运行 OpenSSH 连接到 Windows 10

Cannot connect to Windows 10 over SSH running OpenSSH

我有一台 Windows 10 台机器 运行 OpenSSH,我需要使用 PuTTY 通过 SSH 连接到它。我使用 PuTTYgen 在主机上创建了一个 public/private 密钥。我将 public 加载到 .ssh/authorized_keys 下的用户配置文件目录中。当我从网络外的机器连接 PuTTY 时,我收到此错误消息:

"Server refused our key"

我看过几篇文章,它们都表明 public 键没有被正确读取。我进行了以下更改但没有成功。

  1. 更新 .ssh 的用户权限和/authorized_keys 将用户设置为所有者。
  2. 目前我的 .ssh 文件夹位于 %SYSTEMDRIVE%/users/[USERNAME]/.ssh
  3. 我在我的数据驱动器上重新创建了这个目录以确保这不是问题:“D:/users/[USERNAME]/.ssh
  4. 因为我使用的账号是我创建的管理员账号"%Program Data/ssh/adminstrators_authorized_keys
  5. 我注释掉了 sshd_config 中当用户是管理员时查看 #4 中文件的行。

None 这些尝试已经解决了问题。我以前从未在 Windows 10 主机上设置 SSH,所以我没有想法。我在 sshd_config 中设置了登录,但没有生成任何日志文件。

谁能帮我解决这个问题?

首先,与 this tutorial 一样,确保复制一个 OpenSSH public 密钥

The OpenSSH public key is located in the box under Key / Public key for pasting info OpenSSH authorized_keys file:. The public key begins with ssh-rsa followed by a string of characters.

其次,与 this gist 一样,启动 sshd -d 以在调试模式下获得一次性会话:您将看到更多关于为什么它拒绝您的 public 密钥的线索。


OP gacto confirms :

sshd -d gave me the information I needed.

It was a file permissions issue. I had set the file permissions to the specifications from the OpenSSH setup instructions, but access to the file was getting blocked.
Once I updated the file permissions, I was able to connect without any trouble.

就我而言,sshd -d 中的消息是

Failed publickey for [user] from [IP] port [port] ssh2: RSA SHA256:[fingerprint]

原因是 authorized_keys 文件是 UTF-16 格式。它需要是 UTF-8 才能工作。

确保您在 Windows10 中的用户处于活动状态。 默认情况下,例如,用户管理员未激活,应启用:

net user Administrator /active:yes