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

25,092

Solution 1

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.

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

Solution 3

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

Solution 4

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.
Share:
25,092

Related videos on Youtube

mlibre
Author by

mlibre

A Computer Science Engineer with +10 years of professional experience in Computers, Web, OSs, Linux, Nodejs, Web, Programming, BlockChain, ... Flexibility, Problem Solving, Creativity, and Innovation are my features

Updated on September 18, 2022

Comments

  • mlibre
    mlibre over 1 year

    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
    mlibre over 9 years
    tnx its work. but perhaps few thing not delete.
  • mlibre
    mlibre over 9 years
    tnx. very good command. i try it and see very good files that must be deleted.
  • Jeff Clayton
    Jeff Clayton over 9 years
    +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.
  • mlibre
    mlibre over 9 years
    tnx mohsen. by jeff'command (find -user *) i find very files that i must see those and perhaps delete manulay!
  • Kenster
    Kenster over 9 years
    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".
  • mlibre
    mlibre over 9 years
    same UID very important point that you see it. than i can change m'UID , restart and then remove m. yes?
  • G-Man Says 'Reinstate Monica'
    G-Man Says 'Reinstate Monica' over 9 years
    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.