【问题标题】:How to deal with spaces in SSH config file for Windows?如何处理 Windows 的 SSH 配置文件中的空格?
【发布时间】:2020-07-18 05:36:50
【问题描述】:

我目前正在使用带有 Windows 的 Git Bash 来通过 SSH 连接到 Linux 服务器。

正在使用目录中的配置文件:“C:\Users\FirstName LastName.ssh\config”

配置文件如下所示:

Host hub
    HostName 192.168.1.151
    User root
    IdentityFile ‪‪‪‪C:\Users\FirstName LastName\.ssh\hub

如您所见,IdentityFile 中的 Firstname 和 LastName 之间有一个空格字符。这导致 Git Bash 无法读取指定的路径。它打印出这个错误:/c/Users/FirstName LastName/.ssh/config line 4: garbage at end of line; "LastName\\.ssh\\hub".

我尝试使用引号指定字符串,并尝试在 IdentityFile 路径中使用 %USERPROFILE% 变量,因此没有空格。

带引号的解决方案导致这个错误:

no such identity: \342\200\252\342\200\252\342\200\252\342\200\252C:\\Users\\FirstName LastName\.ssh\\hub: No such file or directory

然后问我密码:

root@192.168.1.151's password:

%USERPROFILE% 的解决方案给了我这个错误:

percent_expand: unknown key %U

所以我基本上被困在这里,关于如何解决这个问题的任何想法?

【问题讨论】:

    标签: windows ssh path config git-bash


    【解决方案1】:

    所以,在使用 IdentityFile 引号时,我实际上是正确地解决了这个问题。问题是,当我将路径(我从 Windows 资源管理器中的文件属性复制)粘贴到配置文件中以定义 IdentityFile 时 - 有一些字符对编辑器是不可见的。这些字符使 Git Bash 中的 SSH 客户端感到困惑。复制路径的开头出现了意外字符。

    Windows 有时很奇怪:/

    通常,对文件运行此命令将删除不可见字符:

    sed -i '1s/^.*#//;s/\r$//' {FILENAME}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-24
      • 2013-12-17
      • 2011-06-15
      • 2023-03-22
      • 1970-01-01
      相关资源
      最近更新 更多