There are hundreds of commands in Linux that have been developed to allow us to be more productive or simply have better control over the different tasks to be performed within the system, one of these commands is the “scp†command which gives us the ability to copy files to, from or between different hosts in Linux environments. The scp (secure copy) command makes use of ssh for data transfer tasks and has the authentication and security of ssh..
Where to use SCP command
By using this command we will be able to transfer files in environments such as:
- From the local system to a remote system.
- Directly from a remote system to the local system.
- Between two remote systems to the local system.
SCP Syntaxis
The general syntax of use is as follows:
scp [OPTION] [user @] SRC_HOST:] file1 [user @] HOST_DESTINATION:] file2
SCP parameters
The parameters are:
- OPTION: allows scp to indicate parameters such as encryption, ssh configuration, ssh port, limit, recursive copy and more
- User 2: destination file.
- -P: indicates the ssh port of the remote host.
- -p: allows you to keep the modification of files and access times to it.
- -q: with this option we can suppress the progress meter and the error-free messages generated.
- -C: scp is forced to compress the data during shipment to the destination computer.
- -r: allows scp to recursively copy directories of the data.
The scp command, being based on ssh, will request an ssh key or password to authenticate on the remote systems to use and it is necessary to have read permissions on the source file and write permission on the destination system.
Now we will see how to use this command to copy secure files on Linux.
How to use SCP Linux command
Step 1
If we want to copy a file easily, for example, to the Home directory we will use the following:
scp file.extension [email protected]: / home / user
Step 2
Note that a security message SHA256 is released, enter the password and the file will be copied:
Step 3
We can copy a file from server to server by running:
scp [email protected]: /home/user1/file.extension [email protected]: / home / user2 /
Step 4
If we want to copy a complete directory with scp we can execute the following syntax:
scp -r / home / user / user [email protected]: / home / user
Step 5
Finally, we can limit the bandwidth to be used with the “l†parameter like this:
scp -l limit [email protected]: /home/user/file.extension Documents
With the scp command we have a simple but reliable alternative to copy files in various ways to Linux safely and completely.