On Unix-like operating systems, the scp command copies files over a secure, encrypted network connection.

scp stands for “secure copy.” It is similar to the standard Unix command, cp, but it operates over a secure network connection.

Description

The scp command can be thought of as a network version of cp. For example, you might use the following cp command:

  • Description
  • Copying files
  • Syntax
  • Examples
  • Related commands
  • Linux commands help

cp /home/stacy/images/image*.jpg /home/stacy/archive

…which would copy all files in the directory images in user stacy’s home directory whose name starts with “image” and ends in “.jpg” into the directory archive in her home directory.

Similarly, you could use the scp command:

scp /home/stacy/images/image*.jpg [email protected]:/home/stacy/archive

…to upload those same files to the server myhost.com, using the login name stacy, into the remote directory /home/stacy/archive. scp will ask for stacy’s remote password before initiating the upload.

Or, you could specify a remote location as the source location if you want to download files. For example,

scp [email protected]:/home/stacy/archive/image*.jpg /home/stacy/downloads

…would download all the files in the remote directory /home/stacy/archive on myhost.com whose name starts with “image” and ends in .jpg, into the local directory /home/stacy/downloads.

You can also specify a remote host as both the source and destination. For instance, the following command will transfer a file from one remote directory on myhost.com to another directory on the same server:

scp [email protected]:/home/user/dir1/file.txt [email protected]:/home/user/dir2

…while this command will transfer a file from one remote host to another:

scp [email protected]:/somedir/somefile.txt [email protected]:/anotherdir

Keep in mind that all scp transfers have the benefit of being secure: they are encrypted, like an ssh or sftp session.

Copying files

scp copies files securely between hosts on a network. It uses ssh for data transfer, and uses the same authentication and provides the same security as ssh. Unlike rcp, scp will ask for passwords or passphrases if they are needed for authentication.

File names may contain a user and host specification to indicate that the file is to be copied to/from that host. Local file names can be made explicit using absolute or relative pathnames to avoid scp treating file names containing ‘:’ as host specifiers. Copies between two remote hosts are also permitted.

Syntax

scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 … [[user@]host2:]file2

Options

Examples

scp myfile.txt [email protected]:myfile.txt

Copies the file myfile.txt to the remote host example.computerhope.com, using the username hope to log in.

scp [email protected]:/home/hope/* .

Copies all files in the remote directory /home/hope on the remote host myremotehost.com into the local working directory.

scp -r [email protected]:/home/jeff/documents /home/jeff/downloads/documents

Copies all files in the remote directory /home/jeff/documents on the server myhost.com, including all subdirectories and the files they contain, into the local directory /home/jeff/downloads/documents.

scp -l 100 [email protected]:/home/jeff/archive.zip .

Transfer the remote file /home/jeff/archive.zip on the remote host myhost.com as the user jeff into the local working directory, and limit the transfer to 100 kilobytes per second.

scp [email protected]:/files/file1.zip [email protected]:/archives

Copies the file in the remote directory /files/file1.zip on the remote host firsthost.com into the remote directory /archives on the remote host secondhost.com. You will be prompted to enter the passwords for the remote accounts [email protected] and [email protected], respectively. The transfer will go directly from one remote host to the other.

scp -3 [email protected]:/files/file1.zip [email protected]:/archives

Same as the above command, but rather than directly transferring the file from one remote host to the other, the transfer is routed through the local host.

rcp — Copy files to or from a remote system.sftp — Conduct an interactive FTP session over a secure network connection.slogin — Login to a remote system securely.