Is it possible to give the server password within the rsync command?
rsync -zvr source destination password
I am developing a web application in Django using rsync protocol. I use a form to take password input from the user. I want to use that password like this in the rsync command itself? How can I do it? I am sure there's a way using stdin, pipe or something like that. Thanks
From man rsync
:
Some modules on the remote daemon may require authentication. If so, you will receive a password prompt when you connect. You can avoid the password prompt by setting the environment variable
RSYNC_PASSWORD
to the password you want to use or using the--password-file
option. This may be useful when scripting rsync.
And regarding --password-file
:
This option allows you to provide a password in a file for accessing a remote rsync daemon. Note that this option is only useful when accessing an rsync daemon using the built in transport, not when using a remote shell as the transport. The file must not be world readable. It should contain just the password as a single line.
So, either set the RSYNC_PASSWORD
environment variable before calling rsync
, or use a temporary file and pass it to the command; The first option is probably easier, using env
:
env RSYNC_PASSWORD=PASSWORD rsync -zvr source destination
Update: Note this little nugget under --password-file
:
Note that this option is only useful when accessing an rsync daemon using the built in transport, not when using a remote shell as the transport.
If you're not using the rsync
built-in transport, but perhaps SSH, you cannot use this method to "automatically" authenticate. If you're using SSH, you should use public/private keys, or possibly the ASK_SSHPASS
trick (See this).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With