You know those moments when you just want to move a file to a remote Linux server and your brain goes blank on the exact scp command? This guide is for that moment. We’ll walk through how the Secure Copy Protocol (SCP) works and how to use each SCP command without overthinking it.
By the end, you’ll be able to copy files and directories between local and remote hosts (and even between two remote servers) in a way that’s secure, fast, and predictable. No fancy tools, no GUIs—just SSH, SCP, and a few clear examples you can copy, paste, and tweak.
SCP stands for Secure Copy Protocol.
It’s a simple way to copy files and folders:
From your local machine to a remote server
From a remote server back to your local machine
Between two remote servers
SCP runs on top of SSH (Secure Shell). That means:
Your data is encrypted during transfer
Authentication uses the same SSH keys/passwords you already know
You don’t need to open extra ports—SCP uses the SSH port
If you already use SSH, learning SCP is basically getting “copy & paste over SSH” for free.
When you run an scp command, a few things happen:
You tell SCP what to copy: a file or a directory.
You tell it where to send it: local path, or user@server:/path.
SCP opens an SSH connection to that remote host.
It sends the data over that encrypted channel.
The remote server saves the file in the path you gave.
If something is wrong—wrong hostname, port closed, permissions off—you’ll see an error from SSH or SCP. Fix that, run the same command again, and you’re back in business.
You don’t need SCP for everything. But in server, cloud, and DevOps work, it shines in a few common situations.
Remote server backup
You can pull config files, database dumps, or logs down to your laptop or a backup server:
Local → Remote (push backups)
Remote → Local (pull backups)
Either way, SCP keeps the backup traffic encrypted.
Deployment of applications
Maybe you have:
A compiled binary
A bunch of static assets
Configuration templates
You can use an SCP command to push those files to one server or several servers as part of a simple deployment process.
Transferring large files
Email says “file too big,” chat tools choke, and web upload fails at 99%. SCP just quietly sends the file over SSH. As long as your connection holds and you have disk space, it works.
Secure file sharing
Need to send a confidential file to a teammate?
Put it on a server they have SSH access to
Use SCP to copy it there
They pull it down with their own SCP command. No public links, no file-sharing sites.
Remote collaboration
Teams that live in terminals—sysadmins, DevOps, backend engineers—use SCP all the time to move scripts, logs, and test data around between machines.
If you’re working with cloud or dedicated servers, you’ll use SSH and SCP sooner or later. If you want real hardware without waiting days for provisioning, dedicated boxes are especially nice to practice on. 👉 Spin up an instant GTHost server and try these SCP commands on real dedicated hardware in a few minutes. That way you can test, break, and learn without touching production.
Let’s look at the generic format once, so the later examples make sense:
bash
scp [options] [source] [destination]
Options
Common flags you’ll see with the scp command:
-r – Copy directories recursively (including subfolders and files)
-p – Preserve permissions, timestamps, and modes
-P – Use a specific SSH port (capital P)
-i – Use a specific SSH private key file
-C – Enable compression during transfer
-l – Limit bandwidth in Kbit/s
-v – Verbose mode (debug/info output)
-o – Pass extra options to the SSH client (e.g., host key checking)
Source
This is what you’re copying:
Local file: /home/user/file.txt
Local directory: /home/user/app/
Remote: user@server:/path/to/file.txt
Destination
This is where the copy lands:
Local: /home/user/backups/
Remote: user@server:/var/www/
One side has a plain path; the other side usually looks like user@host:/path.
Let’s go through real SCP examples you can adjust for your own servers. Replace usernames, IP addresses, and paths with your own.
bash
scp /path/to/local/file.txt user@remotehost:/path/to/destination/
Example:
bash
scp /home/vboxuser/Desktop/sample.zip
abhishekvarma@192.168.29.70:/Users/abhishekvarma/Desktop
What happens:
Your local machine reads sample.zip.
SCP connects to 192.168.29.70 as user abhishekvarma.
It asks for the SSH password (or uses your key).
The file shows a progress bar and ends at 100%.
Output looks something like:
text
sample.zip 100% 20KB 717.9KB/s 00:00
Reverse direction:
bash
scp user@remotehost:/path/to/remote/file.txt /path/to/local/destination/
Example:
bash
scp abhishekvarma@192.168.29.70:/Users/abhishekvarma/Desktop/sample.zip
/home/vboxuser/Desktop
You’re now pulling the file down to your local desktop.
Sample output:
text
sample.zip 100% 20KB 51.2KB/s 00:00
Use -r if you want to copy a folder and everything inside it.
bash
scp -r /path/to/local/dir user@remotehost:/path/to/destination/
Example:
bash
scp -r /home/vboxuser/Desktop
abhishekvarma@192.168.29.70:/Users/abhishekvarma/Desktop
This pushes the whole Desktop directory (and subfolders) to the remote Desktop.
Sample output:
text
sample.zip 100% 20KB 1.0MB/s 00:00
Screenshot-from-2023-08-13-21-45-23.png 100% 27KB 1.5MB/s 00:00
.help.swp 100% 12KB 780.4KB/s 00:00
You can use shell wildcards like *.txt or *.png:
bash
scp /path/to/local/*.txt user@remotehost:/path/to/destination/
Example (copy all PNG files):
bash
scp /home/vboxuser/Desktop/locfolder/*.png
abhishekvarma@192.168.29.70:/Users/abhishekvarma/Desktop
This sends all .png files from locfolder to the remote desktop.
Sample output:
text
Screenshot-from-2023-08-13-21-45-23.png 100% 27KB 1.4MB/s 00:00
Screenshot-from-2023-08-13-21-55-28.png 100% 24KB 1.7MB/s 00:00
Screenshot-from-2023-08-13-22-04-03.png 100% 38KB 2.1MB/s 00:00
Use -p to keep timestamps and permissions:
bash
scp -p /path/to/local/file.txt user@remotehost:/path/to/destination/
Example:
bash
scp -p /home/vboxuser/Desktop/sample.zip
abhishekvarma@192.168.29.70:/Users/abhishekvarma/Desktop
The file arrives on the remote server with the same modification time and mode as the original.
Sample output:
text
sample.zip 100% 20KB 420.0KB/s 00:00
If your SSH service runs on a non-default port, use -P (capital P):
bash
scp -P 2222 /path/to/local/file.txt user@remotehost:/path/to/destination/
Example using port 22 (default, but shown for clarity):
bash
scp -P 22 /home/vboxuser/Desktop/sample.zip
abhishekvarma@192.168.29.70:/Users/abhishekvarma/Desktop
Sample output:
text
sample.zip 100% 20KB 1.2MB/s 00:00
Just swap 22 for whatever port your SSH server uses.
Use -C to enable compression. This can help over slower links:
bash
scp -C /path/to/local/file.txt user@remotehost:/path/to/destination/
Example:
bash
scp -C /home/vboxuser/Desktop/sample.zip
abhishekvarma@192.168.29.70:/Users/abhishekvarma/Desktop
If the files are compressible, you may see slightly better speeds.
Sample output:
text
sample.zip 100% 20KB 985.8KB/s 00:00
Use -v when something isn’t working and you want details:
bash
scp -v /path/to/local/file.txt user@remotehost:/path/to/destination/
Example:
bash
scp -v /home/vboxuser/Desktop/sample.zip
abhishekvarma@192.168.29.70:/Users/abhishekvarma/Desktop
Now SCP prints what it’s doing:
Which config it’s reading
How it connects
Key negotiation details
Sample snippet:
text
Executing: program /usr/bin/ssh host 192.168.29.70, user abhishekvarma, command scp -v -t /Users/abhishekvarma/Desktop
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 192.168.29.70 [192.168.29.70] port 22.
debug1: Connection established.
Same idea, but pulling from remote:
bash
scp -v user@remotehost:/path/to/remote/file.txt /path/to/local/destination/
Example:
bash
scp -v abhishekvarma@192.168.29.70:/Users/abhishekvarma/Desktop/sample.zip
/home/vboxuser/Desktop
You’ll see debug messages for the connection plus the download process:
text
Executing: program /usr/bin/ssh host 192.168.29.70, user abhishekvarma, command scp -v -f /Users/abhishekvarma/Desktop/sample.zip
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to 192.168.29.70 [192.168.29.70] port 22.
debug1: Connection established.
If you use different SSH keys for different servers, -i tells SCP which private key to use:
bash
scp -i /path/to/private_key.pem /path/to/local/file.txt user@remotehost:/path/to/destination/
Example:
bash
scp -i /path/to/private_key.pem
/home/vboxuser/Desktop/sample.zip
abhishekvarma@192.168.29.70:/Users/abhishekvarma/Desktop
This is common in cloud hosting or dedicated server environments where each project or environment has its own key.
Sample output:
text
sample.zip 100% 20KB 1.1MB/s 00:00
You can pass several source files before the destination:
bash
scp file1.txt file2.txt user@remotehost:/path/to/destination/
Example:
bash
scp /home/vboxuser/Desktop/image.png
/home/vboxuser/Desktop/sample.zip
abhishekvarma@192.168.29.70:/Users/abhishekvarma/Desktop
Both files are uploaded in one scp run.
Sample output:
text
image.png 100% 39KB 1.4MB/s 00:00
sample.zip 100% 20KB 1.5MB/s 00:00
You can rename during copy:
bash
scp user@remotehost:/path/to/remote/file.txt /path/to/local/newfilename.txt
Example:
bash
scp abhishekvarma@192.168.29.70:/Users/abhishekvarma/Desktop/sample.zip
/home/vboxuser/Desktop/newfile.zip
The data is the same; only the filename changes on the local side. Keep the extension consistent if you want tools to recognize the file properly.
Sample output:
text
sample.zip 100% 20KB 28.7KB/s 00:00
Use -l when you don’t want SCP to eat the entire network pipe:
bash
scp -l 1000 /path/to/local/file.txt user@remotehost:/path/to/destination/
Here 1000 means 1000 Kbit/s (around 125 KB/s).
Example:
bash
scp -l 300 /home/vboxuser/Desktop/sample.zip
abhishekvarma@192.168.29.70:/Users/abhishekvarma/Desktop
This keeps the SCP transfer from saturating the link.
Sample output:
text
sample.zip 100% 20KB 31.3KB/s 00:00
Combine -r and -p:
bash
scp -rp /path/to/local/source/ user@remotehost:/path/to/destination/
Example:
bash
scp -rp /home/vboxuser/Desktop/image.png
abhishekvarma@192.168.29.70:/Users/abhishekvarma/Desktop
This keeps permissions, timestamps, and symbolic links intact while copying.
Sample output:
text
image.png 100% 39KB 1.8MB/s 00:00
You can stack -v and -C:
bash
scp -vC /path/to/local/file.txt user@remotehost:/path/to/destination/
Example:
bash
scp -vC /home/vboxuser/Desktop/image.png
abhishekvarma@192.168.29.70:/Users/abhishekvarma/Desktop
You get:
Debug logs from -v
Compressed transfer from -C
Sample tail of output:
text
Sending file modes: C0664 40050 image.png
image.png
Transferred: sent 40220, received 2576 bytes, in 0.1 seconds
Bytes per second: sent 352570.0, received 22581.3
debug1: Exit status 0
You can tell your local machine to order one remote server to send a file straight to another remote server:
bash
scp user1@remotehost1:/path/to/remote/file.txt
user2@remotehost2:/path/to/destination/
Example:
bash
scp user1@remotehost1:/path/to/remote/file.txt
abhishekvarma@192.168.29.70:/Users/abhishekvarma/Desktop
The data travels from remotehost1 to 192.168.29.70. Your local machine coordinates, but the actual transfer is remote-to-remote.
Sample success:
text
file.txt 100% 512KB 512.0KB/s 00:00
Sample failure:
text
ssh: connect to host source.example.com port 22: Connection refused
lost connection
That usually means: wrong host, port closed, or SSH not running/allowed.
How is SCP different from FTP or SFTP?
FTP (File Transfer Protocol) is older and usually unencrypted unless you add extra layers.
SFTP (SSH File Transfer Protocol) also uses SSH but works more like a full file management protocol (list, move, delete, resume, etc.).
SCP is simpler: copy from A to B over SSH with encryption and authentication built in.
For quick, secure server-to-server or local-to-server copies, SCP is often the easiest command.
When should I use SCP?
Use SCP when you need:
Secure, encrypted file transfers
Simple one-shot copies (backups, deployments, config sync)
Server-to-server transfers over SSH
It fits well in cloud hosting, dedicated server setups, and small automation scripts where you just need to move files reliably.
Is SCP compatible with IPv6?
Yes. SCP works with both IPv4 and IPv6 addresses.
You can use hostnames that resolve to IPv6 or directly use IPv6 literals (wrapped in brackets in some shells or SSH configs).
SCP is one of those basic server tools that quietly does a lot of work: backups, quick deployments, log grabs, and file sharing between remote hosts. Once you know these 16 SCP commands, moving data around your infrastructure becomes faster, safer, and less stressful.
If you want to practice these SCP examples on real bare-metal machines or build a setup where file transfers are consistently fast and stable, it helps to run on solid dedicated servers. That’s exactly why GTHost is suitable for high-speed, secure file transfers between remote servers—you get instant dedicated hardware that plays very nicely with SSH and SCP. 👉 See why GTHost is suitable for high-speed, secure file transfers between remote servers and spin up a box in minutes.