The scp (Secure Copy) command allows Linux users to securely copy files and directories across multiple systems using an SSH (Secure Shell) connection. When transferring files and directories using this command, they are encrypted, as well as any passwords associated with them. As such, the scp command is one of the most secure ways to transfer data between systems.
Note: For this guide, we’re using three separate systems for this article:
- techobservatory-local-server — Zorin OS 16 (mtr-Zorin) — the user on this server is mtravisrose.
- techobservatory-remote-server-1 — Debian 11 (mtr-debian) — the user on this server is techobservatory.
- techobservatory-remote-server-2 — Xubuntu LTS 22.04 (mtr-xubuntu) — the user on this server is mtravisrose.
Although we’re using three different Linux distros, all Linux commands featured in this article are distro-independent, meaning they will work on any Linux distro.
Copying Files and Directories Using the scp Command
There are three scenarios where Linux users typically use the scp command:
- To copy from your system to a remote server.
- To copy from a remote server to your system.
- To copy from a remote server to another remote server.
scp Command Purpose, Syntax, and Options
With the scp command, you can securely copy a file or directory via SSH. The syntax for the scp command is:
# scp [options] /dir/file(s) ... [destination server]/dir/file(s)
The scp command comes with several powerful options. Some of the most commonly used options include:
- -P — Specify server SSH port (note the upper case P).
- -q — Quiet mode, don’t display progress or messages.
- -p — Preserve permissions, modes, and access time of files.
- -q — Quiet mode. Don’t display progress or messages.
- -C — Compress the data during transmission (note the upper case C).
- -r — Recursive. Include all subdirectories and their contents.
- -l — Limit the bandwidth while copying.
- -v — Verbose output.
- -3 — If copying between two remote hosts, the data is transferred through the local host. This option disables the progress meter and selects batch mode for the second host.
In our three examples, we’ll be using the -C option. The -C option is always recommended to speed up the transfer.
Note: to successfully use scp to copy files, it’s important to have an SSH server installed, enabled, and port 22 (SSH) open on the target system.
Using scp to Copy to a Remote Server
- Log in to the local server (In this instance, mtr-Zorin).
- Launch the terminal.
- Securely copy Download/tar.zip from the local server to mtr-xubuntu in the /home/mtravisrose/Downloads directory. Enter the password for the remote server when prompted. Enter the following command to accomplish this:
# scp -C Downloads/sample.tar mtravisrose@mtr-xubuntu:Downloads

Note that sample.tar is on mtr-xubuntu in the /home/mtravisrose/Downloads directory.

Using scp to Copy from a Remote Server to the Local Server
- Login to the local server (in this case, mtr-Zorin).
- Launch the terminal.
- Securely copy Download/tar.zip from mtr-xubuntu to the /home/mtravisrose/Downloads directory on the local server. Enter your password for your user on the remote server when prompted. Enter the following command to accomplish this:
# scp -C mtravisrose@mtr-xubuntu:/home/mtravisrose/Downloads/sample.tar /home/mtravisrose/Downloads

Using scp to Copy from a Remote Server to a Remote Server
- Login to the source server (in this case, mtr-debian).
- Launch the terminal.
- Securely copy /home/mtravisrose/Downloads/tar.zip from mtr-xubuntu to the /home/techobservatory/Downloads directory on mtr-debian. Enter your passwords for your user on both remote servers when prompted. Enter the following command to accomplish this:
# scp -3 mtravisrose@mtr-xubuntu:/home/mtravisrose/Downloads/sample.tar techobservatory@mtr-debian:/home/techobservatory/Downloads

Note that sample.tar is on mtr-debian in the /home/techobservatory/Downloads directory.

Commands Used in this Guide
- hostname – display the hostname of the system.
- ls – list directory structures.
- pwd – print working directory.
- scp – secure file/directory copy.