SCP Command Quick Use explanation

Source: Internet
Author: User
Tags scp command secure copy

Using the SCP command under Linux

The SCP is the abbreviation for secure copy Protocol, as well as the copy (CP) commands known to many Linux/unix users. SCP is used in a manner similar to the CP command, where a CP command copies a file or folder from one location (source) of the local operating system to the target location (the destination), and the SCP is used to copy the file or folder from one host on the network to another.

The use of the SCP command is as follows, in this example, I copy a file called "Importantfile" from the native (10.10.16.147) to the remote host (10.0.0.6). In this command, you can also use the host name to replace the IP address.

[[Email protected] ~]# SCP importantfile [email protected]:/home/admin/the authenticity of host  ' 10.0.0.6 (10.0.0.6) ' Can ' t be established . RSA key fingerprint is Sha256:lqbzkega6k9bfwwkgcklqoe0u+gjorx0lplx5yftx1y.rsa key fingerprint is MD5:ED:44:42:59:3E:DD : 4c:12:43:4a:89:b1:5d:bd:9e:20.are you sure do want to continue connecting (yes/no)? Yeswarning:permanently added ' 10.0.0 .6 (RSA) to the list of known hosts.[ Email protected] ' s password:importantfile 100% 0 0.0kb/s 00:00[[email protected] ~]< Span class= "hljs-comment" >#             

Similarly, if you want to get files from a remote host, you can use the following SCP command.

[[email protected] ~]# SCP [email protected] :/root/importantfile/home/admin/the authenticity of host  10.10.16.137 (10.10.16.137) ' Can ' t be established. RSA key fingerprint is b0:b0:a3:c3:2e:94:13:0c:29:2e:ba:0b:d3:d6:12:8f. Is you sure want to continue connecting (yes/no)? Yeswarning:permanently added ' 10.10.16 .137 (RSA) to the list of known hosts.[ Email protected] ' s password:importantfile 100% 0 0.0kb/s 00:00[[email protected] ~]< Span class= "hljs-comment" >#             

You can also use different options in the SCP command like the CP command, and the SCP man helps explain in detail the usage and usefulness of the different options.

Sample output

The SCP optional parameters are as follows:

-B      take batch mode (avoid asking for password or password)-C      enable compression. Turn on the compression mode by specifying the-C parameter. -C Encryption Method Select the encryption method that is         used for encryption during transmission This option is passed directly to SSH (1). -F SSH configuration to SSH specifies a configuration file to override the default configuration. This option is passed directly to SSH (kbit/s. -P Port Specifies the port of the remote host to which the connection is required. Note that this option uses an uppercase "p" because the lowercase "-p" has been used to preserve the time and pattern information of the target file. (lctt: The SSH command uses the lowercase "-p" to specify the destination port.) )-P retains the original modification time, access time, and permission mode of the file. -Q Silent mode: does not displayprogress information, warnings, and diagnostic information from the SSH (1) command. -R recursively copies the entire directory. Note that the SCP command also follows the symbolic connection when the tree traverses, copying the attached file. -v Verbose mode. SCP and SSH (1) will print out the debugging information in the process. This can help you debug connectivity, authentication, and configuration issues. 
Verbose mode

With the-v option of the SCP command, you can get details about authentication, debugging, and more.

When we use the-v option, a simple output looks like this:

[[Email protected] ~]# scp-v Abc.txt [email protected]:/home/adminexecuting:program/usr/bin/ssh host10.0.0.6, user admin, command scp-v-t/home/adminopenssh_7.1P1, OpenSSL1.0.2d-fips9 Jul2015debug1:reading configuration data/etc/ssh/ssh_configdebug1:/etc/ssh/ssh_config line56:applying OptionsFor *debug1:connecting to10.0.0.6 [10.0.0.6] Port22.debug1:connection Established.debug1:Server host Key:ssh-rsa sha256:lqbzkega6k9bfwwkgcklqoe0u+ Gjorx0lplx5yftx1ydebug1:next Authentication method:publickeydebug1:Trying Private key:/root/.ssh/id_rsadebug1:trying private key:/root/.ssh/id_dsadebug1:trying private key: /root/.ssh/id_ Ecdsadebug1:trying private key: /root/.ssh/id_ed25519debug1:next authentication method: Password[email protected]10.0.0 .6 s password:debug1:Authentication succeeded (password). Authenticated to 10.0.0.6 ([10.0.0.6]:22). Debug1:channel 0:new [client-session]debug1:requesting [email  protected]debug1:entering Interactive session.debug1:Sending environment.debug1:Sending command:scp-v-t/home/admin Sending file modes:c0644 174 abc.txtSink:C0644 174 abc.txtabc.txt 100% 174 0.2kb/s 00:00transferred:sent 3024, received 2584 bytes, in 0.3 secondsbytes per Second:sent 9863.3, received 8428.1debug1:exit status 0[[email protected] ~]#< /span>      

When we need to copy a directory or a folder, we can use the-r option, which will recursively copy the entire directory.

Silent mode

If you want to turn off progress information along with warning and diagnostic information, you can use the-Q option in the SCP command.

The last time we just used the-r parameter, it shows the file-by-document information, but this time when we use the-q parameter, it doesn't show progress information.

Use the-p option of SCP to preserve the update time, access time, and permission mode of the target file.

Specify the connection port of the remote host with the-P option

SCP uses the SSH command to transfer files between two hosts because SSH uses the 22 port number by default, so the SCP uses the same 22 port number.

If we want to change this port number, we can use the-p (uppercase p, because the lowercase p is used to keep the file's access time, etc.) option to specify the desired port number.

For example, if we want to use the 2222 port number, we can use the following command

[[Email protected] ~] # scp-p 2222 abcd1 [email protected]:/root/
Limits the bandwidth used by the command, the specified unit is kbit/s

As shown below, we can use the-l parameter to specify the bandwidth used by the SCP command, where we limit the speed to 512kbit/s.

Turn on compression

As shown below, we can save bandwidth and time during transmission by opening the compression mode of the SCP command.

Choose how encrypted data is encrypted

SCP uses AES-128 encryption by default, and if we want to change this encryption method, we can specify other encryption methods by using the-C (lowercase c) parameter.

Now you can use the SCP (secure copy) command to securely copy files between the two nodes in your network.

SCP Command Quick Use explanation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.