Casbay Knowledge Base

Search our articles or browse by category below

HOW TO: Securely Transfer Files via rsync and SSH on Linux

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

HOW TO: Securely Transfer Files via rsync and SSH on Linux

By reading this article, you will learn about transferring files securely via rsync and SSH on Linux Server. Below are the steps to follow:

1) Securely Download From a Server

i) 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. Besides, 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. File is the file name.

Example:

rsync -avHe ssh [email protected]:/home/adam/testfile1 /home/localuser/testfile1

ii) Alternate SSH Port:

rsync -avHPe "ssh -pPORTNUMBERuser@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 download 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 download from the target (remote) server, where file is the file name.

Example:

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

2) Securely Upload To a Server

i) 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 [email protected]:/home/adam/testfile1

ii) 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 [email protected]:/home/adam/testfile1

You have just learned about how to securely transfer file via rsync and SSH on Linux. For other articles from the similar topic, you can check out our Knowledge Base to find out.

Was this article helpful?
Dislike 0
Previous: What is ping ?
Next: How to Configure Static IP Address on Ubuntu 18.04
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!