How can I delete root (admin) users that have same UID(0) as root?

1

This is my passwd file:

root:x:0:0:root:/root:/bin/bash
m:x:0:100::/home/m:/bin/bash
masoudjjgh:x:1000:100:masoudjjgh:/home/masoudjjgh:/bin/bash

I try to delete user m that I am created:

[root@...]# userdel m
[root@...]# userdel: user m is currently used by process 1

And when I try to kill m by this command:

[root@...]# killall -KILL -u m

desktop (kde), console and anything exited and logged me off automatically. All things close and I must login again. userdel will again close all. Is there anyway to remove m?

I created it, but now I can't delete it.

mlibre

Posted 2014-08-28T13:18:33.700

Reputation: 195

Answers

4

root:x:0:0:root:/root:/bin/bash  
m:x:0:100::/home/m:/bin/bash
[...]
# userdel: user m is currently used by process 1
# killall -KILL -u m

Processes and files are actually owned by user ID numbers, not user names. m and root have the same UID, so everything owned by one is also owned by the other. Based on your description, it sounds like both userdel and killall saw every root process (UID 0) as belonging to this user "m".

According to this sample man page, userdel has an option -f to force removal of the account even if it has active processes. And userdel would probably just delete m's passwd entry and home directory, without affecting the actual root account.

To be safer, I might be inclined to hand-edit the password file to remove the entry for m, then hand-remove m's home directory. You may have a command on your system named vipw, which lets you safely edit /etc/passwd in a text editor.

Kenster

Posted 2014-08-28T13:18:33.700

Reputation: 5 474

same UID very important point that you see it. than i can change m'UID , restart and then remove m. yes? – mlibre – 2014-08-28T14:52:40.720

Yes. I would expand Kenster's suggestion to say: manually edit the password file to change m's UID to a number not used by any other user, and then do userdel m. It should not be necessary to restart. – G-Man Says 'Reinstate Monica' – 2014-08-28T15:43:16.623

2

Delete the lines in your passwd and shadow files in your /etc directory manually first. You can then rm -fR the home directory for that user account. (m in your example)

Additional files will still have to be removed. For example:

/var/spool/mail/m

This is a very surgical approach to use when userdel refuses to work.

Jeff Clayton

Posted 2014-08-28T13:18:33.700

Reputation: 918

tnx its work. but perhaps few thing not delete. – mlibre – 2014-08-28T13:46:03.057

tnx. very good command. i try it and see very good files that must be deleted. – mlibre – 2014-08-28T14:09:37.213

find / -user m is really questionable here. This "m" user has UID 0, which is also root's UID. So there's no distinction between files owned by "m" and files owned by "root". – Kenster – 2014-08-28T14:23:28.527

2

in /etc/passwd file change the guid of the user you want to delete to something other than 0. Then attempt a userdel.

Source: http://www.shellhacks.com/en/HowTo-Create-USER-with-ROOT-Privileges-in-Linux

Sindhu S

Posted 2014-08-28T13:18:33.700

Reputation: 121

This is essentially the same as just removing that line from the passwd file. You're effectively detaching the user from everything it owns, and leaving any remnants behind. – Dan – 2015-04-23T18:00:38.263

1

It will made you some problem, because some of problem, need of `root.rootfor running. I have a better suggestion:

  1. Import an account to /etc/suders as:

    youraccount   ALL=(ALL) ALL
    
  2. Change root user as /bin/false as a non-login user.

PersianGulf

Posted 2014-08-28T13:18:33.700

Reputation: 823

+1 Good answer, while it did not actually answer the question asked - which was how to delete a root user, it gave a different (SAFER) way to log in. – Jeff Clayton – 2014-08-28T14:10:45.823

tnx mohsen. by jeff'command (find -user *) i find very files that i must see those and perhaps delete manulay! – mlibre – 2014-08-28T14:13:42.953