Log into ssh using key

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.

Insert image description here

2. After generating the key, check whether the .ssh file is generated in the home directory.

Insert image description here

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)

Insert image description here

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

Insert image description here

5. Restart ssh

systemctl restart sshd

6. Copy the private key file to the desktop
Insert image description here

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.

Insert image description here

8. Open the newly created remote connection and find that the connection can be successful using the key.

Insert image description here

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 

Insert image description here

2. Disconnect and find that the connection failed.
Insert image description here

Guess you like

Origin blog.csdn.net/X2965901955/article/details/131335620