Linux – Rsync –password-file Not Working

backuplinuxrsyncssh

I made a shell backup script that uses Rsync and I am trying to get rid of the password prompt because it will use a CRON to run. I have set my variable in my shell script at:

PASSWORD_FILE=rsync_password

and the password in that file only takes up 1 line.

However when I run (ignore $DESTINATION)

rsync -aRvz tmp $DESTINATION --password-file=$PASSWORD_FILE

It still gives me the prompt. How can I accomplish this? I cannot allow a prompt and I do not want to have to use keys.

Thanks

Best Answer

--password-file only sets a password if you're using the rsync daemon. It has no effect when using rsync over rsh or ssh.

The recommended authentication method over ssh is to use public keys. It's both the secure method and the simple method. Generate a private key on the client side (ssh-keygen) and run ssh-copy-id to copy it to the server.

If there's an extremely good reason why you're not using ssh keys (hint: there probably isn't), you can use expect to insert the SSH password into the stream. It's not supposed to be easy to do, in fact SSH is designed to make this difficult, for good reason (passwords are bad for security, and the way you're using that password makes it particularly exposed).

Related Question