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
|
|
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
1
|
|
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.