Linux Command: scp
Securely copy files between hosts over SSH
scp (secure copy) transfers files between local and remote hosts over SSH. It uses the same authentication and encryption as SSH, making it a secure alternative to FTP for file transfers. scp supports copying files in both directions: from local to remote, from remote to local, and between two remote hosts. It can copy directories recursively and preserves file permissions. While rsync is generally preferred for large transfers (it only copies changes), scp remains widely used for quick, simple file transfers because of its straightforward syntax and ubiquity on all SSH-capable systems.
Syntax
scp [OPTION]... SOURCE... DESTINATIONKey Options
-rโ Copy directories recursively-Pโ Specify SSH port-iโ Use specific identity key-Cโ Enable compression during transfer-pโ Preserve timestamps and permissions-qโ Quiet mode (no progress bar)
Examples
Copy file to remote server
scp report.pdf user@server:/home/user/Documents/Copy file from remote server
scp user@server:/var/log/app.log ./app.logCopy directory recursively
scp -r ./deploy user@server:/var/www/html/Pro Tips
- rsync -avz is superior to scp for large directories โ it only transfers changed files and can resume interrupted transfers.
- Define hosts in ~/.ssh/config, then use: scp file.txt myserver:/path/ instead of typing full user@hostname.
- The SCP protocol has known limitations. OpenSSH 9+ uses SFTP internally for scp. For new scripts, consider using rsync or sftp directly.
Learn more: Full scp reference โ
Related Resources