无法删除“postgres”用户,因为 /etc/passwd 中缺少该用户

无法删除“postgres”用户,因为 /etc/passwd 中缺少该用户

我正在尝试在 CentOS 7 服务器上安装 Postgresql。但是当我想添加用户并执行时sudo -u postgres -i,什么也没发生,甚至没有错误。

文件postgres中缺少该用户。 我从服务器中删除了所有 postgres 配置,现在我正尝试删除 postgres 用户。/etc/passwd/etc/shadow

userdel postgres
userdel: cannot remove entry 'postgres' from /etc/passwd
useradd postgres
useradd: user 'postgres' already exists

我试图在 /etc/passwd 中手动添加一行,其中包含找到的 uid id postgres,它删除了该行/etc/password,但它仍然存在。

有人知道吗?

答案1

如果用户在 /etc/passwd 和 /etc/shadow 中不存在,则不存在。删除 postgres 包可能会同时删除该用户。

最好不要编辑 passwd 和 shadow 文件目录。尝试使用为此目的设计的实用程序(usermod、userdel、passwd 等)。

在安装 postgres RPM 期间可能会生成 postgres 用户。所需的系统帐户通常是 - 虽然我对 postgres 并不是特别熟悉。

答案2

尝试使用userdel -f

根据 userdel 手册页:

    -f, --force

    This option forces the removal of the user account, even if the user is still logged in. It also forces userdel to remove the user's home directory and mail spool, even if another user uses the same home directory or if the mail spool is not owned by the specified user. If USERGROUPS_ENAB is defined to yes in /etc/login.defs and if a group exists with the same name as the deleted user, then this group will be removed, even if it is still the primary group of another user.

相关内容