If you’ve ever needed to move a config file from your laptop to a remote server at 2 AM, you already know why learning how to use SCP command in Linux matters. SCP (Secure Copy Protocol) has been the go-to tool for quick, encrypted file transfers between systems for decades. It’s fast, it’s simple, and it rides on top of SSH, which means your data stays protected in transit. I still reach for it almost reflexively, even though the landscape has shifted. Let me walk you through everything you need to know.
scp source_file user@remote_host:/path/to/destination. It encrypts everything in transit and requires no extra setup beyond SSH access.
What Is SCP Command (And Why Every Linux Admin Still Uses It)
SCP stands for Secure Copy Protocol. At its core, it copies files between a local machine and a remote server (or between two remote servers) using the OpenSSH official documentation protocol for encryption. Every byte transferred gets wrapped in SSH encryption, so there’s no plaintext data floating across the wire.
I remember the first time I used SCP. I was still doing Windows sysadmin work and had just set up my first Ubuntu server in my homelab. I needed to copy a backup script over, and a coworker casually said, “just SCP it.” One command later, the file was there. No FTP server setup, no USB drive, no email attachment. That moment changed how I thought about Linux administration forever.
Despite being officially deprecated by OpenSSH (more on that later), SCP remains everywhere. It’s installed by default on virtually every Linux distribution, it requires zero configuration beyond SSH access, and the syntax is dead simple. For quick, one-off file transfers, nothing beats it.
SCP Command Syntax and Basic Structure
The basic SCP syntax follows a predictable pattern:
Get a VPS from as low as $11/year! WOW!
scp [OPTIONS] source destination
Either the source or the destination (or both) can be a remote host. You specify remote locations using this format:
user@hostname:/path/to/file
That’s it. The user is the remote account, hostname is the IP address or domain, and the path points to the file or directory. If you skip the path, SCP drops files into the remote user’s home directory.
One thing that tripped me up early on: the colon (:) after the hostname is critical. Leave it out and SCP thinks you’re doing a local copy. I’ve seen this confuse beginners more times than I can count.
Essential SCP Command Examples
Let me walk through the transfers you’ll actually use day to day. These are the commands I run constantly across my homelab and production servers.
Copy Local File to Remote Server
The most common SCP operation. Push a file from your machine to a remote server:
scp /home/alexa/backup.tar.gz [email protected]:/opt/backups/
This copies backup.tar.gz to the /opt/backups/ directory on the remote host. You can archive files first with the tar command to bundle directories before transfer.
Copy Remote File to Local Machine
Pull a file from a remote server to your local system. Just flip the source and destination:
scp [email protected]:/var/log/syslog ./server-logs/
I use this constantly for grabbing log files from remote machines. It’s faster than SSH-ing in and reading them there, especially when I want to search through them locally.
Copy Files Between Two Remote Servers
SCP can transfer directly between two remote hosts without downloading to your local machine first:
scp user1@server1:/data/export.csv user2@server2:/imports/
This is handy during server migrations. The traffic flows through your local machine as an intermediary, but you don’t need to store anything locally.
Copy Directories Recursively
Add the -r flag to copy entire directories:
scp -r /home/alexa/project/ admin@server:/opt/deploy/
This grabs the directory and everything inside it. Fair warning: for large directories with thousands of small files, this can be slow. That’s where tools like the rsync command start to shine.
Copy Multiple Files at Once
You can specify multiple source files in a single command:
scp file1.txt file2.txt config.yml admin@server:/opt/configs/
Or use wildcards:
scp *.conf admin@server:/etc/nginx/conf.d/
Important SCP Command Options You Need to Know
SCP has a handful of flags that make a real difference in daily use. Here are the ones I actually use:
-r— Recursively copy entire directories-P 2222— Connect on a custom SSH port (capital P, not lowercase)-p— Preserve file modification times, access times, and permissions-C— Enable compression during transfer (great for text files over slow connections)-v— Verbose mode, essential for debugging failed transfers-l 5000— Limit bandwidth to 5000 Kbit/s (prevents saturating your connection)-i ~/.ssh/mykey— Use a specific SSH identity file
-P (uppercase) for SCP, but -p (lowercase) for SSH. I’ve mixed these up more times than I’d like to admit. If your transfer hangs, double-check the case.
If you’re transferring large files and want to check your network speed beforehand, that can help you estimate transfer time and decide whether compression is worth enabling.
Real-World Use Cases for SCP
Beyond basic file copying, here’s how SCP fits into real sysadmin workflows.
Creating Remote Backups
I run a nightly script on my Proxmox homelab that archives critical configs and SCPs them to a secondary machine. The command looks something like this:
tar czf /tmp/configs-$(date +%F).tar.gz /etc/nginx /etc/docker
scp /tmp/configs-$(date +%F).tar.gz backup@nas:/backups/
It’s not as sophisticated as a proper backup tool, but for config files, it’s reliable and fast. For more robust setups, check out our guide on automated backup strategies.
Deploying Configuration Files
When I need to push an updated Nginx config to a web server, SCP handles it in one line:
scp nginx.conf admin@webserver:/etc/nginx/nginx.conf
Then a quick ssh admin@webserver "nginx -t && systemctl reload nginx" to test and apply. Simple deployment pipeline without any extra tooling.
Managing Log Files Across Servers
Pulling logs from multiple servers for local analysis is one of SCP’s sweet spots. Grab what you need, grep through it locally, and move on. If you’re dealing with network issues while pulling logs, our network troubleshooting guide can help.
Common SCP Errors and How to Fix Them
Things break. Here’s how to fix the errors you’ll run into most often.
Permission Denied Errors
This usually means the remote user doesn’t have write access to the target directory. Check Linux file permissions on the remote side:
ssh admin@server "ls -la /opt/backups/"
If permissions are wrong, fix them with the chmod command or verify that the remote user account has proper user management settings.
Connection Refused
This means either SSH isn’t running on the remote host, you’re hitting the wrong port, or a firewall is blocking you. First, check if SSH port is open on the remote machine:
scp -v file.txt admin@server:/tmp/
The -v flag gives you detailed connection info. Look for where the handshake fails.
Command Not Found
If your system says scp: command not found, you need to install the OpenSSH client package:
# Debian/Ubuntu
sudo apt install openssh-client
# RHEL/Fedora
sudo dnf install openssh-clients
SSH Key Authentication Issues
If key-based auth isn’t working, verify your key permissions and make sure the public key is in the remote server’s ~/.ssh/authorized_keys. Need to set up keys? Here’s how to generate SSH keys properly.
SCP Security Best Practices
SCP encrypts data in transit, but the tool itself has known vulnerabilities. Here’s how to use it responsibly:
- Use SSH key authentication instead of passwords. Keys are stronger and eliminate brute-force risk. Set up a secure SSH configuration on all your servers.
- Change the default SSH port from 22 to something non-standard. This cuts down on automated scanning attacks.
- Verify remote host fingerprints the first time you connect. Never blindly accept unknown fingerprints.
- Limit directory permissions on the remote side. Don’t give SCP access to write anywhere it doesn’t need to.
- Consider migrating to SFTP for production workflows, especially after reading the deprecation details below.
Why SCP Is Deprecated (And What to Use Instead)
Here’s the part most SCP tutorials skip. The OpenSSH project officially deprecated SCP’s transfer protocol back in 2019. The reason? As the OpenSSH mailing list discussion on SCP deprecation put it:
“The scp protocol is outdated, inflexible and not readily fixed.”
The specific security concern is CVE-2020-15778, which revealed that SCP clients don’t properly verify that received files match what was requested. A compromised server could potentially write arbitrary files to your system.
As noted in Red Hat’s SCP deprecation announcement, RHEL 9 already switched the scp command to use SFTP protocol under the hood by default. So even when you type scp, you might actually be using SFTP.
If you need the old SCP behavior for compatibility reasons, you can use the -O flag to force the legacy protocol. But for new workflows, SFTP is the way forward.
SCP vs SFTP vs Rsync: Which Should You Use?
This is the question I get asked most. Here’s a straightforward comparison:
| Feature | SCP | SFTP | Rsync |
|---|---|---|---|
| Speed (small files) | Fast | Fast | Moderate |
| Resume transfers | No | Yes | Yes |
| Incremental sync | No | No | Yes |
| Security | SSH (deprecated) | SSH (current) | SSH |
| Best for | Quick one-off copies | Interactive transfers | Large syncs, backups |
My recommendation: use SFTP for day-to-day secure file transfers, the rsync command for backups and large directory synchronization, and SCP only when you need a fast, scriptable one-liner and don’t need resume capability. For downloading files from web servers, wget is still your best bet.
Frequently Asked Questions
Is SCP still safe to use?
For quick transfers on trusted networks, yes. The encryption is still solid SSH. The deprecation concerns are about protocol-level vulnerabilities, not encryption weakness. For production environments, migrate to SFTP.
Can SCP resume interrupted transfers?
No. If a transfer fails midway, you have to restart from the beginning. This is one of SCP’s biggest limitations and a key reason to prefer SFTP or rsync for large files.
What’s the difference between -P and -p in SCP?
Capital -P sets the SSH port number. Lowercase -p preserves file timestamps and permissions. They do completely different things.
Wrapping Up
SCP has been a trusty tool in my Linux toolkit for over a decade. It’s the command I reach for when I need to move a file quickly and securely, no setup required. While it’s officially deprecated, understanding how to use SCP command in Linux is still essential knowledge for any admin or developer working with remote systems.
That said, the future is SFTP and rsync. If you’re building new automation or workflows, start there. And if you haven’t locked down your SSH setup yet, now is the perfect time to set up a secure SSH configuration and generate SSH keys for all your servers.
Want to keep leveling up your Linux skills? Check out our guide on mastering rsync for when you need something more powerful than SCP, or learn how to set up automated backups that run while you sleep.




