deluser: check if specified home is a directory before removing it

On Alpine, some users use /dev/null as a home directory. When removing
such a user with `deluser --remove-home` this causes the /dev/null
device file to be removed which is undesirable. To prevent this pitfall,
check if the home directory specified for the user is an actual
directory (or a symlink to a directory).

Implementations of similar tools for other operating systems also
implement such checks. For instance, the OpenBSD rmuser(1)
implementation [0].


function                                             old     new   delta
deluser_main                                         337     380     +43

Signed-off-by: Sören Tempel <>
Signed-off-by: Denys Vlasenko <>
1 file changed