logo资料库

linux操作系统安全加固方法(最全,亲测有效).docx

第1页 / 共6页
第2页 / 共6页
第3页 / 共6页
第4页 / 共6页
第5页 / 共6页
第6页 / 共6页
资料共6页,全文预览结束
linux安全限制
vi /etc/profile 新加入:TMOUT=600 //600秒无操作,自动退出
[root@station90 桌面]# awk -F : '($2=="") {print $1
linux 安全限制 vi /etc/profile 新加入:TMOUT=600 //600 秒无操作,自动退出 [root@station90 桌面]# awk -F : '($2=="") {print $1}' /etc/shadow //检查空口令 帐号 zhang3 [root@station90 桌面]# tail -n 1 /etc/shadow | head -n 1 //-F :是以冒号作为分隔 符,($2==""表示第 1 个和第 2 个冒号之间是空的,即空口令帐号,{print $1}打印出用户 名 zhang3::15071:0:99999:7::: 检查帐号 [root@station90 桌面]# pwck 用户 adm:目录 /var/adm 不存在 用户 news:目录 /etc/news 不存在 用户 uucp:目录 /var/spool/uucp 不存在 用户 gopher:目录 /var/gopher 不存在 用户 pcap:目录 /var/arpwatch 不存在 用户 avahi-autoipd:目录 /var/lib/avahi-autoipd 不存在 用户 oprofile:目录 /home/oprofile 不存在 pwck:无改变 口令复杂度及登录失败策略 应启用登录失败处理功能,可采取结束会话,限制非法登录次数和自动退出措施,口令应有 复杂度要求并定期更换 要求强制记住 3 个密码历史 口令至少包含 1 个数字,字母和其他特殊字符(如:#,@,!,$等); 5 次远程登录失败自动结束会话 [root@station90 桌面]# cat /etc/login.defs | grep PASS | grep -v ^# PASS_MAX_DAYS 90 //口令最大使用日期 90 天 PASS_MIN_DAYS 0 //若设置为 2,则设置密码 2 天后才可以再次更改密码,即密码至少要保 留的天数 PASS_MIN_LEN 8 //口令最小长度 8 位 PASS_WARN_AGE 7 //口令过期前 7 天警告 [root@station90 pam.d]# cat /etc/pam.d/system-auth | tail -n 2 && grep ^#password /etc/pam.d/system-auth password required pam_cracklib.so difok=3 minlen=8 dcredit=-1,lcredit=-1 ocredit=-1 maxrepeat=3 password required pam_unix.so use_authtok nullok md5 #password requisite pam_cracklib.so try_first_pass retry=3 //注释这一行后,无法 修改密码 [root@station90 pam.d]# passwd Changing password for user root. passwd: Authentication information cannot be recovered 修改登录失败策略
[root@station90 ssh]# cat /etc/ssh/sshd_config | grep MaxAuth MaxAuthTries 1 //远程用户通过 ssh 连接登录 2 次失败后自动结束会话 [root@station90 ssh]# ssh 192.168.0.90 root@192.168.0.90's password: Permission denied, please try again. root@192.168.0.90's password: Received disconnect from 192.168.0.90: 2: Too many authentication failures for root 关闭 telnet 服务,redhat 默认是关闭 telnet 服务的 [root@station90 ssh]# netstat -tnlp | grep :23 [root@station90 ssh]# cd /etc/xinetd.d/ [root@station90 xinetd.d]# ls telnet* ls: telnet*: 没有那个文件或目录 如果有 telnet 服务,则把该目录下的 telnet 文件改为 disable=yes [root@station90 xinetd.d]# tail -n 2 /etc/xinetd.d/krb5-telnet | head -n 1 disable = yes [root@station90 xinetd.d]# service xinetd restart 停止 xinetd: [确定] 启动 xinetd: [确定] [root@station90 xinetd.d]# chkconfig xinetd on openssh 应该禁止使用协议 1,禁止 root 直接登录 /etc/ssh/sshd_config Protocol 2 MaxAuthTries 1 PermitRootLogin no //不允许 root 用户使用 ssh 登录 StrictModes yes PermitEmptyPasswords no //不允许使用空密码登录 PrintLastLog yes [root@station60 init.d]# pwd /etc/rc.d/init.d [root@station60 init.d]# chmod -R 750 ./ 也可以直接 chmod -R /etc/init.d/* [root@station60 init.d]# ll | head -n 2 total 644 -rwxr-x--- 1 root root 1566 Jun 8 2009 acpid umask 至少为 027,最好是 077 [root@station60 ~]# grep umask /etc/bashrc umask 077 umask 077 [root@station60 ~]# . /etc/bashrc [root@station60 ~]# umask 0077 [root@station60 ~]# touch 3.txt [root@station60 ~]# ll 3.txt -rw------- 1 root root 0 Apr 8 00:11 3.txt 检查系统是否最小化安装,启动的运行级别为 3
查看/etc/pam.d/su 是否包含以下两行 auth sufficient pam_rootok.so # Uncomment the following line to implicitly trust users in the "wheel" group. #auth sufficient pam_wheel.so trust use_uid # Uncomment the following line to require a user to be in the "wheel" group. auth required pam_wheel.so use_uid //上面的注释已经说的很清楚了,没有注释下面这 一行,那么要 su 到别的用户就必须在 wheel 组中 [root@station60 pam.d]# gpasswd -a oracle wheel Adding user oracle to group wheel [root@station60 pam.d]# id oracle uid=500(oracle) gid=500(oracle) groups=500(oracle),0(root),10(wheel) context=system_u:system_r:unconfined_t [root@station60 pam.d]# id zhang3 uid=501(zhang3) gid=501(zhang3) groups=501(zhang3) context=system_u:system_r:unconfined_t [root@station60 pam.d]# su - zhang3 [zhang3@station60 ~]$ su - root //以下密码输入都是正确的 Password: su: incorrect password [zhang3@station60 ~]$ su - oracle Password: su: incorrect password [zhang3@station60 ~]$ su - oracle Password: su: incorrect password [zhang3@station60 ~]$ su - oracle Password: su: incorrect password [zhang3@station60 ~]$ [oracle@station60 ~]$ su - oracle Password: [oracle@station60 ~]$ su - root Password: [root@station60 ~]# 操作指南 1.本地登录用户参考配置操作 #cd /etc/profile.d 执行 #vi autologout.sh 加入如下内容: TMOUT=600 readonly TMOUT export TMOUT 保存退出,系统将在用户闲置 10 分钟后自动注销。 2.远程登录用户参考配置操作
#vi /etc/ssh/sshd_config 将以下内容设置为: ClientAliveInterval 600 ClientAliveCountMax 0 以上表示 10 分钟闲置后,自动注销并结束会话。 检测方法 1、判定条件 查看帐号超时是否自动注销; 2、检测操作 cat /etc/ssh/sshd_config 检查其中两个参数设置: ClientAliveInterval 600 ClientAliveCountMax 0 (2)执行:awk -F: '($3 == 0) { print $1 }' /etc/passwd 返回值包括“root”以外的条目,说明有其他超级用户,低于安全要求。 2、检测操作 执行:awk -F: '($3 == 0) { print $1 }' /etc/passwd 返回值包括“root”以外的条目,说明有其他超级用户; /etc/securetty 文件设置 root 登陆的 tty 和 vc(虚拟控制台)设备。/etc/securetty 文 件被 login 程序读 (通常 /bin/login)。它的格式是允许的 tty 和 vc 列表,注释掉或不出 现的设备,不允许 root 登陆。 vc/1 #vc/2 #vc/3 #vc/4 #vc/5 #vc/6 #vc/7 #vc/8 #vc/9 #vc/10 #vc/11 tty1 #tty2 #tty3 #tty4 #tty5 #tty6 #tty7 #tty8 #tty9 #tty10 #tty11 root 只能从 tty1 和 vc 登陆。建议仅允许 root 从一个 tty 或 vc 登陆,如果需要更多设备 登陆,使用 su 命令转换为 root。
#!/bin/sh # export file=/root/Desktop/Look_Here echo "These username have null code" >> $file awk -F : '($2 =="") {print $1}' /etc/shadow >> $file #change system code policy #1 login /etc/login.defs perl -i -pe 's,99999,90,g' /etc/login.defs sed -i.bak '18s/5/8/' /etc/login.defs echo "PASS_MIN_LEN 8">> /etc/login.defs #2 pam /etc/pam.d/system-auth echo "password required pam_cracklib.so difok=3 minlen=8 dcredit=-1 lcredit=-1 ocredit=-1 maxrepeat=3" >>/etc/pam.d/system-auth echo "password required pam_unix.so use_authtok nullok md5 " >> /etc/pam.d/system-auth sed -i.bak '13s/password/#password/' /etc/pam.d/system-auth #perl -i -pe 's/password requisite pam_cracklib.so try_first_pass retry=3/#password requisite pam_cracklib.so try_first_pass retry=3'/g /etc/pam.d/system-auth #3 ssh /etc/ssh/sshd_config perl -i -pe 's/#MaxAuthTries 6/MaxAuthTries 5/g' /etc/ssh/sshd_config #4 telnet /etc/xinetd.d/telnet (chkconfig telnet off 2>&1) > /dev/null #5 ssh /etc/ssh/sshd_config perl -i -pe 's/#StrictModes/StrictModes/' /etc/ssh/sshd_config perl -i -pe 's/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config perl -i -pe 's/#PermitEmptyPasswords/PermitEmptyPasswords/' /etc/ssh/sshd_config #6 umask /etc/bashrc perl -i -pe 's/umask 002/umask 077/' /etc/bashrc perl -i -pe 's/umask 022/umask 077/' /etc/bashrc source /etc/bashrc #7 runlevel 3 /etc/inittab perl -i -pe 's/id:5/id:3/' /etc/inittab #8 /etc/pam.d/su sed -i.bak '6s/#auth/auth/' /etc/pam.d/su #9 securetty /etc/securetty perl -i -pe 's/^/#/g' /etc/securetty echo "vc/1" >> /etc/securetty echo "tty1" >> /etc/securetty #10 uid=0 echo "These username's uid is 0" >> $file awk -F : '($3==0) {print $1}' /etc/passwd > $file #11 auto logout /etc/profile.d/ echo "TMOUT=600" >/etc/profile.d/autologout.sh
echo "readonly TMOUT">>/etc/profile.d/autologout.sh echo "export TMOUT" >>/etc/profile.d/autologout.sh chmod +x /etc/profile.d/autologout.sh #12 ssh ClientAliveInterval perl -i -pe 's/#ClientAlive/ClientAlive/g' /etc/ssh/sshd_config sed -i.bak '106s/0/600/g' /etc/ssh/sshd_config sed -i.bak '107s/3/0/g' /etc/ssh/sshd_config #13 chmod chattr chmod 400 /etc/shadow /etc/gshadow chmod 600 /boot/grub/grub.conf /etc/securetty chattr +a /var/log/messages chattr +i /var/log/messages chattr +i /etc/passwd chattr +i /etc/shadow chattr +i /etc/gshadow chattr +i /etc/group chattr +i /etc/services chattr +i /etc/securetty (service sshd restart;chkconfig sshd on) > /dev/null
分享到:
收藏