$linuxjunkies
>

scp(1)

Securely copy files between hosts using SSH protocol.

UbuntuDebianFedoraArch

Synopsis

scp [OPTION]... [[user@]host1:]file1 ... [[user@]host2:]file2

Description

scp copies files between hosts on a network using SSH for authentication and encryption. It can transfer files from local to remote, remote to local, or between two remote hosts. The syntax follows the pattern [user@]host:path for remote files and plain paths for local files.

scp is secure by default, encrypting all data in transit. It authenticates using SSH keys or passwords (if configured) and uses the same authentication mechanism as ssh.

Common options

FlagWhat it does
-rRecursively copy entire directories
-P portSpecify SSH port (default 22)
-pPreserve file modification times and permissions
-CEnable compression during transfer
-vVerbose output; show transfer progress and debug info
-i identity_fileUse specified private key for authentication
-o optionPass SSH option (e.g., StrictHostKeyChecking=no)
-l limitLimit bandwidth to specified Kbit/s
-qQuiet mode; suppress progress meter and non-error messages

Examples

Copy local file to remote host's home directory

scp file.txt user@remote.com:/home/user/

Copy remote file to current local directory

scp user@remote.com:/home/user/file.txt .

Recursively copy entire local directory to remote host

scp -r /local/folder user@remote.com:/remote/path/

Copy file using non-standard SSH port 2222

scp -P 2222 file.txt user@remote.com:/tmp/

Copy between two remote hosts using specific key and preserving permissions

scp -i ~/.ssh/id_rsa -p user@host1:/file.txt user@host2:/tmp/

Copy large file with compression and 1 Mbps bandwidth limit

scp -C -l 1024 largefile.zip user@remote.com:~/

Recursively copy with verbose output showing transfer details

scp -r -v /local/src/ user@remote.com:~/backup/

Related commands