1、核查空口令的用户的方法:
针对要核查的用户,使用:passwd –S 用户名,核查其状态等信息:
#passwd –S root
root PS 2021-11-11 0 99999 7 -1 (Password set, MD5 crypt.)
字段 | 示例 | 含义 |
1 | Test | 表示用户名 |
2 | PS | 表示用户密码状态,有三种状态: PS = Passworded,表示已设置密码 LK = Locked ,表示已锁住密码 NP = No Password,表示无密码 |
3 | 2013-03-11 | 密码修改日期,/etc/shadow中第三字段 |
4 | 0 | 密码冻结天数,/etc/shadow中第四字段 |
5 | 99999 | 密码有效天数,/etc/shadow中第五字段 |
6 | 7 | 密码警告天数,/etc/shadow中第六字段 |
7 | -1 | 密码宽限天数,/etc/shadow中第七字段,为-1表示不会失效, |
上述信息也可以通过“chage –l 用户名”命令核查:
[root@localhost etc]# chage -l root
Last password change : Nov 12, 2021
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
[root@localhost etc]# chage -l test6
Last password change : Nov 13, 2021
Password expires : Feb 21, 2022
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 100
Number of days of warning before password expires : 12
有时即使是空口令,通过ssh也不一定能登录,核查/etc/ssh/sshd_config文件,内部设定:
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes
上面的设置,通过ssh登录,空口令是no(缺省是no,即使是带#),需要口令鉴权的设置是yes,就是必须要口令才行。空口令不行。
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes
PermitEmptyPasswords yes
上述的情况,通过ssh就可以空口令登录了。
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
PermitEmptyPasswords yes
PasswordAuthentication yes
上述的情况,无论是前后顺序,通过ssh也是可以空口令登录了。
现在root用户登录:
#PermitRootLogin yes(缺省是可以登录),如果想限制root通过ssh登录,需要设置:
PermitRootLogin no
2、核查UID和GID相同的方法(用户改名等)
核查passwd文件的可使用用户命令:
cat /etc/passwd | grep -v 'nologin' 或者直接用:more /etc/passwd
root:x:0:0:root:/root:/bin/bash
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
test:x:500:500:Redhat6.4:/home/test:/bin/bash
test1:x:501:501::/home/test1:/bin/bash