4

In a terminal:

/home$ ls
abuabdullah  alzaabi  hussain  u942

Then I tried to delete account u942 by using command line:

/home$ deluser u942
/usr/sbin/deluser: Only root may remove a user or group from the system.

Then I tried to use sudo

/home$ sudo deluser u942
/usr/sbin/deluser: The user `u942' does not exist.

How can I solve this problem?

3
  • 7
    Did somebody just create a directory in /home? Is there a reason you think there's an account named u942 in your system?
    – muru
    May 8, 2017 at 8:30
  • To verify that there is no such user: Whats the output of cut -d: -f1 /etc/passwd | grep u942. (probably empty)
    – pLumo
    May 8, 2017 at 8:32
  • 2
    please add the output of ls -lsd /home/u942 so we'll able to see the owner of this folder
    – Yaron
    May 8, 2017 at 8:38

2 Answers 2

8

For root/sudo user it is possible to just create folders in /home that are not associated to any user account. That is why ls /home is not a good command to check for users.

To list all users that have their home folder below "/home", you can run:

getent passwd | grep "/home" | cut -d: -f1

List all users: getent passwd | cut -d: -f1

Check if user u942 exists: getent passwd | grep u942. If you get no output, no such user exists.

If the output is empty, you can delete that folder (you might need sudo) rm -Rf /home/u942. But double check the contents of the folder before you delete it.

5
  • 1
    rm command won't work, to delete folder with content use rm -rf /home/u942 instead. Note: Be careful, as with -rf flag you can easily delete anything. May 8, 2017 at 8:46
  • 2
    You should actually use getent passwd instead of reading /etc/passwd manualy. In particular, to see if a u942 is a user in the system: getent passwd u942.
    – muru
    May 8, 2017 at 8:50
  • Why "should" I. There is no problem with /etc/passwd. getent passwd gives me also non-local users, which I may or may not want.
    – pLumo
    May 8, 2017 at 8:54
  • 3
    You gave the reason: "non-local users". There's no guarantee that non-local users also have non-local home directories. "If you get no output, no such user exists" is not necessarily true if you only read /etc/passwd.
    – muru
    May 8, 2017 at 9:01
  • That is true. I edited the answer ...
    – pLumo
    May 8, 2017 at 9:08
3

As you might know, it's possible to create a home directory differ from "username". For example I can have a user named "john" which its home directory is: /home/jack.

If you already know the user name, you could run:

echo ~username

It would print that specific user home directory. You can also run:

ls -ld /home/u942

or

stat -c %U /home/u942

to see which user owns this home directory then delete that user.

Also there is a chance that user is already deleted but its home directory not.

To find it out you can do something like:

id -un `stat -c %U /home/u942`

If it returned nothing it means the owner does not exist on your system. simply remove that directory If only you believe there is no important file there.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .