Linux SCP command for secure file transfer

Secure Copy or SCP is part of SSH. This are few examples of using SCP commands for those like me who just could not remember all the options.

On almost all Linux machines we don’t want to add additional software that we don’t need, but we need to transfer data from one host to another. SSH’s scp command will come in handy for this task.

SCP Basic Commands

The basic scp usage is like this:

scp source_file_path destination_file_path

Copy local file to remote server (Uploading):

scp local_filename.txt

Copy remote file to the local server (Downloading):

scp .

Copy local directory and all of it’s content recursively with -r parameter:

scp -r local_directory

I usually change the default SSH port and for SCP command to use that port we need to add -P parameter:

scp -r -P 22233 /path/to/local_directory

You can speed up transfers if we enable compression using the -C parameter. The files are compressed on the fly and decompressed on the destination server:

scp -rC /path/to/local_directory

If you are transferring data to a production server and you don’t want to consume the bandwidth you can limit it with -l parameter in Kbit/s. To limit the transfer to 10Mbps you need to add -l 10000, this will transfer files with around 1.2MB/s:

scp -rC -l 10000 /path/to/local_directory

To preserve file attributes like modification times, access times, and modes from the original file, use -p parameter:

scp -rCp /path/to/local_directory

I hope this will come in handy while transferring files on you Linux systems.

My most common command used is:

scp -rCp -P 22233 local_directory

For those who need more information just type man scp on your console.

SCP man pages

Nikola Stojanoski

System Administrator and Developer. Giving back to the community by blogging about my problems, solutions and practical howto's.