Use public and private keys to realize linux server password-free login

Take the login from machine A to machine B as an example, assuming that machine A logged in by the root user is used at this time

 Step 1: Enter the /root/.ssh directory (in fact, it is okay not to enter this directory, remember to put the private key under this folder after generating the secret key), execute the command ssh-keygen -t rsa

At this time, you will be asked to enter the name of the generated file (including the name of the path). Note that the private key must be placed under the path of /username/.ssh/ at the end, and the name can be set by yourself.

Carriage return

Step 2: Enter the password of the public and private key, because it is to log in without password, so do not enter the password here, just press Enter. There is no accident that the public and private keys will be generated at this time.

Step 3: Put the public key just generated under /root/.shh/ of machine B, you can use the following command to complete

              scp ./is_rsa.pub [email protected]:/root/.ssh/is_rsa.pub (It is assumed that the IP address of machine B is 101.101.101.101)

Step 4: If the user you are logging in, this is under the .ssh folder under root's home directory. If there is no authorized_keys, rename the passed public key to this name, otherwise just change the name in xxx.pub The content is appended to the end of authorized_keys inside.

Additional command: cat xxxx.pub >> authorized_keys

Step 5: At this time, you can log in without password. Use the command ssh [email protected] to log in to the B server.

Step 6: If the parameter is too long, you can set [email protected] as an environment variable.

             export ssh_101 = "[email protected]"

             Then directly ssh ssh_101 on it.

 

Guess you like

Origin blog.csdn.net/xiaoan08133192/article/details/108884736