Although the FTP protocol still exists for copying files over a network, there are those who prefer to use SCP for this purpose. So today, you will learn all about the SCP command on Linux.
What is the SCP command?
In Unix family operating systems, the SCP command is used to copy files between computers that are preferably on the same network. One of the main features of this command is that the transmission of the data is done in encrypted form.
In short, the SCP command is a combination of RCP and SSH. The RCP (Remote Copy) tool, which copies files insecurely, i.e., unencrypted, over the network. And SSH is for encrypted access to remote systems. So with these technologies, you can copy files securely.
The SCP command allows both copying a file to a server and downloading it from it. Therefore, the flexibility it offers is great. A small limitation is that it is unidirectional, i.e., for each connection you can only copy in one direction.
scp command is a software that runs on the local system and on the server. It acts both as a daemon and as a client of the SCP protocol. As SCP is quite popular throughout Unix, the
scp client command is available on all Linux distributions, so you don’t have to do anything to make it available.
Using the scp command on Linux
The simplest way to use the
scp command is with the following syntax
scp [options] [source username@IP]:/[file_path] [destination username@IP]:/[directory]
It may seem complex to use, but you will see that it is simple.
If you want to display the help via terminal, you can run the following command:
And then see other options and ways to use it.
Remember that since
scp works using SSH, it requires a password and username that will be provided to you by the sysadmin of the server or computer.
Example of how to use the scp command
One of the most important uses is to copy a local file to a remote one. Let’s say the file on your computer is called
file.txt and is in the path
/home/user/ and you want to copy it to the path
/home/user2/Documents on the server.
To do the example I mentioned above, you have to execute this command
scp /home/user/file.txt [email protected]:/home/user2/Documents/
As you can see, it is simple to use and with good transfer rates.
To do the reverse process, i.e., to copy from the remote server to the local computer.
So to achieve this, you will have to run
scp [email protected]:/home/user2/Documents/file.txt /home/user/
Of course, you can replace
/home/user/ with the path where you want the file to be.
Another very frequent use of the command is to copy from a remote computer to a remote computer. The situation is similar.
scp [email protected]:/home/user2/Documents/file.txt [email protected]:/home/user/
Remember that for this to work, you must have read and write permissions on the folders.
Another way to use the tool
scp command options, you can extend the functionality of the
scp command. For example, using the
-r option, you will be able to copy an entire folder.
scp -r /home/angelo/backup [email protected]:/home/user2/Documents/backup
This will copy the entire folder. This process also works in reverse.
Occasionally, you need to copy large files and in order not to affect the network too much, then you can use the
-C option to compress.
scp -C file.iso [email protected]:/home/user2/
SCP is a very useful command to copy files between computers and all in a very secure way thanks to its SSH implementation.
I hope you liked this post, and you can use it in your tasks. Also share this post and help us to grow.