Linux two-way authentication implementation

Principle
Use "public and private key" authentication for ssh login.

Step
1. The client generates "public and private keys", the public key file "~/.ssh/id_rsa.pub", and the private key file "~/.ssh/id_rsa"
2. Upload the public key file "~/.ssh/id_rsa. pub" to the target server, and keep the private key file "~/.ssh/id_rsa/id_rsa"
3. Append the uploaded public key file "~/.ssh/id_rsa.pub" to the server "~/.ssh/authorized_keys" file 4.
Verify validity

1. The client generates "public and private keys", the public key file "~/.ssh/id_rsa.pub", and the private key file "~/.ssh/id_rsa"

1
2
3
4
5
> ssh -keygen
Generating public /private rsa key pair.
Enter file in which to save the key ( /Users/wangjun/ . ssh /id_rsa ):
/Users/wangjun/ . ssh /id_rsa already exists.
Overwrite (y /n )?

2. Upload the public key file "~/.ssh/id_rsa.pub" to the target server and keep the private key file "~/.ssh/id_rsa/id_rsa"

1
> scp ~/. ssh /id_rsa .pub [email protected]: /root/

3. Append the uploaded public key file "~/.ssh/id_rsa.pub" to the server ~/.ssh/authorized_keys file

1
> cat id_rsa.pub >> ~/. ssh /authorized_keys

4. Verify the validity, you do not need to enter a password for ssh login again

In the above, the operation from client to server is the same as the operation from server to client. In this way, two servers can log in to each other without authentication and authorization to achieve two-way authentication.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326530227&siteId=291194637