cat
2、查看暴力破解root的IP和次数
3、修改SSh端口,禁止root登陆
vi /etc/ssh/sshd_config
Port 4484
PermitRootLogin no
最后保存,重启/etc/init.d/ssh restar
DenyHosts应用
你会发现,每天会有多条SSH登录失败纪录。那些扫描工具将对你的服务器构成威胁,你必须设置复杂登录口令,并将尝试多次登录失败的IP给阻止掉,让其在一段时间内不能访问该服务器。
用DenyHosts
DenyHosts安装
#wget 官网下载最新版目前是2.6
# tar -zxvf DenyHosts-2.6.tar.gz //解压
# cd DenyHosts-2.6 //切换到目录
# python setup..py install //进行安装 注意,由于百科不能通过,所以应该是一个.,去掉中间一个点
DenyHosts参数配置
# cd /usr/share/denyhosts/ #DenyHosts默认安装目录
# cp denyhosts.cfg-dist denyhosts.cfg
# vi denyhosts.cfg #DenyHosts配置文件
# format is: i[dhwmy]
# Where i is an integer (eg. 7)
# m = minutes
# h = hours
# d = days
# w = weeks
# y = years
#
# never purge:
PURGE_DENY = 50m #过多久后清除已阻止IP
HOSTS_DENY = /etc/hosts.deny #将阻止IP写入到hosts.deny
BLOCK_SERVICE = sshd #阻止服务名
DENY_THRESHOLD_INVALID = 1 #允许无效用户登录失败的次数
DENY_THRESHOLD_VALID = 10 #允许普通用户登录失败的次数
DENY_THRESHOLD_ROOT = 5 #允许root登录失败的次数
WORK_DIR = /usr/local/share/denyhosts/data #将deny的host或ip纪录到Work_dir中
DENY_THRESHOLD_RESTRICTED = 1 #设定 deny host 写入到该资料夹
LOCK_FILE = /var/lock/subsys/denyhosts #将DenyHOts启动的pid纪录到LOCK_FILE中,已确保服务正确启动,防止同时启动多个服务。
HOSTNAME_LOOKUP=NO #是否做域名反解
ADMIN_EMAIL = #设置管理员邮件地址
denyhosts #自己的日志文件
DAEMON_PURGE = 10m #该项与PURGE_DENY 设置成一样,也是清除hosts.deniedssh 用户的时间。
DenyHosts启动文件配置
# cp daemon-control-dist daemon-control
# chown root daemon-control
# chmod 700 daemon-control
# ./daemon-control start #启动DenyHosts
#ln -s /usr/share/denyhosts/daemon-control /etc/init.d #对daemon-control进行软连接,方便管理
安装到这一步就完成了。
#/etc/init.d/daemon-control start #启动denyhosts
#chkconfig daemon-control on #将denghosts设成开机启动
加入到自动重启
# vi /etc/rc.local
加入下面这条命令
/usr/share/denyhosts/daemon-control start
查看攻击ip 记录
# vi /etc/hosts.deny
版权声明:若无特殊注明,本文皆为( yueshuo )原创,转载请保留文章出处。