Principle
In the traditional SSH authentication process, the server (passive connection side) verifies the user's identity by verifying the user name and password sent by the client (active connection side). In addition to the authentication method of the user name and password, the server can verify the identity of the client by saving and using the public key of the client, which can be understood as the public key in the PKI system.
Know_hosts: Stores public key information for a known server.
Authorized_keys: Stores public key information for known clients.
Id_rsa.pub: Stores public key information.
Id_rsa: Stores private key information.
which
- The permissions for the. SSH directory must be 700.
- The. ssh/authorized_keys file permission must be 600.
Verification process:
- Before the client logs on, the client places the public key on the server to be logged on.
- The client sends public key information to the server, requesting to specify user authentication.
- The server side looks for the corresponding user home directory under the home directory to look for the public key.
- The server side uses the found public key to encrypt the data and send it to the client.
- The client decrypts it with its own private key, and then sends it to the server side.
- Server-side authentication before and after the message is consistent, in order to confirm the user identity.
Environment
- Centos7_x86_64
- Windows10
- Xshell
- OpenSSH
Steps
1. Generate an asymmetric key pair.
1 #生成SSH使用的公钥和私钥只用户家目录下的. SSH directory 2 Ssh-keygen -t RSA
2. Create a Authorized_keys file.
1 #创建. authorized_keys file 2 Touch Authorized_keys 3 #修改文件权限信息 4 chmod Authorized_keys
3. Append the client's public key information to the server-side Authorized_keys file.
1 #拷贝公钥信息至authorized_keys文件 2 ssh-copy-ID -I. ~/. ssh/id_rsa.pub34SCP -P ~/. ssh/id_rsa.pub [email protected]<remote_ip>:/root/. ssh/authorized_keys56cat ~/. ssh/id_rsa.pub >> ~/. ssh/authorized_keys
Linux-ssh Password-Free login