Casbay Knowledge Base

Search our articles or browse by category below

Transfer Files via rsync and SSH on Linux

Last updated: January 18, 2023
Estimated reading time: 2 min

Transfer Files via rsync and SSH on Linux

When it comes to transferring files between systems on the network, there are tons of tools available out there for Linux and Unix users.

Nowadays, the most popular protocols for data transfer are SSH and FTP. However, while FTP is very popular, we would still recommend you to use SSH. This is because it is the most secure way to transfer your files.

There are specialized tools for file transfer over SSH like scp and sftp. However, none of them has all the features that rsync provides. Furthermore, we can use rsync for mirroring data, incremental backups, copying files between systems, and so on.

Before we start, make sure you have the rsync utility installed on both the destination and the source systems. If not, you can install it using your distribution’s package manager:

Ubuntu and Debian:

sudo apt install rsync

CentOS and Fedora:

sudo yum install rsync

Also, you should also have accessed SSH on your computer.

Well, here is how to Securely Transfer Files via rsync. 

rsync

Standard SSH Port:

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

  • user: The username of the remote client through which you’ll be signing into the target (remote) server.
  • server: The hostname or IP address of the target (remote) server.
  • /path/to/file: The direction to the file that needs to be downloaded from the target (remote) server. where the file is the file name.
  • /home/user/path/to/file: The local path where you want to save the downloaded file. From the target (remote) server where the file is the file name.

For example:

rsync -avHe ssh [email protected]:/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 client 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 direction to the file that needs to be downloaded from the target (remote) server, where the file is the file name.

For example:

rsync -avHPe “ssh -p1337” [email protected]:/home/adam/testfile1 /home/localuser/testfile1

Next, here is how to 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 the 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 the file is the file name.

For example:

rsync -avH /home/localuser/testfile1 -e ssh [email protected]:/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 you want to save the downloaded file. From the target (remote) server where the file is the file name.
  • user: The username of the remote client through which you’ll be signing into the target (remote) server.
  • server: The hostname or IP address of the target (remote) server.
  • /path/to/file: The direction to the file that needs to be downloaded from the target (remote) server. where the file is the file name.

For example:

rsync -avHPe “ssh -pPORTNUMBER” /home/localuser/testfile1 -e ssh [email protected]:/home/adam/testfile1

Seems like you have just learned about transferring files via rsync and SSH on Linux. What is coming next? For more information about the security tips on operating systems (OS), please click here.

Was this article helpful?
Dislike 0
Previous: Working with MySQL database engines
Next: HOW TO: Install and configure Node.js
Discover the perfect balance of performance and budget-friendly Dedicated Server plan !
Discover the perfect balance of performance and budget-friendly Dedicated Server plan !
High performance and low cost Dedicated Server plan 128GB from $185 – upgrade today!
High performance and cheap Dedicated Server plan 128GB from $185 – upgrade today!