How to Securely Transfer Files via rsync and SSH on Linux

Reading Time: 2 minutes

Pre-Flight Check

  • These instructions are intended specifically for transferring files between servers via rsync and SSH on Linux.
  • I’ll be working from a Liquid Web Core Managed CentOS 7 server, and I’ll be logged in as root.

Use These Commands to Securely Download From a Server

Standard SSH Port:

rsync -avHe ssh user@server:/path/to/file /home/user/path/to/file

  • user: The username of the remote user through which you’ll be logging into the target (remote) server.
  • server: The hostname or IP address of the target (remote) server.
  • /path/to/file: The path to the file that needs to be downloaded from the target (remote) server, where file is the file name.
  • /home/user/path/to/file: The local path where you would like to store the file that is downloaded from the target (remote) server, where file is the file name.

Example:

rsync -avHe ssh adam@web01.adamsserver.com:/home/adam/testfile1 /home/localuser/testfile1

Alternate SSH Port:

rsync -avHPe "ssh -pPORTNUMBER" user@server:/path/to/file /home/user/path/to/file

  • PORTNUMBER: The port number for SSH on the target (remote) server.
  • user: The username of the remote user through which you’ll be logging into the target (remote) server.
  • server: The hostname or IP address of the target (remote) server.
  • /path/to/file: The path to the file that needs to be downloaded from the target (remote) server, where file is the file name.
  • /home/user/path/to/file: The local path where you would like to store the file that is downloaded from the target (remote) server, where file is the file name.

Example:

rsync -avHPe "ssh -p1337" adam@web01.adamsserver.com:/home/adam/testfile1 /home/localuser/testfile1

Use These Commands to Securely Upload To a Server

Standard SSH Port:

rsync -avH /home/user/path/to/file -e ssh user@server:/path/to/file

  • /home/user/path/to/file: The local path where the file that will be uploaded to the target (remote) server exists, where file is the file name.
  • user: The username of the remote user through which you’ll be logging into the target (remote) server.
  • server: The hostname or IP address of the target (remote) server.
  • /path/to/file: The remote path for the file that will be uploaded to the target (remote) server, where file is the file name.

Example:

rsync -avH /home/localuser/testfile1 -e ssh adam@web01.adamsserver.com:/home/adam/testfile1

Alternate SSH Port:

rsync -avHPe "ssh -pPORTNUMBER" /home/user/path/to/file -e ssh user@server:/path/to/file

  • PORTNUMBER: The port number for SSH on the target (remote) server.
  • /home/user/path/to/file: The local path where the file that will be uploaded to the target (remote) server exists, where file is the file name.
  • user: The username of the remote user through which you’ll be logging into the target (remote) server.
  • server: The hostname or IP address of the target (remote) server.
  • /path/to/file: The remote path for the file that will be uploaded to the target (remote) server, where file is the file name.

Example:

rsync -avHPe "ssh -pPORTNUMBER" /home/localuser/testfile1 -e ssh adam@web01.adamsserver.com:/home/adam/testfile1

Avatar for J. Mays

About the Author: J. Mays

As a previous contributor, JMays shares his insight with our Knowledge Base center. In our Knowledge Base, you'll be able to find how-to articles on Ubuntu, CentOS, Fedora and much more!

Latest Articles

How to use kill commands in Linux

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change the root password in WebHost Manager (WHM)

Read Article