Il existe un utilitaire appelé update-passwd
qui semble le faire en toute sécurité pour vous:
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).
Vérifiez d'abord l'entrée actuelle
$ getent passwd man
man:x:6:12:man:/var/cache/man:/bin/sh
Maintenant, supprimons-le
$ sudo deluser man
[sudo] password for steeldriver:
Removing user 'man' ...
Warning: group 'man' has no more members.
Done.
Vérifiez que c'est vraiment parti
$ getent passwd man
$
Alors
$ sudo update-passwd --dry-run
Adding group "man" (12)
Adding user "man" (6)
Would commit 2 changes
OK faisons-le
$ sudo update-passwd
2 changes have been made, rewriting files
Confirmez maintenant l’entrée du fichier de mot de passe restauré
$ getent passwd man
man:*:6:12:man:/var/cache/man:/bin/sh