SCP (secure copy) is one of those Linux tools that feels a bit scary until you’ve actually typed it a few times. Then it becomes muscle memory.
If you just want a simple, reliable way to move files over SSH without setting up anything fancy, these Linux SCP examples will walk you through it step by step.
By the end, you’ll know how to upload, download, rename, and copy whole directories using secure copy, without bloated GUIs or complicated setups.
SCP sits on top of SSH.
If you can ssh into a server, you can usually scp files to and from it over an encrypted connection.
It uses the same port as SSH (usually 22)
It uses the same users, passwords, and keys as SSH
It’s great when you just want “move this file there, right now”
For more advanced stuff (listing directories, resuming transfers, etc.), SFTP or rsync can be better.
But for quick, one‑off file transfers, SCP is fast, simple, and already installed on most Linux boxes.
Before the examples, here’s the core pattern:
bash
scp [options] source destination
That’s it. One source, one destination.
Source can be local or remote
Destination can be local or remote
The “remote” part looks like: user@host:/path
Once you see that shape, every SCP example becomes easier to read.
You’re logged in locally as john, and the remote server also has a john user.
You want to upload testdoc.txt into john’s home directory on the server.
bash
scp testdoc.txt 192.168.100.101:
What’s going on here:
testdoc.txt – local file you’re uploading
192.168.100.101: – remote host plus a colon, with no path
When you leave the path empty like that, SCP uses the remote user’s home directory.
You can also use a hostname instead of an IP:
bash
scp testdoc.txt filetransfers.mydomain.com:
Don’t forget the colon at the end. No colon, no SCP.
Now imagine you’re logged in locally as john, but the remote user is admin.
You need to say that explicitly:
bash
scp testdoc.txt [email protected]:
Details:
testdoc.txt – local file
[email protected]: – remote user, host, and home directory
SCP will prompt you for admin’s password (or use your SSH key if it’s set up).
You don’t always want to drop things straight into the remote home directory.
Let’s say you want to place testdoc.txt into /remotedir1/remotesubdir1 on the server:
bash
scp testdoc.txt [email protected]:/remotedir1/remotesubdir1
If the directory exists and you have permissions, the file lands there
If you forget the path or mistype it, SCP will complain and you’ll know quickly
You’ve got a bunch of .txt files in your current local directory, and you want them all on the remote server under /remotedir1:
bash
scp *.txt [email protected]:/remotedir1
What this does:
*.txt – the shell expands this to all .txt files locally
SCP sends them all in one go to the remote directory
This is handy for quick batch uploads without typing every filename.
If you’re reading this and thinking, “I don’t even have a second Linux machine to test with,” that’s normal. A lot of people want to practice SCP before they touch production servers.
One easy approach is to spin up a temporary remote box just for experiments and throw it away when you’re done.
👉 Spin up a GTHost Linux server in minutes and practice these SCP commands on real hardware
Because it’s a dedicated server with instant setup and full SSH access, you can break things, fix them, and build confidence with secure copy in a safe environment. Then, when it’s time to touch real production infrastructure, your commands already feel familiar.
Let’s switch direction.
You want to download testdoc.txt from the remote user’s home directory into your current local directory.
bash
scp [email protected]:testdoc.txt .
Pieces:
[email protected]:testdoc.txt – remote source
. – current local directory as destination
Remember: in SCP, the first path is always the source, the second is always the destination.
You don’t have to accept the remote filename as‑is.
Here, you download testdoc.txt and save it locally as testdoclocal.txt:
bash
scp [email protected]:testdoc.txt testdoclocal.txt
Now your local file name can match your own naming scheme, without a second mv command.
You know exactly which files you want from the remote home directory: testdoc.txt and triggerconditions2.txt.
You can grab them both in one command using brace expansion:
bash
scp [email protected]:~/{testdoc.txt,triggerconditions2.txt} .
What’s happening:
~/ – remote user’s home directory
\{testdoc.txt,triggerconditions2.txt\} – shell brace expansion for specific filenames
. – current local directory
The backslashes (\{ and \}) are there so your shell doesn’t try to expand the braces before SCP sees them.
Some SSH servers require that ~ to clearly say “this is the home directory,” so it’s a good habit.
Sometimes wildcards are dangerous.
Maybe your directory is messy, and *.txt would upload way too much. In that case, just list the files:
bash
scp testdoc.txt triggerconditions2.txt [email protected]:/remotedir1
Two local files on the left
One remote destination directory on the right
If you typo a filename, SCP will tell you it can’t find it. Nothing mysterious.
Now you want to move a whole project folder.
You’ve got a local directory ./testdir and you want it (and everything in it) under /remotedir1 on the server.
bash
scp -r ./testdir [email protected]:/remotedir1
The key option here:
-r – recursive; copy the directory and all its contents
After this command, the remote server will have /remotedir1/testdir with all the files and subdirectories from your local testdir.
Now do the reverse.
The server has /remotedir1, and you want it locally as ./testdir:
bash
scp -r [email protected]:/remotedir1 ./testdir
Again, -r means “go through everything inside that directory.”
So:
If ./testdir doesn’t exist, SCP will create it and fill it
If it already exists, the contents of /remotedir1 will be placed inside it (or overwritten, depending on names)
This is a quick way to pull down configs, logs, or small project folders for offline work.
You can get a lot done with just the examples above, but a few small habits make secure copy more pleasant in daily work:
Use SSH keys instead of passwords for faster, safer logins
Once SSH keys are set up, SCP uses them automatically.
Use -P (capital P) if your SSH server listens on a non‑default port
Example: scp -P 2222 file.txt [email protected]:
Combine with ssh for checks
Run ssh [email protected] "ls /remotedir1" right before a big scp so you know where your files will land.
Be explicit with paths
: with no path = home directory, but writing the full path is safer when you’re tired or in a hurry.
Is SCP still safe to use for secure copy?
Yes, SCP runs over SSH, so the connection is encrypted. For most simple file transfers between trusted hosts, it’s perfectly fine. For more control (like resuming transfers or restricting what users can do), combine SCP/SSH with proper user management or consider SFTP and other file transfer tools.
What’s the difference between SCP and SFTP?
SCP is more “fire and forget”: copy this file from here to there, and that’s it.
SFTP is an interactive file transfer protocol: you can list directories, delete files, create folders, and so on. For one‑off file moves, SCP is usually faster to type. For heavy daily file management, SFTP often feels nicer.
Can I use SCP with cloud or hosting providers?
Yes. As long as the provider gives you SSH access to a Linux server, SCP will work. That’s why it’s popular in DevOps and cloud hosting workflows: you can push configs, logs, and code to remote machines with one command.
How do I practice these Linux SCP examples without risking production?
The safest way is to use a throwaway test server. Set up a small Linux machine specifically for testing secure copy and SSH. Once you’re comfortable, move the same commands over to your real environment.
You don’t need a huge toolkit to move files securely between Linux machines. With these 10 Linux SCP examples, you’ve basically learned the everyday “secure copy” moves you’ll use to upload, download, rename, and mirror directories over SSH.
If you want an easy environment for real‑world practice and deployment, it’s worth looking at 👉 why GTHost is suitable for running and testing SCP‑heavy Linux workloads: instant dedicated servers, full SSH access, and predictable performance make secure copy feel like just another quick command instead of a risky operation. With that in place, your file transfers stay simple, stable, and under your control.