The scp command (Secure Copy Protocol) is one of the most common tools used on Linux and Unix-like systems to securely transfer files between computers over SSH. If you’re managing servers, working with VPS instances, or simply copying files between machines, understanding SCP syntax is essential.
In this article, you’ll learn:
- What
scpis and how it works - The correct scp syntax
- Common examples and real-world use cases
- Frequent mistakes and how to fix them
This guide is written to be beginner-friendly while still covering advanced usage, making it ideal both for learning and SEO purposes.
What Is SCP?
scp stands for Secure Copy. It uses the SSH protocol to copy files and directories securely between:
- A local computer and a remote server
- Two remote servers
Because it relies on SSH, all data transfers are encrypted by default, including authentication.
Basic SCP Syntax
The general syntax of the scp command looks like this:
scp [options] source destination
Where:
- source – the file or directory you want to copy
- destination – where the file or directory should be copied
Remote paths always follow this format:
user@host:/path/to/file
Copy a File from Local to Remote Server
scp file.txt user@remote-server:/home/user/
This command uploads file.txt from your local machine to the remote server’s home directory.
Key points:
- The transfer is encrypted
- You’ll be prompted for the SSH password (unless you use SSH keys)
Copy a File from Remote Server to Local Machine
scp user@remote-server:/home/user/file.txt .
This downloads file.txt from the remote server into the current local directory.
Copy Directories with SCP (Recursive Copy)
To copy entire directories, you must use the -r option:
scp -r project/ user@remote-server:/var/www/
Without -r, scp will fail when copying folders.
Copy Files Between Two Remote Servers
scp can also transfer files directly between two remote hosts:
scp user1@server1:/path/file.txt user2@server2:/path/
Your local machine acts only as a controller—the data is transferred securely between the two servers.
Common SCP Options You Should Know
| Option | Description |
|---|---|
-r | Copy directories recursively |
-P | Specify a custom SSH port |
-C | Enable compression |
-v | Verbose mode (debugging) |
-i | Use a specific SSH private key |
Example with Custom SSH Port
scp -P 2222 file.txt user@remote-server:/home/user/
Using SCP with SSH Keys
If you use key-based authentication:
scp -i ~/.ssh/id_rsa file.txt user@remote-server:/home/user/
This is common in automated scripts and server environments.
Preserving File Permissions and Timestamps
To keep original permissions and timestamps:
scp -p file.txt user@remote-server:/home/user/
Typical SCP Errors and Fixes
❌ Permission denied
- Wrong username
- Incorrect SSH key
- Missing permissions on destination directory
❌ No such file or directory
- Path does not exist
- Typo in remote directory path
❌ Connection refused
- SSH not running
- Wrong port (use
-P)
SCP vs SFTP vs rsync
| Tool | Best Use Case |
|---|---|
scp | Quick, simple file transfers |
sftp | Interactive file management |
rsync | Large or incremental backups |
For large or repeated transfers, rsync is usually more efficient, but scp syntax remains the fastest to learn and use.
SEO Keywords Covered
This article naturally includes:
- scp syntax
- scp command
- scp copy file
- scp copy directory
- scp ssh file transfer
Perfect for ranking on Linux, VPS, and server administration topics.
Conclusion
The scp command is a powerful and secure way to transfer files over SSH. By mastering scp syntax, you gain a reliable tool for everyday server management tasks—from quick uploads to full directory transfers.
If you work with Linux servers or VPS hosting, scp is a must-have in your toolbox.
