1、用户帐号和环境

1.1、验证账号情况

awk -F:($2 == “”) { print $1 }/etc/shadow
awk -F:($3 == 0) { print $1 }/etc/passwd

###任何UID为0的账号在系统上都具有超级用户权限.

1.2、密码长度与有效期

默认配置:

[root@localhost ~]# cat /etc/login.defs |grep PASS_ |grep -v '#' PASS_MAX_DAYS 99999 PASS_MIN_DAYS 0 PASS_MIN_LEN 5 PASS_WARN_AGE 7

加固方案:

1.备份配置文件:
# cp -a /etc/login.defs /etc/login.defs.default
2.编辑配置文件并将相关参数改成如下
# vi /etc/login.defs PASS_MAX_DAYS 90 PASS_MIN_DAYS 6 PASS_MIN_LEN 8 PASS_WARN_AGE 30

备注:

/etc/login.defs文件的pass_min_len 参数并不具备强制性,测试仍然可以设置7位密码。最终需要cracklib来实现。

参数说明:

PASS_MAX_DAYS 密码有效期

PASS_MIN_DAYS 修改密码的最短期限

PASS_MIN_LEN 密码最短长度

PASS_WARN_AGE 密码过期提醒

1.3、密码复杂度

默认配置:

[root@localhost ~]# cat /etc/pam.d/system-auth | grep  "pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=" password    requisite     pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=

加固方案:

1.备份配置文件: # cp -a /etc/pam.d/system-auth /etc/pam.d/system-auth.default 
2.编辑配置文件 # vi /etc/pam.d/system-auth 将password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
注释并在其下面新增1行 password requisite pam_cracklib.so try_first_pass minlen=8 difok=5 dcredit=-1 lcredit=-1 ocredit=-1 retry=1 type=
3.保存配置文件

备注:

try_first_pass而当pam_unix验证模块与password验证类型一起使用时,该选项主要用来防止用户新设定的密码与以前的旧密码相同。

minlen=8:最小长度8位

difok=5:新、旧密码最少5个字符不同

dcredit=-1:最少1个数字

lcredit=-1:最少1个小写字符,(ucredit=-1:最少1个大写字符)

ocredit=-1:最少1个特殊字符

retry=1:1次错误后返回错误信息

type=xxx:此选项用来修改缺省的密码提示文本

1.4、新口令不能与4个最近使用的相同

默认配置:

[root@localhost ~]# cat /etc/pam.d/system-auth |grep use_authtok password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok

加固方案:

1.备份配置文件 
2.编辑配置文件: # vi /etc/pam.d/system-auth 在password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok 所在行的后面添加 remember=5
3.保存配置文件
备注:
记住5个历史密码

1.5、设置会话超时(5分钟)

默认配置:

加固方案:

cp -a /etc/profile /etc/profile.default 
echo "export TMOUT=300 " >>/etc/profile

1.备份配置文件: # cp -a /etc/profile /etc/profile.default

2.编辑配置文件: vi /etc/profile 在文件的末尾添加参数 export TMOUT=300

3.保存配置文件


1.6、防止IP SPOOF:

echo "nospoof on" >> /etc/host.conf

1.7、限制能够su为root 的用户

在文件头部添加下面这样的一行

auth required pam_wheel.so use_uid
这样,只有wheel组的用户可以su到root

操作样例:

#usermod -G10 test 将test用户加入到wheel组