As a Linux user or Systems administrator, transferring files in a secure manner between different Linux systems is crucial. This safeguards vital information which could be intercepted and stolen by hackers. In this guide, you will learn how to transfer files securely using the Linux SCP command.
What is the Linux SCP command?
SCP, short for Secure Copy, is a protocol that is used to securely copy files and directories to remote servers/client systems. It comes built-in with SSH that offers encryption and privacy to information that is exchanged between systems. It’s much better in terms of security than the telnet command.
Let’s now look at some of the example usages of SCP command.
Basic Syntax of scp command
The most basic syntax of SCP usage is as shown below:
scp source_file_name username@destination_IP_address:destination_folder
Above command is used to transfer local files to a remote server. We can also transfer remote files to the local server using the below syntax.
scp username@remote_host:remote_file_folder local_folder
There are other additional options that you can use to give you the desired output. But first, let’s have a look at SCP usage without any options.
SCP command usage without any additional options
To begin with, let’s start with the basic usage of the SCP command. In my current directory, I have a file called
linux_for_beginners.pdf. I’m going to send this file to a remote host
22.214.171.124. To achieve this, the command will be
scp linux_for_beginners.pdf firstname.lastname@example.org:
If this is your first time connecting to the host, you will get the output as shown in the output below. You will be prompted for the remote host’s password and upon typing it, the file will be copied on the root folder of the remote host
SCP command with -p option
When used with
-p option, SCP provides connection speed, and estimated time used to complete the transfer the file.
scp -p Exercise1.txt email@example.com
Display detailed information about SCP process
To print a more detailed output when running SCP, use the
-v flag. This prints out verbose output.
scp -v Course1.pdf firstname.lastname@example.org:
Limit bandwidth using -l option
Another useful option is the
-l parameter that allows you to limit bandwidth usage.
scp -l 400 report1.txt email@example.com:
The value 400 is in Kilobits Per second. So basically, you are limiting the file transfer of the file to 400Kbps or 50 Kilobytes per seconds give that 8 bits are equal to 1 byte.
Copy directories recursively
If you want to copy files inside directories, use the
-r flag to copy the directories recursively as shown
scp -r documents firstname.lastname@example.org:
Copy files from a remote server to a local server
In some cases, you may need to copy files from a remote Linux system to your current local Linux system.
This is possible using the syntax.
scp username@remote-host:/remote/path /localpath
For example, to copy a file
file1.pdflocated on the home directory of root user on a remote server
IP 126.96.36.199 to a local system on
/tmp/files path, the command will be:
scp email@example.com:file1.pdf /tmp/files
Supress any diagnostic messages/warnings/progress meter
You can choose not to display any diagnostic messages, warnings or progress meter when running SCP. To achieve this, use the
-q option as shown.
scp -q file1.pdf firstname.lastname@example.org:
We have come to the end of this article. We hope that you’ll now be confident in sending files security between Linux systems. Feel free to get back to us with your experience.