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 [email protected]:/remote/server/directory

Copy remote file to the local server (Downloading):

scp [email protected]:/remote/server/directory/remote_filename.txt .

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

scp -r local_directory [email protected]:/path/to/remote/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 [email protected]:/path/to/remote/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 [email protected]:/path/to/remote/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 [email protected]:/path/to/remote/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 [email protected]:/path/to/remote/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 [email protected]:~/directory

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

SCP man pages

Notify of
Inline Feedbacks
View all comments