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 UserName@TargetHost:/target/path
scp [options] UserName@TargetHost:/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
Example #2: Copy a file from a remote host to your system
Example #3: Copy a file from one remote host to another remote host
Example #4: Enable verbose output
Example #5: Copy two files from your system to a remote host
Example #6: Recursively copy an entire local directory to a remote host
Example #7: Copy a file with compression enabled
Example #8: Use a different cipher when copying a file
Example #9: Copy a file using a different port
Example #10: Limit the amount of bandwidth used when copying a file
Example #11: Use an authentication key to copy a file
Example #12: Disable strict file checking to prevent a file from being rejected
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.