I am trying to consolidate my cron jobs so that everything goes through rclone instead of a mashup of plexdrive, unionfs, rclone and rsync, but I think I have run into a bug.
I am running rclone v1.39 in Ubuntu 16.04.3 LTS and trying to sync to an SSH target using ssh-agent with a password-protected private key.
On boot I run:
ssh-agent -s > ${AGENT}
. ${AGENT}
ssh-add
My cron job calls a bash script that imports ${AGENT}
The bash script successfully sets the environmental variables (which are echoed to a log file):
However, rclone throws this error when called from a cron job: NewFs: couldn't connect SSH: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
If I call the script from the command line, it runs without error, so it seems like the environmental variables are somehow not seen by rclone when called from a cron job.
The reason I think that this is a bug and not a weird shell issue is because rsync runs perfectly from the cron job. That is, I can run rsync -rP /path/ sshtarget:/path/ and rclone copy /path/ sshtarget:/path/ in the same script. When the script is called from an interactive session both commands run perfectly, but when called from cron only rsync runs; rclone throws an error.
Can you show the contents of your sshtarget config please? (redact things you don’t want public is fine - I’m mostly interested in which fields are filled in and which aren’t)
Hmmm, if you try making a new sftp, then what does it print at this point as your user name?
Storage> sftp
SSH host to connect to
Choose a number from below, or type in your own value
1 / Connect to example.com
\ "example.com"
host> example.com
SSH username, leave blank for current username, ncw <<<<<< is this your username?
user>
And does it do the same thing if you do unset USER first in the shell?
Does your script fail if you run unset USER in the shell BTW?
Can you look in the logs of the remote machine and see what user it is connecting as when it fails under the crontab?
With $USER set: SSH username, leave blank for current username, chezmojo
Without $USER set: SSH username, leave blank for current username, chezmojo
It looks like rclone is trying to connect with an empty user name (when user = in the config file and $USER is unset):
Jan 7 06:55:03 sshtarget sshd[18562]: Invalid user from xxx.xxx.xxx.xxx
Jan 7 06:55:03 sshtarget sshd[18562]: input_userauth_request: invalid user [preauth]
Jan 7 06:55:03 sshtarget sshd[18562]: Connection closed by xxx.xxx.xxx.xxx [preauth]
For example, this is what it looks like when random bots fish for default accounts:
sshd[18528]: Failed password for invalid user debian from 91.121.153.218 port 36352 ssh2
How is it determining the username? I am not very familiar with go, but if you could point me at the source code perhaps I could do some tests myself.
I don’t know, but this is far from the first time I have encountered mysterious issues with cron jobs. Ubuntu tends to spread config files all over the place making it hard to figure out exactly what cron vacuums up to configure itself before a run. I did dump env from cron and at least the environmental variables are all fine (e.g., setting $LOGNAME correctly).
Come to think of it, I ran into the same problem trying to get duplicity to backup to an SSH target (all on Ubuntu machines, too). Somehow Python was not passing the username into the backend. I was not able to solve that one and ended up calling it from a daemon spawned from an interactive session.
Currently the link (still) only shows Windows builds, so I have not been able to try it (yet).