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?

link|improve this question
1  
"I tried" is not enough if you try blindly and without researching. Even a quick scan of "userdel"s manual would tell you that you are asking it to remove the home directory by giving -r. – grawity Feb 8 at 9:34
feedback

2 Answers

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
link|improve this answer
feedback

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".

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.