1. SSH uses a key to connect to prevent others from violently cracking the account and password.
1. Generate public and private keys
ssh-keygen
After inputting, keep pressing Enter.
2. After generating the key, check whether the .ssh file is generated in the home directory.
3. Append the public key file in .ssh to the authorized_keys file
cat id_rsa.pub >> authorized_keys
Switch to the upper-level directory and grant 700 permissions to .ssh
chmod 700 ~/.ssh
Then go in to the .ssh file
cd .ssh
Grant 600 permissions to the authorized_keys file (with 600 permissions, only the current user can read and write it)
4. Go to /etc/ssh/sshhd_comfig and modify the configuration file
vim /etc/ssh/sshd_config
After opening the file, add:
RSAAuthentication yes
PubkeyAuthentication yes
Complete the addition, save and exit
5. Restart ssh
systemctl restart sshd
6. Copy the private key file to the desktop
7. Create a new ssh-docker and connect remotely. Because I didn’t set a password just now, I don’t fill in the password.
8. Open the newly created remote connection and find that the connection can be successful using the key.
2. Change to require password verification to connect.
1. You can modify the password login allowed in /etc/ssh/sshd_config to no
PasswordAuthentication yes 改为 PasswordAuthentication no
After modification, restart ssh
systemctl restart sshd
2. Disconnect and find that the connection failed.