Establish a trust relationship between the two servers to solve issues such as SCP and SSH without entering a password.

Source: Internet
Author: User
Tags scp command

Reference address: http://blog.chinaunix.net/u2/76835/showart.php? Id = 1359453

Note: add the blue text for me

Recently, I encountered a problem when writing a regular Python script. In this script, you need to use the SCP command to copy the local file to another machine for backup. However, you usually need to enter the user password after executing the SCP command, so that it is not applicable in the step of regular and Automatic Execution of Python.
Later, I searched for related information on the Internet. For more information, [1] after the two users of the two machines establish a secure trust relationship, you do not need to enter the user password when executing the SCP command. (This method is also applicable to SSH)

For the convenience of discussion, we call the machine that executes the SCP command as the client, and the remote machine operated by the SCP command as the server.
Follow these steps to establish a security trust relationship between the root of the client and the root of the server:
1. Run the ssh-keygen command on the client to generate a certificate that establishes a security trust relationship.
[Root @ client 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): <-- press ENTER
Enter passphrase (empty for no passphrase): <-- press ENTER
Enter same passphrase again: <-- press ENTER
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:
49: 9C: 8A: 8f: BC: 19: 5E: 8c: C0: 10: D3: 15: 60: A3: 32: 1C root @ Client
[Root @ client root] #
Note: When the program prompts you to enter passphrase, enter the carriage return, indicating no certificate password.
The above command generates the Private Key Certificate id_rsa and Public Key Certificate id_rsa.pub, which are stored in the. Ssh subdirectory of the user's home directory.
2. Copy the Public Key Certificate id_rsa.pub to the. Ssh subdirectory of the root directory of the server, and change the file name to authorized_keys.
[Root @ client root] # SCP-P. Ssh/id_rsa.pub root@192.168.3.206:/root/. Ssh/authorized_keys
Root@192.168.3.206's password: <-- enter the root user password for the machine Server
Id_rsa.pub 100% | *************************** | 218
[Root @ client root] #
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 the machine server.
After the above two steps, the security trust relationship is established between the root of the client and the root of the server. Let's take a look at the effect:
[Root @ client root] # SCP-P text root@192.168.3.206:/root
Text 100% | ************************** | 19
[Root @ client root] #
It 'OK! Note: SSH commandsSSH [host] SSH [username @ host]

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.