What Is the scp Command in Linux?¶
Introduction¶
The scp command copies files between hosts over SSH. It is useful for beginners, Linux administrators, DevOps engineers, and RHCSA students because it solves practical terminal tasks.
What the Command Does¶
Use scp to work with the specific Linux object it manages. Before changing anything, identify the target and run a read-only check when possible.
Basic Syntax¶
scp SOURCE DESTINATION
The syntax includes the command, any options, and the target object.
Common Options¶
-r: copy directories recursively.-P: connect to a custom SSH port.-i: use a private key file.
Practical Examples¶
scp file.txt admin@server:/tmp/
scp admin@server:/var/log/app.log .
scp -r project admin@server:/srv/
scp -P 2222 -i ~/.ssh/id_rsa file.txt admin@server:/tmp/
Verification command:
ssh admin@server ls -l /tmp/file.txt
Example output:
-rw-r--r-- 1 admin admin 1200 May 30 10:00 /tmp/file.txt
When to Use This Command¶
Use scp for simple one-time file transfers over SSH. For repeated syncs or large directory trees, rsync is often a better tool.
Common Mistakes¶
- Using lowercase
-pwhen you meant uppercase-Pfor port. - Forgetting
-rwhen copying a directory. - Putting the colon in the wrong place in a remote path.
Quick Reference¶
scp file.txt admin@server:/tmp/
scp admin@server:/var/log/app.log .
ssh admin@server ls -l /tmp/file.txt
Related Guides¶
Summary¶
The scp command is safest when you understand the target, choose the right option, and verify the result with a separate command.