首页 > 其他 > 详细

第十二周

时间:2020-07-05 21:24:55      阅读:47      评论:0      收藏:0      [点我收藏+]

1、编写脚本/root/bin/checkip.sh,每5分钟检查一次,如果发现通过ssh登录失败 次数超过10次,自动将此远程IP放入Tcp Wrapper的黑名单中予以禁止防问

[root@centos7 bin]#cat checkip.sh 
#!/bin/bash

touch /etc/hosts.deny
lastb | awk ‘/ssh/{IP[$3]++}END{for(n in IP){if(IP[n]>2){system("echo ‘sshd:‘" n ":deny >> /etc/hosts.deny")}}}‘
grep ‘^#‘ /etc/hosts.deny > /etc/hosts.deny.tmp
grep -v "^#" /etc/hosts.deny | sort -u >> /etc/hosts.deny.tmp
cat /etc/hosts.deny.tmp > /etc/hosts.deny
rm -f /etc/hosts.deny.tmp


[root@centos7 bin]#crontab -l
*/5 * * * * /bin/bash /root/bin/checkip.sh

2、配置magedu用户的sudo权限,允许magedu用户拥有root权限

# 使用visudo,添加下面一行
[root@centos7 ~]#visudo
magedu  ALL=(root)  ALL

# 验证效果
[root@centos7 ~]#su - magedu
Last login: Sat Jul  4 12:40:52 CST 2020 on pts/2

# 使用sudo才可以访问/root目录
[magedu@centos7 ~]$ls /root
ls: cannot open directory /root: Permission denied
[magedu@centos7 ~]$sudo ls /root
anaconda-ks.cfg  bin  create.sh  expect2.sh  expect3.sh  expect.sh  hellodb_innodb.sql	initial-setup-ks.cfg

第十二周

原文:https://www.cnblogs.com/kfscott/p/13251875.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!