This morning, I found that the server has been illegally tried to log in by others ssh countless times, and quickly configure it:
1. ssh-keygen -t rsa
2. cd /root/.ssh
3. ls
4. Download the id_rsa in the above directory to the local
5. (rm -f ./id_rsa, optional)
6.cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
7. Modify the /etc/ssh/sshd_config file to uncomment the following lines:
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
in addition
PasswordAuthentication yes改为PasswordAuthentication no
8. service sshd restart
Add fail2ban below to enhance security
9. yum install fail2ban
10. Add the /etc/fail2ban/jail.local file with the following contents:
[DEFAULT]
#ban a IP for 2 hours
bantime=7200
#overwrite /etc/fail2ban/jail.d/00-firewalld.conf
banaction=iptables-multiport
[sshd]
enabled=true
11. service fail2ban start
In addition, after the above configuration, putty cannot log in with the password normally. It needs to log in with the private key. The configuration is as follows:
On the Connection-->SSH-->Auth page on the left tree, fill in the id_rsa file path downloaded above into the relevant input box at the bottom of the page, and re-save a configuration.