CentOS7云主机SSH安全设置

今天早上发现服务器被别人ssh非法尝试登录了无数次了,赶紧配置一下:

1. ssh-keygen -t rsa

2. cd /root/.ssh

3. ls

4. 将上述目录下的id_rsa下载到本地

5.(rm -f ./id_rsa,可选)

6.cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys

7. 修改/etc/ssh/sshd_config文件,去掉以下行的注释:

RSAAuthentication yes

PubkeyAuthentication yes

AuthorizedKeysFile .ssh/authorized_keys

另外

PasswordAuthentication yes改为PasswordAuthentication no

8. service sshd restart

下面添加fail2ban增强安全性

9. yum install fail2ban

10. 添加/etc/fail2ban/jail.local文件,内容为:

[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

另外,经过上述配置后,putty无法正常用密码登录了,需要用私钥登录,配置如下:

左侧树上Connection-->SSH-->Auth页面, 将上面下载后的id_rsa文件路径填到页面下方的相关输入框里,重新保存一个配置即可。

猜你喜欢

转载自johnsmith9th.iteye.com/blog/2421778
今日推荐