Windows Server 2019:

Windows Server 2019:

在此处输入图片描述在此处输入图片描述

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

我尝试了以下命令:

cat .ssh/id_rsa.pub | ssh [email protected] 'cat >> .ssh/authorized_keys'

ssh [email protected] "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"

但出现错误,无法理解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.

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

任何帮助都值得感激。以下是错误图片。

错误图像

答案1

在 Linux ⬌ Windows 之间建立无密码 SSH 的步骤:

笔记:

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

Windows Server 2019:

  • 通过 Windows 更新确保系统是最新的
  • 确保安装了 OpenSSH 功能:
    • 应用程序和功能>管理可选功能
    • OpenSSH 服务器OpenSSH 客户端应列出,如果不是:添加功能

Windows Server 2012 和 2016:

  1. 下载OpenSSHOpenSSH-Win64.zip
  2. 提取内容C:\Program Files\OpenSSH并进入目录
  3. 按照步骤 4 - 6 中提到的安装 Wiki

    # 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
    

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

  1. Running执行以下操作,它将显示两个服务的状态:

    Set-Service ssh-agent -StartupType Automatic
    
    Set-Service sshd -StartupType Automatic
    
    Get-Service -Name ssh-agent,sshd
    

    如果没有运行:打开服务OpenSSH Server并开始OpenSSH Authentication Agent

  2. 对于公钥和私钥对的生成,请发出ssh-keygen并按照提示进行操作
  3. 创造C:\ProgramData\ssh\administrators_authorized_keys
    New-Item -ItemType file "C:\ProgramData\ssh\administrators_authorized_keys"
    
  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
    • 如果authorized_keys不存在:
      touch "/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
    

Windows主机上的相关位置:

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

参考:

答案2

错误说明了一切。

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

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

您可能可以在 Windows 上获取 cat - 通过它的各种本机包,例如与 git 捆绑在一起的或者九州

权限模型可能工作方式不同,因此您需要使用本机工具来执行此操作。

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

要点是 - 你必须了解你的工具并且意识到你不会在任何地方找到相同的环境。

相关内容