How to delete a user in Ubuntu but keep his home dir?
I need to delete a user, but I need to keep his home dir.
I tried userdel -r user
, but this also removes his home dir.
Is there a way to do this?
Solution 1:
The -r
does the exact opposite of what you want. From userdel --help
:
-r, --remove remove home directory and mail spool
Instead of userdel -r user
, just use:
userdel user
Solution 2:
Option 1:
Use the deluser command.
However, before doing so check the file /etc/deluser.conf
And check the line
# Remove home directory and mail spool when user is removed
REMOVE_HOME = 0
Ensure this to 0 (not 1) before calling deluser.
Option 2:
sudo vipw Find the entry you want to remove (first part of the line up to the first ':' is the username). Then type "dd" to remove the entire line.
Save and exit with "esc + wq".