-->

Last Updated on 4 weeks by Sachin G

Managing files across multiple servers is a common task in any Linux-based environment. Whether you’re deploying web applications, backing up configs, or simply moving logs, you need a secure, fast, and reliable file transfer method. That’s where the SCP command in Linux comes into play. This blog post will share exactly what happened when I tried different options, what worked, what didn’t, and how you can avoid the same pitfalls.

The SCP is a secure and managed file transfer protocol for files or folders from the local system to a remote host or from a remote system to the local host. scp command usage SSH protocol in the back-end to copy files securely through encrypted data transfer and authentication. So it is the best way to copy files or folders to or from a remote host with this command. The scp command is for secure file transfers between local and remote Linux systems. It details syntax, options like -r for directories, -P for custom ports, -i for identity files, and cipher selection for performance or security optimization.

My Experience Using the SCP Command in Linux

General syntax I used :

scp  source_path_of_file_folder [remote_user@]remote_host:/file_system_location

Remote server location as well as file system writes in the format like [remote_user@]remote_host:/file_system_location . Here [remote_user@] is optional, because of if you do not mention it in the command, the current local user will be invoked to run the command and then in the command, you should mention the remote host and the file that will be copied into the file system. Before the sync of files, it authenticates the user with scp server .

How do I copy a file from the local to the remote user’s host system

Here’s what happened when I tried using the scp For the first time, between two VPS servers

scp techtransit.zip   techtransit_user@172.24.25.10:/backup/

Here in the above command, I have logged in as a user and want to copy a techtransit.zip file into another host machine through another user, techtransit_user, in the backup directory that is on another host /backup. The file was copied over SSH seamlessly.

How do I copy files from the remote user’s host system to the local system?

We can copy files from a remote host account on a local machine with scp. See below command and explanation.

scp 172.24.25.10:/tmp/techtransit.zip  /home/techtransit

Here in the above command, we are copying the techtransit.zip file from the tmp directory on the remote system ( 172.24.25.10) to the local system directory of /home/techtransit.

 What Happened When I Tried Copying Folders Using SCP

I needed to copy a full website directory from my local Linux system to a cloud-based CentOS instance. Here’s the command I ran:

scp  -r: Copy  whole directory structure recursively

The -r flag tells scp to recursively copy folders. It transferred everything — configs, media, and hidden .htaccess files — without a hiccup.

scp -r  /var/www/techtransit  remote_user@172.24.25.10:/var/www

We can send the whole directory and its files to a remote host, and also from a remote host to a local machine, as we have discussed in the above part. We only need to use the –r option.

Lesson learned from this that always use -r when copying directories.

SCP Command Syntax and Options I Use Regularly

scp -P: Copy on a different remote host port. -P Specify scp port number (useful when not the default 22)

scp -P 4433 techtransit.zip  remote_user@:172.24.25.10/directory

If your remote host uses a different port in SSH, then you need to give the port manually with the –P option. By default, it is taking 22 port of the SSH protocol .so, scp or ssh, we were using directly without options. Here in the above part remote server using different port like 4433 , so we have take after –P option 4433

scp -C: Enable compression during transfer

scp -i :  Copy through  identity private  key  file or key-based authentication using private keys

Most of the cloud servers provide login through pem or key file like private . So here is an option to copy files using PEM authentication with scp .

scp -i  techtransit.pem filename  root@EC2_PUBLIC_IP:/

Here I am shown example of my PEM key with option -i.

How I Transferred Files Between Remote Linux Servers

When managing multiple cloud nodes, I often need to copy files with scp between remote Linux machines — not just local-to-remote. That’s trickier because scp doesn’t allow direct remote-to-remote copying without some creative tunneling.

Instead, I SSH’d into one server and pulled files from another using:

scp user@remote1:/etc/nginx/nginx.conf user@remote2:/tmp/
 

Which — as expected — failed.

So I downloaded locally first, then re-uploaded:

scp user@remote1:/etc/nginx/nginx.conf .
scp nginx.conf user@remote2:/tmp/

Use rsync if you need direct server-to-server copies.

Why I Prefer SCP for Secure File Transfer

SCP is based on OpenSSH, ensuring encrypted, secure file transfer over SSH. While it’s being replaced by more modern tools like sftp or rsync, it still holds its place when simplicity and quick transfers matter.

For sensitive configs and backups, I always opt for transferring files securely in Linux using scp over a hardened SSH connection.

Frequently Asked Questions

Is scp better than Rsync for file transfer?

For quick and small transfers, SCP is simpler. But scp vs rsync leans in favor of rsync for large-scale syncs or server-to-server copies with retry support.

How can I use scp to transfer files between Linux servers?

You’ll typically download to your local machine first, then upload to the other remote server unless using rsync or special SSH configuration.