恢复男人用户


34

由于某种矛盾的原因(或睡眠不足),我输入了

deluser man

而不是更常见

man deluser

……您可以想象,我刚刚删除了man用户!从来没有发生过...

如何正确还原系统的男性用户?


5
这是一个完美的示例,为什么您不将root用于不需要root的事情。
兰迪·奥里森

Answers:


33

有一个名为的实用程序update-passwd可以为您安全地执行此操作:

NAME
       update-passwd - safely update /etc/passwd, /etc/shadow and /etc/group

SYNOPSIS
       update-passwd [options]

DESCRIPTION
       update-passwd   handles   updates   of   /etc/passwd,  /etc/shadow  and
       /etc/group on running Debian systems.  It compares the current files to
       master  copies, distributed in the base-passwd package, and updates all
       entries in the global system range (that is, 0–99).

首先检查当前条目

$ getent passwd man
man:x:6:12:man:/var/cache/man:/bin/sh

现在让我们删除它

$ sudo deluser man
[sudo] password for steeldriver: 
Removing user `man' ...
Warning: group `man' has no more members.
Done.

检查它真的消失了

$ getent passwd man
$ 

然后

$ sudo update-passwd --dry-run
Adding group "man" (12)
Adding user "man" (6)
Would commit 2 changes

好的,让我们一起做

$ sudo update-passwd
2 changes have been made, rewriting files

现在确认还原的密码文件条目

$ getent passwd man
man:*:6:12:man:/var/cache/man:/bin/sh

2
优秀+赞成。请接受此内容,而不是我的内容;)
Rinzwind
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.