简体   繁体   中英

SSH from rsync on Windows

My build script uploads to production using rsync via ssh . Normally, I deploy from a Linux box, but I want to be able to deploy from Windows, too, for those times when I need to make a quick change and only have access to my Windows machine. However, I'm having trouble. Here's the relevant part of the verbose output. The first line is printed by my build script, while the rest are printed by either rsync or programs it calls (ie, I don't call SSH directly).

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:

I think the key is what directories it's searching for. Notice that it can't create /home/Scott/.ssh . Naturally, it can't do this, since /home doesn't exist on a Windows machine. $HOME returns /c/Users/Scott , so even if it's looking for UNIX-style variables, it shouldn't get confused. In addition, the fact that it's asking for a password instead of using my key shows that my .ssh directory isn't getting found.

Here's my setup.

  • I'm calling my scripts from Git Bash, and as far as I can tell, the SSH on my system is the one that Git installed. Running ssh directly from the command line works as expected.
  • I used Chocolatey to install rsync .
  • My build script is in Python and runs on Python 3.7.

Any ideas what might be going on?

I found the answer in a comment posted on Chocolatey's rsync page . The issue is that choco 's rsync inexplicably ships with a bundled SSH, and that ssh is broken. Of course, it doesn't make any sense to include SSH with rsync as they're two entirely separate programs. I tried renaming the bundled SSH, but that didn't work. The comment below did, however:

The user 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM