Need to move files between your laptop and a Linux server without setting up fancy tools? The scp command is already on most systems and works over plain SSH, so you can start transferring in minutes.
Whether you’re managing cloud hosting, a dedicated server, or a lab box at home, scp gives you a quick, encrypted way to copy files.
By the end of this guide, you’ll know how to send and fetch single files, whole directories, and multiple logs with a few short commands—on Windows, macOS, and Linux.
scp rides on top of SSH. If SSH works, scp will work.
You need an SSH server (daemon) running on the Linux machine.
You need a username and a way to log in (password or SSH key).
You should already be able to run something like:
bash
ssh [email protected]
If that command lets you in, you’re ready to use the scp command to copy files to and from that Linux server.
Maybe you don’t even have a Linux server yet and you just want a real machine to test this on. In that case, spinning up a temporary server is often easier than fighting with local VMs.
👉 Launch a GTHost Linux server and start using the scp command for real-world transfers in just a few minutes
Once it’s online, you can treat it exactly like any other SSH host in the examples below.
There are alternatives like sftp and rsync, and they’re great when you need syncing or more advanced options. But for quick, occasional file copies in a DevOps or cloud hosting workflow, scp is usually the fastest thing to reach for.
scp stands for “Secure CoPy”.
It uses SSH for login.
It encrypts all traffic between your computer and the Linux server.
It works on Linux, macOS, and Windows (via tools like OpenSSH, Git Bash, or WSL).
So you get secure login plus encrypted file transfer, out of the box, with a single command.
At its core, the command looks like this:
bash
scp [options] [source] [destination]
Or, in plain English:
bash
scp [options] [from] [to]
You can skip options most of the time. The important parts are the source and destination.
Each side can be:
A local path, like ./file.txt or /home/alex/file.txt
A remote path, like [email protected]:/home/alex/file.txt
You’ll see this pattern a lot:
bash
username@IP_OR_HOSTNAME:/path/on/remote/server/
Once you get used to the pattern, scp commands start to look very predictable.
Let’s start with sending a file to the server.
bash
scp localfile.txt [email protected]:/home/alex/
This does three things:
Takes localfile.txt from your current directory.
Connects as user alex to server 10.11.12.14.
Drops the file into /home/alex/ on that Linux server.
bash
scp /path/to/local/file [email protected]:/home/alex/
scp C:\path\to\local\file [email protected]:/home/alex/
A more concrete example:
bash
scp /home/alex/unikernels/lighttpd.img [email protected]:/home/alex/
scp /Users/alex/unikernels/lighttpd.img [email protected]:/home/alex/
scp C:\Users\Alex\unikernels\lighttpd.img [email protected]:/home/alex/
On Windows, you can usually run this in Command Prompt:
Press the Windows key.
Type cmd.
Press Enter.
Run the scp command there.
If scp isn’t recognized, install the OpenSSH client (available in modern Windows) or use a terminal that ships with it (like Git Bash).
Now let’s pull a file back from the Linux machine.
bash
scp [email protected]:/home/alex/oldstuff/script.sh .
What happens:
You connect as alex to 10.11.12.14.
You read /home/alex/oldstuff/script.sh on the server.
You copy it into your current local directory (the . at the end).
bash
scp [email protected]:/home/alex/oldstuff/script.sh /Users/alex/Downloads/
scp [email protected]:/home/alex/oldstuff/script.sh /home/alex/Downloads/
scp [email protected]:/home/alex/oldstuff/script.sh C:\Users\Alex\Downloads\
Again, on Windows you can run this from Command Prompt or PowerShell once the scp client is installed.
Sometimes you don’t want to repeat the command ten times. Let scp grab multiple files in one go.
bash
scp file1 file2 file3 [email protected]:/home/alex/
This sends file1, file2, and file3 from your current directory to /home/alex/ on the remote Linux server.
bash
scp *.log [email protected]:/home/alex/
Here *.log means:
“Anything, as long as it ends in .log.”
So all .log files from your current directory go up to the server.
You can swap .log with any extension you care about: .txt, .csv, .tar.gz, etc.
To grab multiple specific files from the server:
bash
scp -O "[email protected]:/home/alex/{file1,file2,file3}" .
What’s going on here:
/home/alex/{file1,file2,file3} is shell “brace expansion” on the remote side.
The -O option tells scp to use the traditional scp protocol instead of the sftp protocol, so this brace trick works.
The double quotes " around the remote path stop your local shell from trying to interpret {} itself.
Without the quotes, your local shell might try to be clever and break the command before it even reaches the server.
To download all .log files from a directory on the server:
bash
scp "[email protected]:/home/alex/*.log" .
All *.log files from /home/alex/ will land in your current local directory.
When one file at a time is not enough, add the recursive flag.
bash
scp -r [email protected]:/home/alex/oldstuff/ .
Details:
-r stands for “recursive”.
You copy the entire oldstuff directory and everything inside it.
A new oldstuff directory appears in your current local directory.
bash
scp -r unikernels [email protected]:/home/alex/
This sends the whole unikernels directory from your current directory to /home/alex/ on the Linux server.
If the directory lives elsewhere, use the full path:
bash
scp -r C:\Users\Alex\unikernels\ [email protected]:/home/alex/
scp -r /Users/alex/unikernels/ [email protected]:/home/alex/
scp -r /home/alex/unikernels/ [email protected]:/home/alex/
For migrating applications, moving backups, or pushing code to a remote Linux host in a cloud hosting environment, this -r flag is usually the star of the show.
You don’t have to memorize all options, but a few make real-life work much easier.
bash
scp -C lighttpd.img [email protected]:/home/alex/
-C turns on compression. It can speed up transfers of large, compressible files over slow connections.
If your SSH server listens on a non‑standard port, say 1234, you can tell scp:
bash
scp -C -P 1234 lighttpd.img [email protected]:/home/alex/
-P 1234 says “connect to port 1234 instead of 22”.
Combine it with other options like -C as needed.
Always put options before source and destination.
bash
scp -p report.csv [email protected]:/home/alex/
This keeps:
Modification times
Access times
File mode bits (permissions)
Handy when you care about original timestamps, like when copying logs or audit files.
We’ve already used this, but it’s worth repeating:
bash
scp -r /path/to/dir [email protected]:/home/alex/
Use it whenever you want the entire directory tree, not just one file.
Q: Is scp still safe to use?
A: For basic file copying, yes. It runs over SSH, so the connection and authentication are encrypted. For more complex automation or modern workflows, many people prefer sftp or rsync, but the scp command is still fine for quick, secure transfers.
Q: What port does scp use?
A: By default, scp uses port 22, just like SSH. If your Linux server uses a different port (for example when hardened in a hosting environment), you can connect with -P, like scp -P 2222 file [email protected]:/home/alex/.
Q: When should I use rsync instead of scp?
A: Use rsync when you need to sync directories, resume broken transfers, or copy large trees repeatedly. Use scp when you just want to send or grab a few files quickly and move on.
Q: Can I use scp with cloud hosting or bare‑metal servers?
A: Yes. As long as you have SSH access, scp works the same whether the Linux box is under your desk or in a data center. That’s why many people use it to move code, backups, and configs in and out of their VPS or dedicated servers.
The scp command gives you a simple, encrypted way to move files between your machine and any Linux server—single files, batches of logs, or full directories, all with short commands that work across Windows, macOS, and Linux. Once you remember the basic pattern of source and destination, most file transfer tasks in everyday server management become routine.
And if you want a clean, on‑demand place to practice or run these Linux file transfers in a real hosting environment, 👉 why GTHost is suitable for quick Linux file‑transfer and testing scenarios is simple: instant bare‑metal servers, fast global connectivity, and SSH access ready for your next scp command.