【问题标题】:Copying ssh key from windows machine to windows server 2019将 ssh 密钥从 windows 机器复制到 windows server 2019
【发布时间】:2021-04-15 19:15:54
【问题描述】:

我一直在尝试通过 OpenSSH 协议无需密码即可访问 Windows Server 2019。 所以我创建了新的密钥,我需要将它复制到 Windows Server,我试过这个:

ssh-copy-id -i ~/.ssh/id_rsa user@server

但输入正确密码后我得到了这个:

'exec' is not recognized as an internal or external command,
operable program or batch file.
The system cannot find the path specified.
The system cannot find the path specified.

我的问题是如何从一台 Windows 机器传输密钥(使用 gitbash、WSL、powershell 或其他) 如果我没记错的话,到 Windows Server 2019 的授权密钥位置。

我迫切需要手动完成,但这些密钥的位置对我来说是个谜,我是否需要先在 Windows Server 上设置一些东西以便它可以接受用于身份验证的密钥?

ssh-copy-id 从 Windows 机器到 Windows Server 2019 的替代方法是什么?

找到解决方案: 遵循这个有用的 youtube 指南,支持 https://www.youtube.com/watch?v=Cs3wBl_mMH0&ab_channel=IT%2FOpsTalk-Deprecated-SeeChannelDescription

此外,安装 OpenSSHUtils 可以使用:

Install-Module -Name OpenSSHUtils -RequiredVersion 0.0.2.0 -Scope AllUsers

本指南也有帮助:

https://www.cloudsma.com/2018/03/installing-powershell-modules-on/

我的服务器没有访问权限,所以我手动从以下位置复制了文件: C:\Program Files\WindowsPowerShell\Modules 到服务器的: 服务器:\Program Files\WindowsPowerShell\Modules

【问题讨论】:

    标签: ssh server openssh windows-server


    【解决方案1】:

    首先,这个错误信息后面跟着microsoft/vscode-remote-release issue 25

    当前解决方法(上下文是 VSCode,但也应适用于常规 SSH 连接):

    此外,对于这里喜欢在 Windows 上使用 bash 但仍希望能够使用 VSCode 远程的其他人,我目前设置的解决方法是使用部署在服务器上的 autorun.cmd 来检测何时建立 SSH 连接进来并分配了一个终端:

    @echo off
    
    if defined SSH_CLIENT (
        :: check if we've got a terminal hooked up; if not, don't run bash.exe
        C:\cygwin\bin\bash.exe -c "if [ -t 1 ]; then exit 1; fi"
        if errorlevel 1 (
            C:\cygwin\bin\bash.exe --login
            exit
        )
    )
    

    这可以与 Cygwin bash 一起使用,不确定 Windows 附带的 bash;我想它对 TTY 代码在内部的工作方式非常敏感。
    这样,启动cmd.exe 正常工作,使用VSCode(因为它不分配PTY)正常工作,但是SSH 进入机器会启动bash.exe。

    如果将它安装在目标服务器上,我怀疑它也可以使用 Git for Windows 附带的 bash.exe

    目标文件应该在服务器上:

    %USERPROFILE%\.ssh\authorized_keys
    

    如果您可以手动操作,只需尝试使用scp,而不是使用ssh-copy-id

    scp user@server:C:/Users/<user>/.ssh/authorized_key authorized_key 
    # manual and local edit to add the public key
    scp authorized_key  user@server:C:/Users/<user>/.ssh/authorized_key
    

    (同样,我会使用 Git For Windows 附带的 scp.exe,这次安装在本地)

    【讨论】:

    • Windows 10 中附带的 bash 通常指向您的默认 WSL 发行版。根据您在 Path 上的配置,这可能指向 Cygwin 或 Git Bash。
    • @AndreiJirohEugenioHalili 但是 Windows 10 并未附带 Cygwin,是吗?
    【解决方案2】:

    找到解决方案: 遵循这个有用的 youtube 指南,支持 https://www.youtube.com/watch?v=Cs3wBl_mMH0&ab_channel=IT%2FOpsTalk-Deprecated-SeeChannelDescription

    此外,安装 OpenSSHUtils 可以使用:

    Install-Module -Name OpenSSHUtils -RequiredVersion 0.0.2.0 -Scope AllUsers
    

    本指南也有帮助:

    https://www.cloudsma.com/2018/03/installing-powershell-modules-on/

    我的服务器没有访问权限,所以我手动从以下位置复制了文件: C:\Program Files\WindowsPowerShell\Modules 到服务器的: 服务器:\Program Files\WindowsPowerShell\Modules

    【讨论】:

      猜你喜欢
      • 2021-08-26
      • 2017-04-30
      • 2021-06-23
      • 2015-06-18
      • 1970-01-01
      • 1970-01-01
      • 2020-01-18
      • 1970-01-01
      • 2021-09-14
      相关资源
      最近更新 更多