The rsync (remote synchronization) utility copies an ordinary file or directory hierarchy locally or from the local system to or from another system on a network. By default, this utility uses OpenSSH to transfer files and the same authentication mechanism as OpenSSH; it, therefore, provides the same security as OpenSSH. The rsync utility prompts for a password when it needs one.
$ rsync -avz /data root@srv::files Password:
Although, sometimes you may not want rsync to prompt you for the password. For example, if you want to have a rsync job to be scheduled in crontab, it is required to have a passwordless rsync operation.
There are two ways of using rsync without prompting for a password:
1. use the RSYNC_PASSWORD environment variable
2. –password-file option.
1. Method using the environment variable
1. In this method we set the environment variable RSYNC_PASSWORD before using the rsync command. For example:
$ export RSYNC_PASSWORD=secret
Here, “secret” is the password used. Now you can use the rsync command and it should not prompt you for the password anymore.
$ rsync -avz /data root@srv::files
You can also export the variable RSYNC_PASSWORD in a script if you want. But make sure the script is readable only by you and not anyone else.
2. Another way is to specify the environment variable RSYNC_PASSWORD in the rsync command itself. For example:
$ RSYNC_PASSWORD=secret rsync -avz /data root@srv::files
2. Method using the --password-file option1. In this method we create a password file as shown below. Make sure the password file is not world readable ( having permission 600).
$ echo passw0rd > user1.secret $ chmod 600 user1.secret
2. Now run the rsync command with the --password-file option and specifying the password file you just created.
$ rsync -avz --password-file user1.secret /data root@srv::files
For more details, see the manual page for rsync with:
# man rsync