在 Windows 上从 rsync 使用 SSH

SSH from rsync on Windows

我的构建脚本通过 ssh 使用 rsync 上传到生产环境。通常,我从 Linux 框进行部署,但我也希望能够从 Windows 进行部署,以便在我需要进行快速更改并且只能访问我的 [=39] 的时候使用=] 机。但是,我遇到了麻烦。这是详细输出的相关部分。第一行由我的构建脚本打印,其余由 rsync 或它调用的程序打印(即,我不直接调用 SSH)。

Executing the rsync command: ['rsync', '--verbose', '-avzihhhc', '--exclude=/.well-known', '--exclude', 'deploy.sh', '--delete', '..\scottseverance.mss\_site\', 'myuser@myhost:/home/public']
opening connection using: ssh -l myuser myhost rsync --server -vvnlogDtprcze.iLsfxC "--log-
format=%i" --delete . /home/public  (11 args)
Could not create directory '/home/Scott/.ssh'.
The authenticity of host 'myhost (host's ip address)' can't be established.
ECDSA key fingerprint is SHA256:a+Ny0PLkKhm80+5kqzqfVXIlbkQpn/CpMMrzurd8sDI.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/Scott/.ssh/known_hosts).
myuser@myhost's password:

我认为关键在于它正在搜索的目录。请注意,它无法创建 /home/Scott/.ssh。当然,它不能这样做,因为 /home 在 Windows 机器上不存在。 $HOME returns /c/Users/Scott,所以即使它正在寻找 UNIX 风格的变量,也不应该混淆。此外,它要求输入密码而不是使用我的密钥这一事实表明找不到我的 .ssh 目录。

这是我的设置。

知道会发生什么吗?

我在 Chocolatey's rsync page 上发表的评论中找到了答案。问题是 chocorsync 莫名其妙地附带了一个捆绑的 SSH,并且 ssh 被破坏了。当然,将 SSH 与 rsync 包括在一起没有任何意义,因为它们是两个完全独立的程序。我尝试重命名捆绑的 SSH,但这没有用。然而,下面的评论确实如此:

用户Adam wrote:

Kind of broken SSH!

The ssh that comes with rsync is effectively not working because it looks for the user home directory in the wrong place. You can fix this by creating C:\ProgramData\chocolatey\lib\rsync\cwRsync_5.5.0_x86_Free\etc\nsswitch.conf containing db_home: /%H. Would be nice to have the installer creating it. But then when you use PubkeyAuthentication or a per user ssh config, it complains about too open permissions, which can be fixed by running

set key=".ssh\id_rsa"
icacls %key% /c /t /inheritance:d
icacls %key% /c /t /grant %username%:F
icacls %key% /c /t /remove Administrator BUILTIN\Administrators BUILTIN Everyone System Users
icacls %key%

The ssh from the openssh package does not have this problem.