恶意扫描攻击服务器的人越来越多,运维们为了防止服务器被入侵,真是煞费苦心。不做点儿什么,服务器真就被攻破了!
多数的攻击手段,都是从ssh下手的,攻破ssh,相当于整台服务器都是黑客的了。我之前发过一篇关于宝塔的安全设置,防御手段都用上了。当然除了宝塔的安排配置,感觉还差些什么,所以就有了这篇文章。
本文演示所用系统为CentOS 7.9
服务器端配置文件
打开/etc/ssh/sshd_config文件,这个文件是SSH 守护进程的配置文件
1.确保密码登陆失败次数3-6
设置最大密码尝试登陆失败次数3-6,建议为4
搜索MaxAuthTries
MaxAuthTries 4
![图片[1]-SSH安全加固建议-王先生笔记](https://wxsnote.cn/wp-content/uploads/2022/09/ce993f2cfa151230.png)
2.禁止空密码登陆
设置为no
搜索PermitEmptyPasswords
PermitEmptyPasswords no
![图片[2]-SSH安全加固建议-王先生笔记](https://wxsnote.cn/wp-content/uploads/2022/09/8c37ffc8c8151335.png)
3.设置SSH空闲超时退出时间
将ClientAliveInterval设置为300-900(即客户端存活时间时长5到15分钟),建议设置为600,将ClientAliveCountMax设置为0-3(即客户端存活数0到3个),建议设置为2
搜索ClientAlive
ClientAliveInterval 600
ClientAliveCountMax 2
![图片[3]-SSH安全加固建议-王先生笔记](https://wxsnote.cn/wp-content/uploads/2022/09/75ba655881151338.png)
4.设置SSH日志级别
设置为INFO
搜索LogLevel
LogLevel INFO
![图片[4]-SSH安全加固建议-王先生笔记](https://wxsnote.cn/wp-content/uploads/2022/09/1a95433fda151340.png)
5.SSHD强制使用V2安全协议
如果配置中有这个属性就设置为2,没有就略过
搜索Protocol
Protocol 2
![图片[5]-SSH安全加固建议-王先生笔记](https://wxsnote.cn/wp-content/uploads/2022/09/f5678238cc151342.png)
6.SSH 禁止root远程登录
设置为no
搜索PermitRootLogin
PermitRootLogin no
![图片[6]-SSH安全加固建议-王先生笔记](https://wxsnote.cn/wp-content/uploads/2022/09/be0174fb67151347.png)
完成以上配置后,需重启sshd服务或重启服务器,使设置生效!
service sshd restart
SSH密码相关配置
1.1.SSH密码修改最小间隔
打开/etc/login.defs文件
设置为大于等于7
搜索PASS_MIN_DAYS
PASS_MIN_DAYS 7
![图片[7]-SSH安全加固建议-王先生笔记](https://wxsnote.cn/wp-content/uploads/2022/09/b6bcab6cea190241.png)
1.2.SSH密码失效时间
参数设置为90-180之间,使用非密码登陆方式时,忽略此设置
搜索PASS_MAX_DAYS
PASS_MAX_DAYS 120
![图片[8]-SSH安全加固建议-王先生笔记](https://wxsnote.cn/wp-content/uploads/2022/09/8653edaeaa190243.png)
1.3.SSH过期提前警告天数
设置为大于等于7
搜索PASS_WARN_AGE
PASS_WARN_AGE 7
![图片[9]-SSH安全加固建议-王先生笔记](https://wxsnote.cn/wp-content/uploads/2022/09/bafdb058d9190246.png)
2.1.SSH密码长度度检查
打开/etc/security/pwquality.conf文件
设置为9-32位
搜索minlen
minlen = 9
![图片[10]-SSH安全加固建议-王先生笔记](https://wxsnote.cn/wp-content/uploads/2022/09/849661f4cc151351.png)
2.2.SSH密码复杂度检查
(至少包含小写字母、大写字母、数字、特殊字符等4类字符中等3类或4类)设置为3或4
搜索minclass
minclass = 3
![图片[11]-SSH安全加固建议-王先生笔记](https://wxsnote.cn/wp-content/uploads/2022/09/dbc93ee681151349.png)
对默认配置文件进行简单的修改,即可提高安全度。与下文配合使用,效果更佳
红帽官网安全指南:《RedHat Linux安全指南》
2022-09-22 17:30:43,某些文章具有时效性,若有错误或已失效,请在下方留言或加入QQ群:
399019539 联系群主反馈。注意一些链接无法访问可能是你网络的原因,如Github,并非资源地址失效。
登录后可快速点此处反馈,点击登录













请登录后查看评论内容