SCP command details

Source: Internet
Author: User
Tags scp file scp command

The SCP command is similar to the CP command, except that the CP command is used on the same machine, and the SCP command is copied on two machines.

Example:
Copy remote server files to local

SCP-P 999 root@21andy.com:/home/test.zip/home/

Copy the local directory to the remote server

SCP-P 999-r/home/Andy/root@21andy.com:/home/

SCP command syntax
SCP [-1245 bcpqrv] [-C cipher] [f ssh_config] [-I identity_file] [-l limit] [-O ssh_option] [-P port] [-s program] [[user @] host1:] file1 […] [[Suer @] host2:] file2

SCP command description
SCP Copies files between hosts. It uses SSH (1) for data transmission. And use the same authentication and security. SCP requests for password input during authentication. All files may need a special description from the server and the user to indicate that the file will be copied to/from a server. File Replication between two remote login servers is allowed.

SCP Command Option
-1 force SCP Protocol 1
-2 force SCP Protocol 2
-4 force SCP to use IPv4 URLs
-6 force SCP to use IPv6 URLs
-B. Select the batch processing mode (to prevent password input)
-C allows compression. Mark-C to SSH (1) to allow Compression
-C Cipher
Select cipher to encrypt data transmission. This option is passed directly to SSH (1)
-F ssh_config
Set a variable user configuration to ssh. This option will be passed directly to SSH (1)
-I identity_file
Select the file to which the private password is read by RSA Authentication. This option can be passed directly to SSH (1)
-L limit
Limits the transmission bandwidth, that is, the kbit/s speed.
-O ssh_option
You can upload the configuration format in ssh_config to ssh. This mode is helpful for SCP that does not have an independent SCP file interrupt character. The options are as follows. For their values, see ssh_config (5)
-P Port
Specify the remote connection port. Note that this option must be written in uppercase. Because-P has reserved the number and mode.
-S program
Specifies an encryption program. This program must read all SSH (1) options.
-P specifies the number of modifications, connections, and the mode of the original file.
-Q: Turn off the progress parameter.
-R Recursively copies the entire folder
-S program
Specifies an encryption program. This program must read all SSH (1) options.
-V redundancy mode. Let SCP and SSH (1) print their troubleshooting information, which is useful in troubleshooting connections, authentication, and configuration.

SCP command Diagnosis
If SCP returns 0, the return value is greater than 0 if it fails.

SCP command does not need to enter the User Password

Between two users of two machinesEstablish a secure Trust RelationshipYou do not need to enter the user password when executing the SCP command.

1. Run the command on machine A as the root user.Ssh-keygenCommand to generate a certificate that establishes a security trust relationship.

[Root @ A root] # ssh-keygen-B 1024-T RSA
Generating public/private RSA key pair.
Enter file in which to save the key (/root/. Ssh/id_rsa): <-enter the Enter key directly.
Enter passphrase (empty for no passphrase): <-press ENTER
Enter same passphrase again: <-press enter directly.
Your identification has been saved in/root/. Ssh/id_rsa.
Your public key has been saved in/root/. Ssh/id_rsa.pub.
The key fingerprint is :......

Note: When the program prompts you to enter passphrase, enter the carriage return, indicating no certificate password.
The above command will generate the Private Key CertificateId_rsaAnd Public Key CertificateId_rsa.pub, Stored in the user directory. SSHSubdirectory.

2. Change the Public Key CertificateId_rsa.pubCopy to The. Ssh subdirectory of the root directory of machine B and replace the file nameAuthorized_keys.

[Root @ A root] # SCP-P. Ssh/id_rsa.pub root @ IP address of machine B:/root/. Ssh/authorized_keys
Root@192.168.3.206's password: <-enter the root user password for machine B

When executing the preceding command, the root user of the two machines has not yet established a security trust relationship, so you also need to enter the root user password of machine B.
After the above two steps, we will establish a security trust relationship between the root of machine A and the root of machine B. Let's take a look at the effect:

[Root @ A root] # SCP-P test root @ IP address of machine B:/root

Successful! You do not need to enter the password any more.

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.