无法使用公钥身份验证通过 SSH 连接到 Windows

无法使用公钥身份验证通过 SSH 连接到 Windows

我正在尝试使用公钥身份验证通过 SSH 连接到 Windows。但显然不起作用。

以下是我所做的事情。

我在 Windows 上安装并激活了 SSH。

Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

我生成了公钥文件并将其发送到远程机器以供 ssh 使用。

ssh-keygen

我在 SSH 设置文件“C:\ProgramData\ssh\sshd_config”中更改/添加了以下行

PermitRootLogin yes
AllowUsers otheruser
PubkeyAuthentication yes
PasswordAuthentication no

我重新启动了 ssh 服务器以应用设置更改。

net stop sshd ; net start sshd

我尝试从远程机器(也是 Windows、PowerShell)通过 ssh 连接到 Windows 机器

ssh -i C:\_sync_\id_rsa [email protected]

但失败了。

> ssh -i C:\_sync_\id_rsa [email protected]
[email protected]: Permission denied (publickey,keyboard-interactive).

那么,我该如何解决这个 SSH 公钥认证问题?

答案1

通过 SSH 连接到 Windows 有点浪费时间。他们的文档https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_keymanagement已经过时了https://github.com/MicrosoftDocs/windowsserverdocs/issues/4598并且不幸的是不再起作用。

如果您使用的是 Windows 10,我建议在 Windows 10 上使用 WSL Linux。它基本上是 Windows 上的 Linux 机器,但也可用于 SSH 功能。WSL SSHing 的效果与在 Linux 机器上一样好。

答案2

authorized_keys根据您是标准用户还是管理用户,Windows 似乎需要不同的文件。

截至 2024 年 4 月 15 日,Windows 版 OpenSSH 中有提及文档也就是说(对于行政的用户):

您的公钥 (.ssh\id_ed25519.pub) 的内容需要放在服务器上名为 Administrators_authorized_keys 的文本文件中,位于 C:\ProgramData\ssh\

相关内容