Linux – How to Securely Copy Files Using SCP

Secure copy or SCP allows secure transferring of files between a local host and a remote host or between two remote hosts. It uses the same authentication and security as the Secure Shell (SSH) protocol from which it is based.

Basic secure copy examples:

Copy file from a remote host to local host:

 

Copy file from local host to a remote host:

 

Copy directory from a remote host to local host:

 

Copy directory from local host to a remote host:

 

Copy file from remote host to remote host:

Notes: 

– Example:  scp -r  root@123.123.123.123:/var/www/html/ /home/hydn/backups/test/

– Host can be IP or domain name. Once you click return, you will be prompted for SSH password.

– Although this page covers Linux OS, the instructions will also work for Mac using “Terminal”. You can also use WinSCP to accomplish this on a Windows PC/server.

– When copying a source file to a target file which already exists, scp will replace the contents of the target file. So be careful.

– SCP is faster and more secure than FTP.

SCP options:

-r Recursively copy entire directories. Note that scp 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. Causes scp and ssh to print debugging messages about their progress. This is helpful in debugging connection, authentication, and configuration problems.

Linux – How to Securely Copy Files Using SCP was last modified: September 16th, 2013 by Hayden James
No comments yet.

Leave a Reply