【问题标题】:Setting up Password Free SSH from Linux to Windows 10设置从 Linux 到 Windows 10 的无密码 SSH
【发布时间】:2020-05-06 15:54:55
【问题描述】:

我正在尝试设置从 linux 服务器到 windows 机器的无密码 ssh 路径。我目前在 Windows 机器上运行 MobaSSH。我可以从 linux 服务器 ssh 到 windows 机器,执行命令也很好,但我必须输入密码。

我在 linux 系统上创建了一个公共 RSA 密钥,并使用 WinSCP 将文件复制到 C:\Users\MyUserName\.ssh 文件夹并在 windows 机器上重新启动了 MobaSsh 服务。

它仍然不会让我在没有密码的情况下通过 ssh 登录。我在这里想念什么?非常感谢任何帮助。

【问题讨论】:

  • 无论在linux系统上生成什么.pub键,都应该重命名为authorized_keys,然后属于C:\Users\MyUserName\.ssh你确定要重命名为authorized_keys吗?
  • 我确实忘记了那一步。所以我将公共 rsa 密钥复制到 C:\Users\MyUserName\.ssh 中的 authorized_keys 中。我重新启动并重新启动所有内容,但它仍然要求输入密码。我在linux机器上创建了公共rsa密钥并复制到windows机器上,应该是正确的。不知道我在这里还缺少什么。
  • 您是否有 Windows 中可见的已知文件类型的文件扩展名。确定authorized_keys 没有保留.pub 扩展。
  • 是的,我始终保持我的文件扩展名可见。这是一个古老但很好的习惯。 “authorized_keys”上没有文件扩展名
  • 您可以使用 Windows 框中的实际 sshd_config 文件或其中的 gist 来编辑问题吗?具体来说,PubkeyAuthentication 的行是什么样的?

标签: ssh


【解决方案1】:

OpenSSH 可用于 Windows 10,并且对我来说非常可靠。我可以在没有密码的情况下从 Linux 机器上始终如一地连接。以下是设置方法。

  • 升级到 Windows 10 版本 1809 或更高版本

    • 检查通过:powershell -c "(Get-Item 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion').GetValue('ReleaseID')";另请参阅 systeminfo | findstr /B /C:"OS Name" /C:"OS Version" 了解 Pro 与 Home,内部版本号
    • 通过 Windows 更新设置或Download Windows 10 升级(后者可以解决某些系统为stuck at 1803 的问题)
  • 安装 SSH 客户端和服务器(以管理员身份;source)-在 Windows PowerShell 中

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Start-Service sshd  # remote login should be possible following this command
Set-Service -Name sshd -StartupType 'Automatic'
Get-NetFirewallRule -Name *ssh*  # there should be a firewall rule named "OpenSSH-Server-In-TCP"  # optional
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0  # optional
  • 为管理员启用公钥登录 (source) - 从 Linux 命令行
scp ~/.ssh/id_rsa.pub administrator@remote_computer_name:'C:\ProgramData\ssh\administrators_authorized_keys'  # if using an alternate method, ensure file is not UTF-16 encoded
icacls C:\ProgramData\ssh\administrators_authorized_keys /remove "NT AUTHORITY\Authenticated Users"
icacls C:\ProgramData\ssh\administrators_authorized_keys /inheritance:r
get-acl C:\ProgramData\ssh\ssh_host_dsa_key | set-acl C:\ProgramData\ssh\administrators_authorized_keys
  • 为非管理员启用公钥登录 - 在 Windows PowerShell 中
Install-Module -Force OpenSSHUtils -Scope AllUsers  # for: Repair-AuthorizedKeyPermission
cd C:\Users\...
ssh-keygen  # create ~/.ssh
# add key(s) to ~/.ssh/authorized_keys
$ConfirmPreference = 'None'; Repair-AuthorizedKeyPermission -FilePath .ssh\authorized_keys
# if above fails, try ''%%Set-ExecutionPolicy Unrestricted -Scope CurrentUser%%''; see also https://github.com/PowerShell/Win32-OpenSSH/issues/1245#issuecomment-440388604

【讨论】:

  • 我会试一试。我查看了 regedit,我的 windows 10 版本是 1703,所以我现在正在升级,谢谢你的链接!我会及时通知大家。
  • 这个答案不起作用(不再):“Repair-AuthorizedKeyPermission”不存在,“OpenSSHUtils”也不存在。见->github.com/MicrosoftDocs/windowsserverdocs/pull/…
猜你喜欢
  • 1970-01-01
  • 2017-12-14
  • 2020-05-19
  • 2019-07-13
  • 1970-01-01
  • 1970-01-01
  • 2011-10-31
  • 2023-04-03
  • 1970-01-01
相关资源
最近更新 更多