SCP Command Line Examples – Transferring files from one Linux host to another

Copy file from a remote host to local host SCP example:

scp [email protected]_host:file.txt /local/directory/

Copy file from localhost to a remote host SCP example:

scp file.txt [email protected]_host:/remote/directory/

Copy all files and folders from a directory on a local host to a remote host

scp -rp /local-host/www/website-name/* [email protected]:/remote-host/website-name/public_html/


Copy directory from a remote host to local host SCP example:

scp -r [email protected]_host:/remote/directory/  /local/directory/


Copy directory from localhost to a remote hos SCP example:

scp -r /local/directory/ [email protected]_host:/remote/directory/


Copy file from the remote host to remote host SCP example:

scp [email protected]_host:/remote/directory/image.jpg [email protected]_host:/remote/directory/

How can I use SCP with AWS EC2 instances?

The same command as above, but for Amazon AWS EC2 remote hosts

scp -rp -i /LightsailDefaultPrivateKey-eu-west-2.pem /local-host/website-name/public_html/* [email protected]:/remote-host/www/website-name/

You must first upload and reference your AWS EC2 private key as shown above. Furthermore, in order for this to work, you must set the correct permissions to your PEM key using the following command

chmod 400 /awskeyfile.pem

What SCP Linux options can I use?

SCP has 8 different options you can use, all listed below:

r Recursively copy entire directories. Note that this follows symbolic links encountered in the tree traversal.

-C Compression enable. Passes the -C flag to ssh to enable compression.

-l limit – Limits the used bandwidth, specified in Kbit/s.

-o ssh_option – Can be used to pass options to ssh in the format used in ssh_config.

-P port – Specifies the port to connect to on the remote host. Note that this option is written with a capital ‘P’.

-p Preserves modification times, access times, and modes from the original file.

-q Quiet mode: disables the progress meter as well as warning and diagnostic messages from ssh.

-v Verbose mode. Print debugging messages about progress. This is helpful in debugging connection, authentication, and configuration problems.

Join the thousands of websites that trust Koerge.


Receive WordPress tips, tricks and news straight to your inbox every week.