从 Linux 到 Windows 的无密码 ssh

Sub*_*ash 3 windows ssh cygwin

在此处输入图片说明在此处输入图片说明

我正在尝试从 Linux 服务器无需密码登录到 Windows。我已经从 GitHub 安装了 OpenSSH,并且可以执行scpssh. 我尝试将 复制authorized_keys到 Windows 位置。但它仍然无法正常工作。该功能应该是没有密码提示,用于从 linux 环境运行 ssh 或 scp 到登录/显示 windows 目录。

我尝试了以下命令:

cat .ssh/id_rsa.pub | ssh edh_win@xxx.xxx.xxx.xxx 'cat >> .ssh/authorized_keys'

ssh edh_win@xxx.xxx.xxx.xxx "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"
Run Code Online (Sandbox Code Playgroud)

但得到错误无法理解catchmod

更新错误

'cat' is not recognized as an internal or external command,
operable program or batch file.

'chmod' is not recognized as an internal or external command,
operable program or batch file.
Run Code Online (Sandbox Code Playgroud)

我需要安装cygwin吗?如果是,请帮助实施。

任何帮助表示赞赏。下面是错误的图像。

错误的图像

小智 6

在 Linux 之间建立无密码 SSH 的步骤?视窗:

笔记:

  • 使用管理员权限打开 PowerShell 控制台,并仅在该控制台中执行下面提到的所有命令
  • 根据安装路径,添加C:\Windows\System32\OpenSSHC:\Program Files\OpenSSH到系统Path

视窗服务器 2019:

  • 通过 Windows 更新确保系统是最新的
  • 确保安装了 OpenSSH 功能:
    • 应用程序和功能>管理可选功能
    • 如果未列出OpenSSH ServerOpenSSH Client,则应列出它们:添加功能

Windows Server 2012 和 2016:

  1. 下载OpenSSH ( OpenSSH-Win64.zip)
  2. 将内容解压到C:\Program Files\OpenSSH并进入目录
  3. 按照安装 Wiki 中提到的步骤 4 - 6 进行操作:

    # In an elevated Powershell console, run the following:
      powershell -ExecutionPolicy Bypass -File install-sshd.ps1
    
    # Open the firewall for sshd.exe to allow inbound SSH connections
      New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
    
    # Start sshd (this will automatically generate host keys under %programdata%\ssh if they don't already exist)
      net start sshd ; net start ssh-agent
    
    Run Code Online (Sandbox Code Playgroud)

Windows Server 2012/2016/2019 的常见步骤:

  1. 执行以下命令,它应该显示Running两个服务的状态:

    Set-Service ssh-agent -StartupType Automatic
    
    Set-Service sshd -StartupType Automatic
    
    Get-Service -Name ssh-agent,sshd
    
    Run Code Online (Sandbox Code Playgroud)

    如果没有运行:打开服务并启动OpenSSH ServerOpenSSH Authentication Agent

  2. 对于公私钥对生成,发出ssh-keygen并按照提示操作
  3. 创建C:\ProgramData\ssh\administrators_authorized_keys
    New-Item -ItemType file "C:\ProgramData\ssh\administrators_authorized_keys"
    
    Run Code Online (Sandbox Code Playgroud)
  4. 附加/root/.ssh/id_rsa.pubC:\ProgramData\ssh\administrators_authorized_keys
    • 如果id_rsa.pub在 Linux 上不存在,请通过以下方式生成:ssh-keygen
  5. 附加C:\Users\Administrator\.ssh\id_rsa.pub/root/.ssh/authorized_keys
  6. 对于权限设置:

    icacls "C:\ProgramData\ssh\administrators_authorized_keys" /remove "NT AUTHORITY\Authenticated Users"
    
    icacls "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r
    
    Restart-Service -Name sshd, ssh-agent -Force
    
    Run Code Online (Sandbox Code Playgroud)

Windows 主机上的相关位置:

  • C:\Windows\Sytem32\OpenSSH\
  • C:\Program Files\OpenSSH\
  • C:\Users\Administrator\.ssh\
  • C:\ProgramData\ssh\

参考:


Jou*_*eek 1

错误说明了一切。

或多或少,您的 ssh 服务器提供了……嗯,一个 ssh 服务器。默认情况下,它没有您尝试运行的“unix”样式或 linux coreutils。

虽然将此 ssh 服务器替换为 cygwin 可能会有所帮助 - 您实际上需要做的是了解您在做什么,而不是假设 linux 命令会起作用。

你可能可以在 Windows 上获取 cat - 通过它的各种本机包,例如与 git或GOW捆绑的包

权限模型的工作方式可能有所不同,因此您需要使用本机工具来完成此操作。

它需要一些阅读,但这表明“只有系统、管理员和所有者可以访问” - 并且这篇文章建议您可以使用它ICACLS来设置适当的权限。

结论是——你必须了解你的工具,并意识到你不会在任何地方都找到相同的环境。