Grow your Business Online​
Wesbytes Blue Logo

Wesbytes Knowledge Base

Search our articles or browse by category below

Transfer Files via rsync and SSH on Linux

Last modified: July 2, 2022
You are here:
Estimated reading time: 2 min

There are several tools out there for Linux and Unix users to employ when transferring files between computers on a network.

SSH and FTP are currently the most widely used data transfer protocols. Despite the fact that FTP is quite popular, we still advise using SSH. This is due to the fact that it is the most secure method of file transfer.

SSH file transfers can be done using specialist programmes like scp and sftp. None of them, however, offers all the functions that rsync does. Additionally, we may utilise rsync to copy files between systems, mirror data, perform incremental backups, and more.

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. 

Standard SSH Port:

rsync -avHe ssh [email protected]:/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” [email protected]:/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 [email protected]:/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 [email protected]:/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

Was this article helpful?
Dislike 0
Views: 6