How To Use Rsync Without Password
The rsync utility allows you to transfer and synchronize files between your PC and an external hard drive. You can also use it to send files across a local area network to all devices, but to do that, the receiving party has to enter the correct password. However, there is a trick you can use to get your devices rsynced without using any passwords. Read on to learn how to bypass the password using SSH or SCP commands.
How to RSYNC Without Using a Password
You can set up your rsync over ssh and you can then use it without a password. The feature is great for scheduling cron jobs for automatic backup when using rsync. Here is how you can work around the password.
First, you have to test out rsync over ssh while using an existing password.
Do a standard rsync like you do all the time to ensure that you are asked to enter your password on the remote server. Copy some files just to make sure that the remote server is working.
Use this example to sync your local folder/home/pies
with the remote folder/backup/pies
. Use the 192.168.188.15 server command.
After you execute this command, you will be prompted to enter your account password on the remote server: rsync -avz -e ssh /home/pies/ pies@192.168.188.15:/backup/pies/
The next step is to configure ssh to skip the part where it asks for your password. Use the ssh-keygen command on your local server to create private and public keys. Use the following command:
$ ssh-keygen
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
NOTE: After you are prompted to enter a passphrase, just leave the section blank and press Enter.
Copy the public key to your remote host by using ssh-copy-id
. Enter the following command: ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.188.15
You will then be prompted to enter the password on your remote host, and you will have to copy the public key to the right location.
Now, when everything is set up, you are ready to rsync without a password. Use this command: ssh 192.168.188.15
to rsync without entering your password. Here’s the rsync you should use: rsync -avz -e ssh /home/pies/ pies@192.168.188.15:/backup/pies/
. You can also automate this rsync backup and schedule it with cron.
Other Practical Rsync Commands in Linux
Rsync or Remote Sync can help you get a lot done quickly, and that includes copying and synchronizing files remotely. Here are some useful commands you can use to speed things up when working remotely.
Copy and Sync Files on a Computer
The command below will sync a single file on your local computer from one location to another. Copy a file called backup.tar to /tmp/backups/ folder
for it to work.
[root@tecmint]# rsync -zvh backup.tar /tmp/backups/
created directory /tmp/backups
backup.tar
sent 14.71M bytesreceived 31 bytes3.27M bytes/sec
total size is 16.18Mspeedup is 1.10
The example above is for situations where the destination folder/directory doesn’t exist in rsync already and you want to create one automatically.
Copy and Sync Directories on a Computer
The next command will sync or transfer all files from one directory to a different one on the same computer. Here’s an example: /root/rpmpkts
has some rpm package files and you want to copy it to the /tmp/backups/ folder
. Use the following command:
[root@tecmint]# rsync -avzh /root/rpmpkgs /tmp/backups/
sending incremental file list
rpmpkgs/
rpmpkgs/httpd-2.2.3-82.el5.centos.i386.rpm
rpmpkgs/mod_ssl-2.2.3-82.el5.centos.i386.rpm
rpmpkgs/nagios-3.5.0.tar.gz
rpmpkgs/nagios-plugins-1.4.16.tar.gz
sent 4.99M bytesreceived 92 bytes3.33M bytes/sec
total size is 4.99Mspeedup is 1.00
Copy and Sync Files and Directories to/from a Server
Copying a directory from the local server to a remote server is done by using the following command:
[root@tecmint]$ rsync -avz rpmpkgs/ root@192.168.0.101:/home/
root@192.168.0.101's password:
sending incremental file list
./
httpd-2.2.3-82.el5.centos.i386.rpm
mod_ssl-2.2.3-82.el5.centos.i386.rpm
nagios-3.5.0.tar.gz
nagios-plugins-1.4.16.tar.gz
sent 4993369 bytesreceived 91 bytes399476.80 bytes/sec
total size is 4991313speedup is 1.00
It will transfer the files from “rpmpkgs” folder to the remote server you want.
When you want to copy files from a remote server to your local machine, use this command:
[root@tecmint]# rsync -avzh root@192.168.0.100:/home/tarunika/rpmpkgs /tmp/myrpms
root@192.168.0.100's password:
receiving incremental file list
created directory /tmp/myrpms
rpmpkgs/
rpmpkgs/httpd-2.2.3-82.el5.centos.i386.rpm
rpmpkgs/mod_ssl-2.2.3-82.el5.centos.i386.rpm
rpmpkgs/nagios-3.5.0.tar.gz
rpmpkgs/nagios-plugins-1.4.16.tar.gz
sent 91 bytesreceived 4.99M bytes322.16K bytes/sec
total size is 4.99Mspeedup is 1.00
You can use it to sync a remote file or directory and copy it to your local machine.
Bypass the Password and Rsync Anyway
If you use Linux and a remote server a lot, it’s useful to know these commands because they can help you get things done much faster. You can now copy and sync files with these basic commands.
One thought on “How To Use Rsync Without Password”