Question: When I perform rsync, it asks for my password on the remote server before starting the transfer. I would like to avoid this, and perform rsync without password. Can you explain with an example on how to setup rsync over ssh without password on Linux?
Answer: The following steps explains how to setup rsync over ssh that doesn’t ask for a password. This is helpful when you are scheduling a cron job for automatic backup using rsync.
1. Test rsync over ssh (with password):
Do a rsync to make sure it asks for the password for your account on the remote server, and successfully copies the files to the remote server.
The following example will synchronize the local folder /home/ramesh to the remote folder /backup/ramesh (on 192.168.200.10 server).
We discussed in detail about rsync in our previous 15 rsync examples articles.
This should ask you for the password of your account on the remote server.
rsync -avz -e ssh /home/ramesh/ ramesh@192.168.200.10:/backup/ramesh/
2. ssh-keygen generates keys.
Now setup ssh so that it doesn’t ask for password when you perform ssh. Use ssh-keygen on local server to generate public and private keys.
$ ssh-keygen Enter passphrase (empty for no passphrase): Enter same passphrase again:
Note: When it asks you to enter the passphrase just press enter key, and do not give any password here.
3. ssh-copy-id copies public key to remote host
Use ssh-copy-id, to copy the public key to the remote host.
ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.200.10
Note: The above will ask the password for your account on the remote host, and copy the public key automatically to the appropriate location. If ssh-copy-id doesn’t work for you, use the method we discussed earlier to setup ssh password less login.
4. Perform rsync over ssh without password
Now, you should be able to ssh to remote host without entering the password.
ssh 192.168.200.10
Perform the rsync again, it should not ask you to enter any password this time.
rsync -avz -e ssh /home/ramesh/ ramesh@192.168.200.10:/backup/ramesh/
If you want to schedule this rsync backup job automatically, use cron to set it up.
Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.Get the Linux Sysadmin Course Now!
If you enjoyed this article, you might also like..
|
|
|
|






My name is Ramesh Natarajan. I will be posting instruction guides, how-to, troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write articles that will either teach you or help you resolve a problem. Read more about
{ 8 comments… read them below or add one }
This is very useful, was one of the problems to research on my todo. Done now! Thanks.
Great info. NOTE: this only works if your identity key is named id_rsa.pub or id_dsa.pub. If you choose a custom name you’ll have to create/modify the ~./.ssh/config file (when rsync-ing). or use the -i flag for the ssh command.
I use rsa instead of dsa, what is your view?
Yo, thanks for the article. I learned about the ssh-copy-id command. I never used that before. How about using some options with the ssh-keygen command?
ssh -t rsa -N ” -f ~/.ssh/id_rsa_key -b 4096 -C ‘rsync backup’
@shark dsa is the default if you do not specify rsa.
Great website!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! I love it!
Excellent article. Been searching for this answer for a while now and this was just the ticket. Thanks
Great tip! Thanks!
Great, thanks !
Just a suggestion to avoid copying the empty passphrase key onto the default one.
Let’s say that the empty passphrase key as been created as ~/.ssh/id_rsa_empty.pub, and for sure the private key as well.
It is therefore possible to use it within the ssh option on the rsync command.
Reusing the command given above, it gives :
rsync -avz -e ‘ssh -i ~/.ssh/id_rsa_empty’ /home/ramesh/ ramesh@192.168.200.10:/backup/ramesh/
Hope this will help
Best regards.
J-L