Establish trust relationships between Linux machines

  
 

There are two machines a and b. Now we need to add the user1 user of the machine to the user2 user trust list of the b machine, so that the user1 user of the machine can directly ssh to the user2 user of the b machine. Steps: 1. Enter a machine /home/user1/.ssh directory (if it is the root user, in /root/.ssh), if not, execute mkdir -p /home/user1/.ssh, check if there is an id_rsa.pub file in the directory. If not, execute the ssh-keygen -t rsa command, the file will be generated in the directory. Copy the contents of the file; 2. Enter the b machine /home/user2/.ssh directory, if not created, in the directory Execute vi authorized_keys, paste the contents copied in step 1 here in the last line, and then save and exit;

3, vi b /etc/hosts.allow of the machine, add a line: sshd: [here is a machine Ip, if it is two-way, remember to add two ip] and then execute in the user1 directory of a machine: ssh user2@b, successfully connected to the b machine. The ssh trust relationship refers to a user on a server trusting a user of the client, allowing the user to log in without entering a password. Another term is called public_key_auth. In fact, it is certificate trust. First, you need to create a certificate for the trusted user. Run the following command: ssh-keygen -t rsa will generate two files, id_rsa and id_rsa.pub, in the ~/.ssh directory, which are the private and public keys. Note that the id_rsa file must have a permissions of 600. Then, to the server user's ~/.ssh directory, create a file authorized_keys (if you already have it, edit it directly), and add the contents of id_rsa.pub (only one line of text) to the file and save it. Ok, so if you run ssh username@remotehost on the client, you can log in without entering the password. After setting up the trust relationship, you can download the remote file in the shell script or execute the command on the server without entering the password: ssh username@remotehost << EOF remote command... EOF sftp username@remotehost << EOF Get remotefile EOF

Copyright © Windows knowledge All Rights Reserved