Linux: Rsync with SSH without prompting for password

Posted: June 28, 2013 in Linux
Tags: ,

Rsync is a powerful tool that you can use it to backup local files to a remote server. Below is the command:

rsync -az -e ssh /files/to/be/backup

To use a different ssh port, e.g., 123:

rsync -az -e ‘ssh -p 123’ /files/to/be/backup

To use a different ssh user:

rsync -az -e ‘ssh -p 123’ /files/to/be/backup anotheruser@

The terminal will prompt for password before proceed.

To rsync without prompting for password, we can generate a ssh public key and add it to backup server’s ssh authorized keys. Below are the steps.

Assuming the file server is ServerA and backup server is ServerB

  1. Genarate the public key in ServerA: $ssh-keygen -t rsa
  2. The public key will be generated and stored in ~/.ssh/
  3. Open, copy the content
  4. Login to ServerB using the same user in the rsync command
  5. In ServerB, append the contents to ~/.ssh/authorized_keys. Create the file if not exist. Make sure the file mode is 700.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s