There were failed login attempts since the last successful login.

本文介绍了如何在Linux服务器上新建用户,设置密码,修改SSH配置以禁止root直接登录,并通过修改`/etc/hosts.allow`文件拉黑尝试暴力破解的IP。此外,还演示了如何禁用密码登录,增强服务器的安全性。


查看试图暴力破解你的主机ssh的坏蛋们:

>>> grep "Failed password for invalid user" /var/log/secure | awk '{print $13}' | sort | uniq -c | sort -nr
	
	611 51.210.247.118
     75 107.182.110.105
     30 91.134.242.66
     30 64.225.36.142
     30 61.218.5.190
     30 34.72.163.246
     30 218.149.128.186
     30 167.99.209.119
     30 1.220.90.53
	...

把这些 ip 拉黑

>>> cat /var/log/secure |  grep "Failed password for invalid user" | awk '{print $13}' | sort | uniq -c | sort -n | tail -10 |awk '{print "sshd:"$2":deny"}' >> /etc/hosts.allow 

>>> tail -20 /etc/hosts.allow 
#		allow or deny connections to network services that
#		either use the tcp_wrappers library or that have been
#		started through a tcp_wrappers-enabled xinetd.
#
#		See 'man 5 hosts_options' and 'man 5 hosts_access'
#		for information on rule syntax.
#		See 'man tcpd' for information on tcp_wrappers
#

sshd:218.149.128.186:deny
sshd:222.122.82.135:deny
sshd:34.72.163.246:deny
sshd:51.255.163.60:deny
sshd:61.218.5.190:deny
sshd:64.225.36.142:deny
sshd:80.227.134.221:deny
sshd:91.134.242.66:deny
sshd:107.182.110.105:deny
sshd:51.210.247.118:deny

新建一个用户

>>> useradd xxx (xxx为你要新建的用户名)

为新用户设置密码

>>> passwd xxx (xxx为你要新建的用户名)

修改SSHD配置,禁止root直接登录

>>> vi /etc/ssh/sshd_config

查找#PermitRootLogin yes
将前面的#去掉,“Yes”改为“No”,并保存文件。

重启sshd服务

>>> systemctl restart sshd.service

禁用密码登录

还可以做得更绝一点,开启密钥登录然后禁用密码登陆:

>>> vim /etc/ssh/sshd_config #修改 PasswordAuthentication yes/no
>>> systemctl restart sshd.service
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

颹蕭蕭

白嫖?

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值