Linux Commands

12 SCP Command Examples and How to Use SCP

This article introduces the SCP (Secure Copy Protocol) command as a secure and efficient way to transfer files across the public internet, providing 12 SCP command examples that you can try yourself on virtually any distribution.

What Is the SCP Command?

SCP stands for Secure Copy Protocol. As the initialism suggests, the SCP command’s purpose is to transfer files between two computers securely.

Unlike many other file transfer methods, SCP ensures the authenticity and confidentiality of the data in transit using the Secure Shell (SSH) protocol.

As a user, you can use the SCP command to transfer files between a local host and a remote host or between two remote hosts. When the SCP command is used to transfer data, a password or key is required for authentication. This password or key is transmitted in an encrypted form so that nobody can capture it.

Many Linux distributions, including Linux Mint, let you use the SCP command (included as part of OpenSSH) right out of the box, and you can always install the openssh-client package manually on any distribution that doesn’t include it.

Why Should I Use the SCP Command?

There are two main reasons to use the SCP command: convenience and security. Let’s tackle them in the same order.

Convenience: There are many ways to copy files between two computers. You can transfer them using a USB flash drive, create an NFS or samba server, or upload them to a cloud storage service like Dropbox. However, all these methods require you to go through way more steps than the SCP command does.

Security: A big no-no is transferring sensitive files over the public internet in an unencrypted form, such as using the FTP protocol. SCP is based on SSH, so it does a reasonably good job of protecting data in transit.

We say that SCP does a reasonably good job because OpenSSH developers consider it to be “outdated, inflexible, and not readily fixed.” They recommend sftp and rsync as more modern alternatives. Despite this, SCP is a handy tool, and learning how to use it isn’t that difficult.

How to use the SCP Command?

The basic syntax of the SCP command looks like this:

scp [options] /local/file/or/folder [email protected]:/target/path

scp [options] [email protected]:/target/path /local/file/or/folder

The first syntax is used to copy a file or folder from a local system to a target host, while the second syntax is used to retrieve a file or folder from a target host and copy it to a local system.

In either case, you can add a variety of options to modify how exactly the file transfer process happens. Check the scp man page for a full list of options.

12 SCP Command Examples

Now that you’re familiar with the basic syntax of the SCP command and the options it supports, we can take a closer look at 12 SCP command examples that illustrate how to use SCP in practice.

Example #1: Copy a file from your system to a remote host

$ scp document.txt morelo@192.168.44.132:/tmp

Example #2: Copy a file from a remote host to your system

$ scp morelo@192.168.44.132:/tmp/document.txt /tmp

Example #3: Copy a file from one remote host to another remote host

scp morelo@192.168.44.132:/tmp/document.txt robert@192.168.44.130:/tmp/

Example #4: Enable verbose output

$ scp -v document.txt morelo@192.168.44.132:/tmp

Example #5: Copy two files from your system to a remote host

$ scp document1.txt document2.txt morelo@192.168.44.132:/tmp

Example #6: Recursively copy an entire local directory to a remote host

$ scp -r ~/Desktop morelo@192.168.44.132~/Desktop

Example #7: Copy a file with compression enabled

$ scp -C document.txt morelo@192.168.44.132:/tmp

Example #8: Use a different cipher when copying a file

$ scp -c aes256-cbc document.txt morelo@192.168.44.132:/tmp

Example #9: Copy a file using a different port

$ scp -P 4600 document.txt morelo@192.168.44.132:/tmp

Example #10: Limit the amount of bandwidth used when copying a file

$ scp -l 1000 document.txt morelo@192.168.44.132:/tmp

Example #11: Use an authentication key to copy a file

$ scp -i key.pem document.txt morelo@192.168.44.132:/tmp

Example #12: Disable strict file checking to prevent a file from being rejected

$ scp -T document.txt morelo@192.168.44.132:/tmp

Conclusion

The SCP command is easy to learn and incredibly useful to know. You can use it to securely and conveniently transfer files and even entire folders between two locations, which everyone needs to do from time to time. The 12 SCP command examples listed in this article provide a comprehensive overview of what SCP can do, but there are more options to play with, so we encourage you to have fun with them.

About the author

David Morelo

David Morelo is a professional content writer in the technology niche, covering everything from consumer products to emerging technologies and their cross-industry application