SCP commandIt is a common tool used in Linux to copy files across servers. Its usage is very simple:
SCP-options [[user @] host1:] file1 [[user @] host2:] file2
In options, we usually use very little. We mainly use-V to view the detailed information in the Command Execution Process, which is very useful when the replication fails;
Another common option is-R, which is used for deep replication, including all directories and files under sub-directories;
The above syntax can be used flexibly. It can copy each other between host1 and host2, not only from host1 to host2;
Although this command is easy to use, it uses the SSH protocol to encrypt the transmitted content, and you need to manually enter the password when accessing another server; next we will introduce a method to avoid entering the password every time, that is, what we often sayChannel Connection during service period;
1. Use commandsSsh-keygen-T RSAGenerate a key pair in servera.-t rsa indicates that the RSA algorithm is used to generate the key pair. You can also use the DSA algorithm to generate the key pair. For supported algorithm sets, see OpenSSH documentation; the detailed command parameters of SSH-keygen are not described here. For more information, see man or help;
The generated key pair is stored in ~ by default ~ /. Ssh/directory, id_rsa.pub stores the public key, and id_rsa stores the private key;
Note: When generating a key pairThe system will prompt you to enter the password of the key pair. Press enter here.Do not enter the password. Otherwise, the password is still required after the channel is connected, but only the password set here;
2. Copy the public key in id_rsa.pub and append it to serverb.~ /. Ssh/authorized_keysFile;
In this way, the password will not be entered every time from servera to serverb, and SSH, SCP, SFTP, and other commands Based on the SSH protocol will benefit;
PS: during the intermediate process, you may need to set the permissions for each file under the. Ssh directory, depending on the actual situation;