SSH uses public and private keys to log in without password

 

ssh uses public and private keys to log in to remote hosts

The command used is ssh-keygen. For the specific usage of this command, please refer to the blog:

http://killer-jok.iteye.com/blog/1853451

 

E.g:

localhost A user a.

Target host B user b IP: 192.168.0.11.

1. Generate public and private keys

Enter the following command on the command line of host A:

[a@localhost ~]$ ssh-keygen -t rsa

Then enter three times

The .ssh directory will be generated under /home/a, which contains two files: id_rsa and id_rsa.pub

id_rsa is the private key on the local machine, and id_rsa.pub is the public key on the remote host B.

We will give the public key to the server, and when we need to request content from the server, we must bring the private key. At this time, the server will calculate the private key through a certain algorithm, and judge whether the result of the calculation is the same as the public key, if not, the response request will fail.

2. Copy the public key to the target host B

use the scp command

 

[a@localhost ~]$ scp .ssh/id_rsa.pub [email protected]:/home/b/
Password:
id_rsa.pub             100%  406     0.4KB/s   00:00

 

 3. Add the public key to the authorized_keys authorization file

Use ssh [email protected] to log in to host B and enter the command

[b@B ~]$ cat id_rsa.pub >> .ssh/authorized_keys
[b@B ~]$ chmod 600 .ssh/authorized_keys

600 is the file usage permission (only the owner has read and write permissions). 

4. The above steps are completed, exit to exit B, and use the ssh command to log in again without a password.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326565023&siteId=291194637