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?

jwodder
  • 916

2 Answers2

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.

pLumo
  • 27,991
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.

Ravexina
  • 57,256