如何处理 Windows 的 SSH 配置文件中的空格?
How to deal with spaces in SSH config file for Windows?
我目前正在使用 Git Bash 和 Windows 通过 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 之间有一个 space 字符。这导致 Git Bash 无法读取指定的路径。它打印出这个错误:/c/Users/FirstName LastName/.ssh/config line 4: garbage at end of line; "LastName\.ssh\hub".
我尝试使用引号来指定字符串,并且我尝试在 IdentityFile 路径中使用 %USERPROFILE% 变量,因此没有 spaces。
带引号的解决方案导致此错误:
no such identity: 202202202202C:\Users\FirstName LastName\.ssh\hub: No such file or directory
然后问我密码:
root@192.168.1.151's password:
%USERPROFILE% 的解决方案给我这个错误:
percent_expand: unknown key %U
所以我基本上被困在这里,关于如何解决这个问题有什么想法吗?
所以,我实际上在为 IdentityFile 使用引号时正确地解决了这个问题。问题是,当我将路径(我从 Windows Explorer 中的文件属性复制而来)粘贴到配置文件中以定义 IdentityFile 时,有些字符对编辑器是不可见的。这些字符使 Git Bash 中的 SSH 客户端感到困惑。复制路径的开头存在意外字符。
Windows 有时很古怪:/
通常,运行文件上的这个命令会删除不可见的字符:
sed -i '1s/^.*#//;s/\r$//' {FILENAME}
我目前正在使用 Git Bash 和 Windows 通过 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 之间有一个 space 字符。这导致 Git Bash 无法读取指定的路径。它打印出这个错误:/c/Users/FirstName LastName/.ssh/config line 4: garbage at end of line; "LastName\.ssh\hub".
我尝试使用引号来指定字符串,并且我尝试在 IdentityFile 路径中使用 %USERPROFILE% 变量,因此没有 spaces。
带引号的解决方案导致此错误:
no such identity: 202202202202C:\Users\FirstName LastName\.ssh\hub: No such file or directory
然后问我密码:
root@192.168.1.151's password:
%USERPROFILE% 的解决方案给我这个错误:
percent_expand: unknown key %U
所以我基本上被困在这里,关于如何解决这个问题有什么想法吗?
所以,我实际上在为 IdentityFile 使用引号时正确地解决了这个问题。问题是,当我将路径(我从 Windows Explorer 中的文件属性复制而来)粘贴到配置文件中以定义 IdentityFile 时,有些字符对编辑器是不可见的。这些字符使 Git Bash 中的 SSH 客户端感到困惑。复制路径的开头存在意外字符。
Windows 有时很古怪:/
通常,运行文件上的这个命令会删除不可见的字符:
sed -i '1s/^.*#//;s/\r$//' {FILENAME}