Networking

Linux scp command

Copy files between hosts over SSH. Check both source and destination paths.

Availability: Common Linux commands; shell built-ins and external implementations may differ by distribution.中文

Syntax

scp [OPTION]... SOURCE... TARGET

Examples

Copy a local file to a remote directory.

scp report.txt alice@example.com:/tmp/

Copy a directory tree using a custom SSH port.

scp -P 2222 -r ./site alice@example.com:/srv/backup/

Parameters, options and clauses

Option / clauseDescription
-rCopy directories recursively.
-P PORTConnect to the SSH server on PORT (uppercase P).
-i IDENTITY_FILESelect the private key file.
-pPreserve modification times, access times and modes.
-CEnable compression during transfer.
-qSuppress progress and diagnostic messages.
Safety note

Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.

Official reference ↗Back to directory