passwd安全加固脚本分享
发布日期:2021-07-01 04:12:33
浏览次数:2
分类:技术文章
本文共 1831 字,大约阅读时间需要 6 分钟。
前言
有的时候,使用chattr未必可以保证passwd不被篡改。下面分享的是/etc/passwd的安全加固脚本,相对的解决篡改问题。
使用前提:
要在$file1路径添加一份passwd的备份,可使passwd被改写后恢复,因此要保证passwd备份为正常的。 当新添加/修改服务或用户时,要先"chattr -i ",再修改;然后将修改后的/etc/passwd拷贝到file1路径下,且要在设定的sleep的时间内完成,否则用户修改不会生效。此脚本建议使用后台运行:
chmod +x /script/check_passwd.shnohup /script/check_passwd.sh &
#!/bin/bash check() { TIME=`date +%F-%R` file1=/etc/back/passwd file2=/etc/passwd if [ -s $flie2 ];then lsattr $file2 | grep i > /dev/null if [ $? -eq 0 ];then echo "$TIME passwd file rights is ok" >> /var/log/passwd_file.log #当/etc/passwd中存在UID为0,且非root用户的用户,就删除改用户 awk -F ':' '($3==0){print $1}' $file2 |grep -v root > /var/log/userdel.log for duser in `cat /var/log/userdel.log` do chattr -i /etc/passwd userdel -r $duser #sed -i "/$duser/d" /etc/passwd #sed -i "/$duser/d" /etc/group #sed -i "/$duser/d" /etc/shadow rm -rf /home/$duser rm -rf /var/spool/mail/$duser #userdel -r $duser chattr +i /etc/passwd done else #下方是判断文件内容是否一致 diff $file1 $file2 > /dev/null if [ $? -eq 0 ]; then echo "$TIME file are same" >> /var/log/diff.log else echo "$TIME file are different" >> /var/log/diff.log fi tail -n1 /var/log/diff.log |grep different > /dev/null if [ $? -eq 0 ]; then chattr -i $file2 \cp $file1 $file2 chattr +i $file2 echo "$TIME ERROR: passwd file is update" >> /var/log/passwd_file.log fi fi else \cp $file1 $file2 chattr +i $file2 echo "$TIME ERROR: passwd file does not exist;passwd file is update" >> /var/log/passwd_file.log fi}while truedo check sleep 3600 done
备注:当复制粘贴导致窜行时,建议手打。
转载地址:https://moxiao.blog.csdn.net/article/details/89187034 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月22日 06时13分19秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
EL、JSTL、servlet
2019-05-02
2 QCreator调试并查看源码
2019-05-02
4 Qt 之 pro 配置多个子工程/子模块
2019-05-02
12 Qt 之 QToolBox、QLCDNumber
2019-05-02
32 Qt 之绘图之绘制一个漂亮的西瓜
2019-05-02
33 Qt 之绘图之绘制卡通蚂蚁
2019-05-02
34 Qt 之绘图之绘制时钟
2019-05-02
35 Qt 之绘制闪烁文本
2019-05-02
QT知识点总结(一)
2019-05-02
Unix环境变量--文件操作
2019-05-02
Unix环境变量--进程管理
2019-05-02
Unix环境变量--信号(一)
2019-05-02
Unix环境变量--线程基础
2019-05-02
Unix环境变量--缓冲区
2019-05-02
Unix环境变量--POSIX异步I/O
2019-05-02
UNIX环境变量--存储映射I/O
2019-05-02
tinyhttpd源码学习1
2019-05-02
Plus One
2019-05-02
Linux内核完全剖析0.12(一)
2019-05-02
Sum Root to Leaf Numbers
2019-05-02