I need to have a script periodically rsync files from a remote host via ssh. The account which the script runs under does not have home directory on the remote host, so I'm not able to store my public key on the remote host. I'm happy to store my password in a file on my local host, but I can't seem to get rsync to use the password.
The --password-file
option is only an option for connecting to an rsync daemon, and the password prompt does not read from stdin.
Have you looked at using expect?
Look for the program
sshpass
in your distribution. Once you have it, you can do:or, putting everything in one file:
You might want to look into changing the
AuthorizedKeysFile
option in the remote server'ssshd_config
, if that's an option, so you may have your public key set up there without a home directory. In that case, it would be something like/home/%u/.ssh/authorized_keys
, to minimize potential conflicts with other users on the system.