Back to top

Linux – Secure Copy (scp)

Using SCP

Secure Copy or SCP is a means of securley transferring files between two machines on a network. SCP uses SSH for improved security and will prompt you if it needs a password or passphrase for authentication.

Any file name may contain a host and user specification to indicate that the file is to be copied to or from that host.

Copies between two remote hosts are permitted.

Syntax

The general form used for command line scp is as follows:

scp [options] [path to source file] [user_name@remote_host]:[path to destination file]

Examples

To copy a file from a local machine to a remote machine and preserve the filename - you would use the following:

scp /home/user_name/filename user_name@elstar.compbio.cornell.edu:/home/user_name/

To copy a file from a local machine to a remote machine and create a new filename - you would use the following:

scp /home/user_name/filename user_name@elstar.compbio.cornell.edu:/home/user_name/new_filename

To copy a directory from a local machine to a remote machine and preserve the directory name - you would use the following:

scp /home/user_name/directoryname user_name@elstar.compbio.cornell.edu:/home/user_name

To copy a directory from a local machine to a remote machine and create a new directory name - you would use the following:

scp /home/user_name/directoryname user_name@elstar.compbio.cornell.edu:/home/user_name/new_directoryname

Common Options

-2
Forces scp to use protocol 2.
-C
Compression enable. The -C flag is passed to ssh to enable compression
-p
Preserves modification times, access times, and modes from the original file.
-r
Recursively copy entire directories.
-v
Verbose mode, casues SCP and SSH to print debugging messages about their progress.

Additional Information

For more information, you can always consult the following man page(s):

  • man scp