Method of synchronizing files by executing rsync through ssh without a password

  • 2020-05-13 04:07:05
  • OfStack

1. rsync via ssh (password required)

rsync is executed through the ssh account (password required) to synchronously mirror the files to the remote server.
The following example synchronizes the local /home/ramesh to the remote directory /backup/ramesh(server address 192.168.200.10).
When you do the following, the server will prompt the user to log in with a password.


rsync -avz -e ssh /home/ramesh/ ramesh@192.168.200.10:/backup/ramesh/

2. Generate keys using ssh-keygen

Now let's set up ssh so that we don't need a password to perform the ssh operation, and use ssh-keygen to generate the public and private keys locally.


$ ssh-keygen
Enter passphrase (empty for no passphrase):
Enter same passphrase again:

Tip: when prompted for a password, just enter the enter key twice. No password characters are assigned.

3. Copy the public key to the remote host using ssh-copy-id

Execute ssh-copy-id and copy the public key generated by ssh-keygen to the remote host.


ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.200.10

Tip: when you do this, you will be prompted for a remote host account and password, and the public key will be automatically copied to the remote directory.

4. No password is required to execute rsync via ssh

You can now ssh to a remote host without requiring a password


ssh 192.168.200.10

If you execute rsync again, you should not be prompted for your password now


rsync -avz -e ssh /home/ramesh/ ramesh@192.168.200.10:/backup/ramesh/


Related articles: