scp linux – copy files securely using scp instances

This post covers SCP examples. SCP or Secure Copy allows the secure transfer 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. SCP is preferred for its simplicity, security and pre-installed availability.

scp example

Copy the file from the remote host to the local host SCP instance:

$ scp username@from_host:file.txt /local/directory/

Copy the file from the local host to the remote host SCP instance:

$ scp file.txt username@to_host:/remote/directory/

Copy the directory from the remote host to the local host SCP instance:

$ scp -r username@from_host:/remote/directory/  /local/directory/

Copy the directory from the local host to the remote hospital SCP instance:

$ scp -r /local/directory/ username@to_host:/remote/directory/

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

$ scp username@from_host:/remote/directory/file.txt username@to_host:/remote/directory/


– scp example: scp -r  root@ /home/hydn/backups/test/ Also, see Backup Solutions.

– Host can be IP or domain name. Once you click on Return, you will be asked for an SSH password.

— Although this page covers scp linux, 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 an already existing target file, SCP will replace the contents of the target file. so be careful.

Screenshot: Output of “man scp” command.

scp options:

,R Copy entire directories recursively. Note that it follows the symbolic links encountered in the tree traversal.

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

-Ale Limit – Limits the bandwidth used, specified in Kbit/s.

-This 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 letter ‘P’.

-P Preserves the modification time, access time and mode from the original file.

-Why Quiet Mode: Disables the progress meter as well as alert and diagnostic messages from SSH.

-V verbose mode. Print debugging message about progress. It is helpful in debugging connection, authentication and configuration issues.

Also, take a look at the rsync option: man rsync

Also, see Linux networking commands and scripts.

Leave a Comment