scp (Secure Copy Protocol) copies files and directories between hosts over SSH.
It uses SSH for authentication and encryption, so no extra setup is needed beyond
an existing SSH configuration.
General syntax:
scp [options] <source> <destination>
Remote paths use the format user@host:/path.
scp /local/path/file.txt user@host:/remote/path/
scp user@host:/remote/path/file.txt /local/path/
scp user1@host1:/path/file.txt user2@host2:/path/
Use -r to copy a full directory tree.
scp -r /local/dir user@host:/remote/path/
scp -i ~/.ssh/id_rsa /local/file.txt user@host:/remote/path/
scp -P 2222 /local/file.txt user@host:/remote/path/
NOTE: The port flag for
scpis uppercase-P, unlikesshwhich uses lowercase-p.
scp -p /local/file.txt user@host:/remote/path/
Value is in Kbits/s.
scp -l 1024 /local/file.txt user@host:/remote/path/
scp -v /local/file.txt user@host:/remote/path/
| Option | Description |
|---|---|
-r |
Recursive copy (directories) |
-P <port> |
Non-standard SSH port |
-i <key> |
Private key file |
-p |
Preserve file timestamps and permissions |
-l <kbps> |
Limit transfer bandwidth |
-v |
Verbose mode |
-C |
Enable compression |
-q |
Quiet mode (suppress progress) |
scp relies on the remote scp binary being present on the target host.rsync over SSH: it supports delta
transfers and is more efficient for repeated syncs.scp may use the SFTP subsystem by default.
If transfers fail, check that Subsystem sftp is enabled in sshd_config.