How to make rsync recognize ssh publickey when run from script (nodejs)

A strange problem here.

Running rsync script call through ssh throws

"Permission denied (publickey). Rsync: connection unexpectedly closed (0 bytes received so far) [receiver]"

strange:

  • ssh user @host works, so all ssh keys are configured correctly
  • logging and inserting the command created by the script in the terminal works
  • running whoami from the script shows the correct user, and the environment is passed to the spawn instance via process.env
  • running ssh user @host from the script does not throw an error and returns a buffer, so it seems to work
  • running a script (which just runs an already verified command) will throw the above error

    var spawn = require('child_process').spawn; spawn('rsync', [ '-avc', '--delete', '"'+src+'"' , '--link-dest="'+path.join(dest, folder_name)+'"', '"'+path.join(dest, 'latest/')+'"' ],{ cwd: process.cwd(), env: process.env }); 
+4
source share
1 answer

Try to specify the key path

 rsync -avz -e "ssh -i /home/thisuser/cron/thishost-rsync-key" remoteuser@remotehost :/remote/dir /this/dir/ 
+2
source

All Articles