Linux 修改root密码报错

情况一

认证的地方出问题了。
现象:

1
2
3
[root@x ~]# passwd  root
Changing password for user root.
passwd: Authentication token manipulation error

检查/etc/pam.d/passwd、/etc/pam.d/system-auth以下配置是否存在:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
cat /etc/pam.d/system-auth
#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth required pam_env.so
auth required pam_faildelay.so delay=2000000
auth sufficient pam_unix.so nullok try_first_pass
auth requisite pam_succeed_if.so uid >= 1000 quiet_success
auth required pam_deny.so

account required pam_unix.so
account sufficient pam_localuser.so
account sufficient pam_succeed_if.so uid < 1000 quiet
account required pam_permit.so

#password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok
password required pam_deny.so

session optional pam_keyinit.so revoke
session required pam_limits.so
-session optional pam_systemd.so
session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session required pam_unix.so

发现设置密码复杂被人注释了

1
password    requisite     pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=

修复去掉# 就可以了。
如果没有文件,或者文件被改动比较大,可以去同系统版本的操作系统上把这两个文件copy过来覆盖。

这条是设置密码,设置口令复杂度, 参数意思。

difok= :此选项用来定义新密码中必须要有几个字符和旧密码不同

minlen=:此选项用来设置新密码的最小长度

ucredit= :此选项用来设定新密码中可以包含的大写字母的最大数目。-1 至少一个

lcredit=:此选项用来设定新密码中可以包含的小写字母的最大数目

dcredit=:此选项用来设定新密码中可以包含的数字的最大数目 

情况二

/etc/passwd, /etc/shadow文件被锁住,不允许修改。
现象:

1
2
3
4
[root@x ~]# lsattr /etc/passwd
----i-------- /etc/passwd
[root@x ~]# lsattr /etc/shadow
----i-------- /etc/shadow

情况

1
2
3
4
5
6
[root@x ~]# passwd root
Changing password for user root.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: Authentication token manipulation error

解决方法:

1
2
3
4
5
6
[root@x ~]#  chattr -i /etc/shadow
[root@x ~]# chattr -i /etc/passwd
[root@x ~]# lsattr /etc/passwd
------------- /etc/passwd
[root@x ~]# lsattr /etc/shadow
------------- /etc/shadow

情况三

磁盘空间满了,检查下,并清理磁盘空间

1
2
3
4
5
6
7
8
[root@x ~]#  df -l
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 20960256 20960256 0 100% /
devtmpfs 980108 0 980108 0% /dev
tmpfs 990780 0 990780 0% /dev/shm
tmpfs 990780 106996 883784 11% /run
tmpfs 990780 0 990780 0% /sys/fs/cgroup
tmpfs 198156 0 198156 0% /run/user/0