- 要更新的软件:
bash,openssl,glibc
配置密码不允许重复次数和复杂度
#编辑/etc/pam.d/system-auth文件,找到以下行: password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok #后面添加 remember=3 代表不允许使用之前3次用过的密码
#找到以下行 password requisite pam_cracklib.so try_first_pass retry=3 type= 修改为: password requisite pam_cracklib.so try_first_pass retry=6 ucredit=-1 lcredit=-1 dcredit=-1 ocredit=-1 #retry=N 重试N次后返回密码错误 #difok=N 新密码必需与旧密码不同的位数 #dcredit=N N>=0表示密码最多N个数字,反之最少N个数字 #lcredit=N 小写字母个数 #ucredit=N 小写字母个数 #ccredit=N 小写字母个数 #minclass=N 密码组成(大/小字母,数字,特殊字符) #root不受此限制,普通用户登录后改密码才受限制
禁止root登录
#更改/etc/ssh/sshd_config,之后重启sshd PermitRootLogin yes 改成:PermitRootLogin no
修改密码长度和过期时间:
#改 /etc/login.defs PASS_MAX_DAYS 90 PASS_MIN_DAYS 1 PASS_MIN_LEN 9 PASS_WARN_AGE 7 解释: # PASS_MAX_DAYS 密码使用的最长期限 # PASS_MIN_DAYS 密码允许更改的最短期限 # PASS_MIN_LEN 能接受的密码最短长度 # PASS_WARN_AGE 密码过期之前的提醒天数
设置连续失败次数和失败锁定时间
修改(/etc/pam.d/system-auth和/etc/pam.d/sshd)分别在开始位置加入以下内容:
auth required pam_tally2.so deny=6 unlock_time=300 even_deny_root root_unlock_time=120 #最大失败次数6次,超过6次锁定300s,root用户锁定120s #两个文件中"required pam_tally2.so deny"要删掉
umask降权,设置历史命令数
默认uid>199的umask是022,uid<199的umask是022,可以在/etc/profile里新加一行”umask 027”,修改HISSIZE=100,即最大历史命令是100
修改ssh banner
自定义banner文件:echo “Only Gomeholdings users can login” > /etc/ssh/gomebanner
再修改/etc/ssh/sshd_config 新增”Banner /etc/ssh/gomebanner”
修改ssh访问控制
/etc/hosts.allow文件
如: sshd:10.35.0.0/255.255.0.0
禁止访问的文件 /etc/hosts.deny sshd:all
hosts.allow文件优先
空闲超时退出
改/etc/profile 追加 TMOUT=300
su限制
修改/etc/login.defs 追加”SU_WHEEL_ONLY yes”
修改/etc/pam.d/su
将”auth required pam_wheel.so use_uid”取消注释
将要配置su权限的用户加到wheel组:
usermod -G wheel work
取消CTRL+ALT+DELETE
修改/etc/init/control-alt-delete.conf,注释掉以下内容:
start on control-alt-delete
exec /sbin/shutdown -r now “Control-Alt-Delete pressed”
对于Centos7只需:rm -rf /usr/lib/systemd/ctrl-alt-del.target
修改motd,登陆系统后的提示信息
echo “Illegal users are not allowed to login, Only authorized users can login” > /etc/motd
当用显示器连接linux主机的时候,屏幕会显示系统版本等相关信息,可以将他取消掉,将/etc/issue和/etc/issue.net改名即可
禁用不用的用户和组
改/etc/passwd #adm:x:3:4:adm:/var/adm:/sbin/nologin #lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin #sync:x:5:0:sync:/sbin:/bin/sync #shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown #halt:x:7:0:halt:/sbin:/sbin/halt #uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin #operator:x:11:0:operator:/root:/sbin/nologin #games:x:12:100:games:/usr/games:/sbin/nologin #gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
改/etc/group #adm:x:4:root,adm,daemon #lp:x:7:daemon,lp #uucp:x:14:uucp #games:x:20: #dip:x:40:
禁用没用的服务
chkconfig acpid off chkconfig anacron off chkconfig auditd off chkconfig avahi-daemon off chkconfig autofs off chkconfig atd off chkconfig bluetooth off chkconfig cpuspeed off chkconfig cups off chkconfig firstboot off chkconfig gpm off chkconfig haldaemon off chkconfig hidd off chkconfig ip6tables off chkconfig iptables off chkconfig lvm2-monitor off chkconfig mcstrans off chkconfig mdmonitor off chkconfig messagebus off chkconfig nfslock off chkconfig pcscd off chkconfig rawdevices off chkconfig readahead_early off chkconfig restorecond off chkconfig rpcidmapd off chkconfig sendmail off chkconfig xfs off chkconfig yum-updatesd off chkconfig NetworkManager off