If you manage Linux servers, you move files all the time—configs, logs, backups, random scripts you swear you’ll clean up “later.”
The scp command in Linux is the simplest way to do secure file transfer over SSH without extra tools or UI.
In this guide, we’ll go through scp syntax, real-world examples, SSH key authentication, and useful options so you can move files confidently between your laptop, remote Linux server, and cloud hosting.
Let’s strip away the buzzwords.
scp = Secure Copy (it uses SSH under the hood)
It behaves like cp, but between machines
Traffic is encrypted, so passwords and data aren’t sent in plain text
It works on almost every Linux server out of the box
So whenever you think “I need to get this file to that server quickly and safely,” scp is usually the first tool you reach for.
To follow along, you just need:
One local machine (Linux or macOS with SSH installed)
One remote Linux server (VPS, dedicated server, or cloud instance)
SSH access to the remote server (ssh user@server-ip works)
If you don’t already have a remote server, it’s easier than you think to spin one up just for testing. A small VPS box is more than enough to practice moving files, breaking things, and fixing them again.
Once that server is online, keep its IP address, SSH port (usually 22), and username handy—you’ll use them in every scp example below.
The basic scp command looks like this:
bash
scp [options] source destination
Breakdown:
source – the file or directory you’re copying
destination – where it should land
options – extra flags to tweak behavior
Remote paths use this pattern:
bash
user@server:/path/on/server
Some quick examples:
Local → Remote:
bash
scp file.txt user@server:/home/user/
Remote → Local:
bash
scp user@server:/home/user/file.txt .
Remote → Another remote (from your local machine):
bash
scp user1@server1:/path/file.txt user2@server2:/path/
Once this pattern clicks, scp feels a lot less mysterious.
Instead of copying “important stuff” first, let’s build a small playground.
Make a folder and some test files:
bash
mkdir -p ~/scp-demo/dir
cd ~/scp-demo
touch file1.txt file2.txt file3.txt
You now have:
file1.txt, file2.txt, file3.txt
a directory called dir/
SSH into your remote server:
bash
ssh user@server
Then run:
bash
mkdir -p ~/dir1 ~/dir2
touch ~/file4.txt
Now you’ve got:
file4.txt on the remote server
dir1/ and dir2/ directories ready for testing
Exit back to your local machine when you’re done:
bash
exit
Let’s walk through the bread‑and‑butter scp operations you’ll use all the time.
From your local machine:
bash
cd ~/scp-demo
scp file1.txt user@server:/home/user/
What happens:
file1.txt goes from your local scp-demo folder
to /home/user/ on the remote server
If it’s your first time connecting, SSH will ask you to confirm the fingerprint. Type yes and continue.
To put the file into a subdirectory instead:
bash
scp file1.txt user@server:/home/user/dir2/
Now pull file4.txt back from the remote server:
bash
cd ~/scp-demo
scp user@server:/home/user/file4.txt .
The trailing . means “copy it to the current directory.”
To send the entire dir/ directory to the remote server:
bash
scp -r dir user@server:/home/user/
The -r flag means “recursive.” It copies the directory and everything inside it.
To copy dir1/ from the remote server back to your local machine:
bash
cd ~/scp-demo
scp -r user@server:/home/user/dir1 .
Now you have a local copy of dir1/ in ~/scp-demo/dir1.
Typing your SSH password every time gets old fast, especially in CI/CD or backup scripts. SSH keys solve this problem.
Run:
bash
ssh-keygen -t ed25519 -C "your-email@example.com"
Press Enter to accept the default file location (~/.ssh/id_ed25519) and optionally set a passphrase.
Easiest method (if ssh-copy-id exists on your system):
bash
ssh-copy-id user@server
It will ask for your password one last time and then install your public key.
If you don’t have ssh-copy-id, you can do it manually:
bash
cat ~/.ssh/id_ed25519.pub | ssh user@server 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys'
Try logging in:
bash
ssh user@server
If everything is set up right, you should get in without a password prompt (or just a passphrase prompt if you set one on the key).
From now on, every scp command that uses user@server will also use that SSH key automatically.
Once keys are working, all your old commands still apply—just without passwords.
Copy from local to remote:
bash
scp file2.txt user@server:/home/user/dir2/
Copy a directory from remote to local:
bash
scp -r user@server:/home/user/dir2 .
Same syntax, less friction.
scp has a bunch of options, but only a few really matter day to day. Let’s hit the practical ones.
If you care about original modification times and permissions:
bash
scp -p file3.txt user@server:/home/user/dir2/
-p keeps timestamps and modes intact. Handy for backups and log files.
When the network is slow but CPU is cheap, compression can help:
bash
scp -C file1.txt user@server:/home/user/dir2/
-C tells SSH to compress the stream. The win depends on file type (text compresses well; already-compressed media, not so much).
If you don’t want scp to eat the whole pipe:
bash
scp -l 500 file2.txt user@server:/home/user/dir2/
-l 500 limits the transfer to 500 Kbps. Useful on shared links or production servers where you want to be polite.
If something fails and you have no idea why:
bash
scp -v file1.txt user@server:/home/user/
-v prints detailed SSH messages so you can see what’s going on during connection and authentication.
If you juggle multiple keys (work/personal, different projects):
bash
scp -i ~/.ssh/my_special_key file3.txt user@server:/home/user/dir2/
This forces scp to use that particular private key instead of guessing.
To list your default SSH keys, check:
bash
ls ~/.ssh/
You’ll usually see names like id_rsa, id_ed25519, and their .pub friends.
Notice this is uppercase -P (lowercase -p is already taken).
If your server runs SSH on port 2222 instead of 22:
bash
scp -P 2222 file3.txt user@server:/home/user/dir2/
Always remember: ssh uses -p for port, scp uses -P. Yes, it’s confusing. No, they’re not changing it.
For huge directory trees, it’s often faster and cleaner to:
Archive and compress locally
Copy the archive
Extract it remotely
From your local machine:
bash
cd ~/scp-demo
tar czf dir.tar.gz dir
bash
scp dir.tar.gz user@server:/home/user/dir1/
SSH into the server:
bash
ssh user@server
cd /home/user/dir1
tar xzf dir.tar.gz
Now dir/ appears under /home/user/dir1/, with all its files.
This pattern gives you more control, better compression, and fewer surprises than copying a giant tree one file at a time.
Yes, scp is still encrypted and uses SSH for transport. For advanced use or better error handling, many people also use rsync or sftp, but for quick secure file transfer scp is still perfectly fine.
By default, scp uses SSH port 22.
If your SSHd listens on another port (like 2222), use -P:
bash
scp -P 2222 file.txt user@server:/home/user/
scp is simple: just copy from A to B
rsync is smarter: resuming partial transfers, syncing only changes, more options for backups
For one-off transfers, scp is enough. For recurring sync or large backups, rsync is usually better.
Yes. On Windows 10+ you can install OpenSSH client and use scp from PowerShell or Command Prompt. Tools like PuTTY’s pscp or WSL (Windows Subsystem for Linux) also work.
Definitely. If you manage Linux VPS or dedicated servers in the cloud, the scp command gives you a low‑friction, zero‑extra‑software way to move configs, deploy small apps, and grab logs securely.
You’ve seen how the scp command in Linux works: basic syntax, real copy commands, SSH key authentication, and the handful of options that actually matter in daily server work. With this, you can move files quickly and securely between local machines, remote Linux servers, and any cloud hosting you use.
And if you want an easy way to get reliable remote Linux boxes for backups, deployments, and everyday secure file transfer testing, 👉 see why GTHost is suitable for fast SCP‑based backup and deployment scenarios — having instant, stable servers makes practicing and using scp in real-world scenarios much smoother.