+4 votes
307 views
How to use SCP Linux command Examples

in Linux / Unix by (552k points)
reopened | 307 views

1 Answer

+5 votes
Best answer

How to use SCP Linux command

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 1: source file.
  • 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 
image
Step 2

Note that a security message SHA256 is released, enter the password and the file will be copied: image
Step 3

We can copy a file from server to server by running:
 scp [email protected]: /home/user1/file.extension [email protected]: / home / user2 / 
image
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 
image
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.

by (3.5m points)
edited

Related questions

+4 votes
1 answer
asked Sep 22, 2020 in Linux / Unix by backtothefuture (552k points) | 329 views
+5 votes
1 answer
asked Feb 22, 2020 in Linux / Unix by backtothefuture (552k points) | 349 views
+5 votes
1 answer
asked Oct 4, 2019 in Linux / Unix by backtothefuture (552k points) | 247 views
+3 votes
1 answer
asked Feb 6, 2023 in Linux/Unix by backtothefuture (552k points) | 80 views
+5 votes
1 answer
asked Feb 21, 2020 in Linux / Unix by backtothefuture (552k points) | 298 views
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users