How to run Rsync through SSH tunnel

Run Rsync through SSH tunnels.

You can run Rsync through a SSH tunnel easily.

Use -e parameter to run Rysnc through a SSH tunnel. In this example, we'll run Rsync from local destination to a remote destination:

$ rsync -e ssh SRC_FOLDER USER@HOST:DEST_FOLDER

It's the same if you want to sync the remote destionation to a local destination:

$ rsync -e ssh USER@HOST:SRC_FOLDER DEST_FOLDER

Here's what these options mean:

  • SRC_FOLDERis the source directory
  • DEST_FOLDERthe destination directory
  • USERis the remote SSH username
  • HOSTis the remote SSH host or IP address

Here's a full command to transfer a local ZIP archive to a remote destination folder using SSH tunnel:

$ rsync -a /home/ubuntu/Documents/code.zip user@18.18.18.18:/var/www/

It's the same if you want to transfer from the remote destination folder over to your local folder:

$ rsync -a user@18.18.18.18:/var/www/code.zip /Documents/ubuntu/home

The -a option means "archive mode" which can be used to sync directories, transfer files, and preserve ownership and permissions.