Linux基础安全配置(centos7)
阅读原文时间:2023年07月10日阅读:1

1、帐户口令的生存期不长于90天

sed -i.old 's#99999#90#g' /etc/login.defs
egrep "90" /etc/login.defs

2、密码强度
口令长度至少12位,并包括数字、小写字母、大写字母和特殊符号4类中至少3类, 更新的口令至少5次内不能重复。

sed -i.old '14apassword requisite pam_pwquality.so minlen=12 dcredit=-1 ucredit=-1 lcredit=-1 ocredit=-1 try_first_pass local_users_only retry=5 enforce_for_root authtok_type=' /etc/pam.d/system-auth
egrep "minlen=12" /etc/pam.d/system-auth

3、用户登录回话超时时间
设置回话超时时间为5分钟,如果用户登录5分钟无响应则中断回话

echo "export TMOUT=300" >>/etc/profile
source /etc/profile

4、账户锁定策略
当用户终端登录失败次数超过5次,锁定半小时

sed -i.old22 '3aauth required pam_tally2.so deny=5 unlock_time=1800 even_deny_root root_unlock_time=1800' /etc/pam.d/system-auth
egrep "unlock_time=1800" /etc/pam.d/system-auth

5、 系统审计日志开启

service auditd restart
service rsyslog restart
service auditd status|egrep 'running'
service rsyslog status|egrep 'running'

6、 防火墙开启

systemctl restart firewalld
systemctl status firewalld |egrep 'running'

7、普通用户特定ip远程登录禁止root远程登录
  指定跳板机和运维服务器登录,其他服务器禁止ssh登录

1、允许普通账户登录
echo "AllowUsers appuser@10.0.2.35" >> /etc/ssh/sshd_config
systemctl restart sshd

2、禁止root远程连接
echo "PermitRootLogin no" >> /etc/ssh/sshd_config

#删除该策略(意味着所有源ip都能用普通账户登录该主机)
  #sed -i '/^AllowUsers/d' /etc/ssh/sshd_config

8 应用最小化权限运行
Tomcat应用基本已经是appuser用户运行,检查是有遗漏的

ps -ef|grep java

9 检查是否存在空口令和root权限的账号

egrep ":0:0:" /etc/passwd |wc -l
egrep ":0:" /etc/group |wc -l

注:仅供参考,建议测环境测试,如若出了问题概不负责。