【问题标题】:ssh-copy-id on windows doesn't work: No such file or directoryWindows 上的 ssh-copy-id 不起作用:没有这样的文件或目录
【发布时间】:2020-08-22 13:46:11
【问题描述】:

我想将公钥从 Windows 系统复制到我的服务器。 我遇到的问题是,我没有找到钥匙的路径。 我试过这样的事情:

ssh-copy-id -i C:/Users/username/.ssh/mykey.pub user@serverIP

ssh-copy-id -i ~/.ssh/mykey.pub user@serverIP

结果总是

没有这样的文件或目录

我做错了什么?我在 Windows 10

上为此使用 Git Bash

【问题讨论】:

    标签: windows ssh git-bash


    【解决方案1】:

    Git 的 ssh 是 OpenSSH 的一个版本。您可以通过在path\to\git\usr\bin 下运行ssh -V 来确认它。这是它在我的机器上评估的结果:

    OpenSSH_7.7p1, OpenSSL 1.0.2o  27 Mar 2018
    

    ssh-copy-id 脚本在内部执行一些 *nix shell 命令(如 execcat 等。您可以通过在文本模式下打开 path\to\git\usr\bin 下的命令来找到更多信息),因此它仅适用于 *nix机器。这就是为什么path\to\git\usr\bin下的ssh-copy-id不是可执行文件的原因。

    根据PowerShell/Win32-OpenSSH 中的this issue,Windows 不支持ssh-copy-id

    但是,有一些替代方法可以做同样的事情:

    this answer 的 powershell 版本可以是

    Get-Content $env:USERPROFILE\.ssh\id_rsa.pub | ssh <user>@<hostname> "cat >> .ssh/authorized_keys"
    

    还有一个 python 脚本可以做同样的事情:ssh-copy-id for Windows

    【讨论】:

      猜你喜欢
      • 2018-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-28
      • 1970-01-01
      • 2018-03-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多