Home Linux Commands How to Download Files from Remote Linux Servers

How to Download Files from Remote Linux Servers

The mechanism of a computer user accessing different directory files on different hard disk partitions is comparatively similar to how SSH is used to access remote machines existing under a common or different network.

[ You might also like: How to Disable SSH Login to Specific User in Linux ]

This network can be public like the Internet or private like LAN (Local Area Network) and SSH makes it possible for these machines to be accessible but what about downloading their associated files?

​Prerequisites

This article is for the Linux user on a desktop environment who wishes to access and download files on a remote Linux server environment via SSH.

You need to have authenticated access to these two Linux environments and some familiarity with the Linux command-line interface.

Basic Syntax of Using SSH with SCP Command

The SSH (Secure Shell) protocol is used to enable the SCP (Secure Copy) command to successfully accomplish specific file download objectives from a Linux server environment to a Linux desktop environment.

The standard syntax of using the SSH command with the SCP command looks like the following:

$ scp username@server_url_or_ip:/path/to/downloading/file/from/server /path/to/download/location/on/desktop 

Firstly, you should know the username and the IP address or hostname of the remote server from where you wish to retrieve a specific file.

Secondly, you should accurately specify the relative path to your download file location on the remote server and the relative path to the download file storage location on your desktop computer.

Create Files in Remote Linux Using SSH

You can achieve successful file downloads from a remote Linux server environment to a Linux desktop environment through three techniques.

Before we reference the three SCP file download techniques, let us first have some files on our server that we wish to download. If these files already exist on your end, you are good to go. All you need is the files’ correct relative path.

$ ssh [email protected]

Create files on a remote Linux server.

$ touch LinuxShellTips_secrets.pdf && ls
$ touch LinuxShellTips_certification.pdf && ls
$ touch LinuxShellTips_for_beginners.pdf && ls
Create Files in Remote Linux
Create Files in Remote Linux

Let’s check out three ways to download files from a remote Linux server.

Download Remote Files Using SCP Command in Linux

In reference to the above syntax rule, we can download our first file with the following approach from your desktop environment.

$ scp [email protected]:/home/ec2-user/LinuxShellTips_secrets.pdf /home/dnyce/Desktop/files 

Check for the existence of the downloaded file:

$ cd /home/dnyce/Desktop/files && ls
Download Remote Linux Files
Download Remote Linux Files

Download Remote Files with Port Number Using SCP Command in Linux

Maybe you have defined a non-standard port or you want to use a standard port on your Linux server environment for handling all remote file downloads. In this case, you should adhere to the following syntax rule:

$ scp -P port_number username@server_url_or_ip:/path/to/download/file/on/server /path/to/download/location/on/desktop 

Let us try to download the second file we created:

$ scp -P 22 [email protected]:/home/ec2-user/ LinuxShellTips_certification.pdf /home/dnyce/Desktop/files 
Download Remote Linux Files with Port
Download Remote Linux Files with Port

From the look of things, the download was a success.

Download Remote Files with Private Key Using SCP Command in Linux

If the remote server you are using restricts you to a private key/certificate for your remote connections, worry not. You can still achieve remote file download with the following syntax.

$ scp -i private_key/certificate_file.pem username@server_url_or_ip:/path/to/download/file/on/server /path/to/download/location/on/desktop 

Let us try to download the third file we created using this approach.

$ scp -i my_file_name.pem [email protected]:/home/ec2-user/ LinuxShellTips_for_beginners.pdf /home/dnyce/Desktop/files

Your terminal instance should be on the same path as this certificate file.

Download Remote Linux Files with Private Key
Download Remote Linux Files with Private Key

Finally, let us check for the existence of the three downloaded files:

$ cd /home/dnyce/Desktop/files && ls
Verify Remote Download Files
Verify Remote Download Files

By using a wild card (*), you could download all these files at once since they have a common file extension.

$ scp [email protected]:/home/ec2-user/*.pdf /home/dnyce/Desktop/files 

This tutorial has taught us how to use SCP (Secure Copy) through the SSH protocol to accomplish specific file downloads from a remote server. The covered approaches are flexible enough to meet your remote files download needs.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.