🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

scp Command

Beginner SSH & Remote man(1)

Securely copy files between hosts over SSH

👁 7 views 📅 Updated: Mar 15, 2026
SYNTAX
scp [OPTION]... SOURCE... DESTINATION

What Does scp Do?

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.

Options & Flags

OptionDescriptionExample
-r Copy directories recursively scp -r ./project user@server:/var/www/
-P Specify SSH port scp -P 2222 file.txt user@server:/tmp/
-i Use specific identity key scp -i ~/.ssh/key.pem file user@server:/path/
-C Enable compression during transfer scp -C largefile.sql user@server:/backup/
-p Preserve timestamps and permissions scp -p config.yml user@server:/etc/app/
-q Quiet mode (no progress bar) scp -q backup.tar.gz user@server:/backup/
-l Limit bandwidth in Kbit/s scp -l 5000 large.iso user@server:/tmp/

Practical Examples

#1 Copy file to remote server

Uploads a file to the remote server.
$ scp report.pdf user@server:/home/user/Documents/

#2 Copy file from remote server

Downloads a file from the remote server to local machine.
$ scp user@server:/var/log/app.log ./app.log

#3 Copy directory recursively

Copies an entire directory tree to the remote server.
$ scp -r ./deploy user@server:/var/www/html/

#4 Copy with custom port

Copies a file using a non-standard SSH port.
$ scp -P 2222 config.yml admin@server:/etc/app/

#5 Copy between two remote hosts

Copies a file directly between two remote servers.
$ scp user@server1:/data/db.sql user@server2:/backup/

#6 Compressed transfer

Enables compression for faster transfer over slow connections.
$ scp -C database.sql.gz user@server:/backup/

Tips & Best Practices

Use rsync instead for large transfers: rsync -avz is superior to scp for large directories — it only transfers changed files and can resume interrupted transfers.
Use SSH config for shortcuts: Define hosts in ~/.ssh/config, then use: scp file.txt myserver:/path/ instead of typing full user@hostname.
SCP protocol deprecated: The SCP protocol has known limitations. OpenSSH 9+ uses SFTP internally for scp. For new scripts, consider using rsync or sftp directly.

Frequently Asked Questions

How do I copy a file to a remote server?
Use scp filename user@server:/remote/path/. For example: scp backup.tar.gz admin@192.168.1.100:/backups/
How do I copy a directory recursively?
Add the -r flag: scp -r ./mydir user@server:/path/. This copies the entire directory tree.
What is the difference between scp and rsync?
scp copies everything every time. rsync only copies changed files, supports resume, and is more efficient. Use rsync for regular transfers and large directories.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →