DEBUG.WIKI
PanstarCloud:部署应用,接入 AI,云服务器与 AI 网关
晚安云;香港 CN2 ¥15/月
V.PS:让项目靠近用户,亚太、欧洲、北美 KVM VPS

解决 Linux 报错 groupadd PAM Authentication failure 异常

分析 Linux 使用 root 权限执行 groupadd 提示 PAM Authentication failure 的 limits.conf 与 PAM 规则损坏修复方案。

问题现象

即使使用 root 身份执行 groupadd 创建新用户组时,系统报错中断:

groupadd: PAM: Authentication failure
groupadd: cannot rewrite group file

触发根因

  1. PAM 配置文件(/etc/pam.d/other 或 /etc/pam.d/common-auth)被误修改,默认策略设置为了 deny。
  2. 系统最大文件句柄或资源限制在 PAM 会话加载时失败(如 /etc/security/limits.conf 存在语法错误)。
  3. SELinux 安全上下文或只读属性阻碍了 PAM 对 /etc/group 的重写。

解决步骤与操作命令

步骤一:检查 /etc/pam.d/other 兜底配置

确保其没有直接拒绝所有未知认证请求:

#%PAM-1.0
auth        required      pam_deny.so
auth        required      pam_warn.so
account     required      pam_deny.so
password    required      pam_deny.so
session     required      pam_deny.so

步骤二:排查 /etc/group 文件是否被赋予了只读锁属性(chattr +i)

lsattr /etc/group /etc/gshadow

若看到 i 属性(不可变锁),使用 chattr 解除:

sudo chattr -i /etc/group /etc/gshadow

步骤三:验证 limits.conf 语法

确保 /etc/security/limits.conf 无多余非数字字符或破损行。

验证确认

再次运行用户组创建:

sudo groupadd testgroup
getent group testgroup

用户组成功创建并打印 GID,PAM 认证失败报错彻底消除。