How to delete a non-root use with UID 0 in Linux

This pos describes how to delete a non-root user with UID zero. If you try to delete a user with UID 0 by userdel command, you will get the following error.

# id user2
uid=0(root) gid=0(root) groups=0(root)
# userdel user2
userdel: user user2 is currently used by process 1

If you need to delete non-root user having UID 0 (say user1), follow these steps:

1. Backup the /etc/passwd file before proceeding:

# cp /etc/passwd /etc/passwd.bkup

2. Open /etc/passwd and change the UID of user1 from 0 to a UID which is not used by any other user:

user1:x:0:0::/home/scom:/bin/bash

For example:

user1:x:1111:0::/home/scom:/bin/bash

Give a higher number for the new UID and make sure you do not specify standard UIDs.

3. Now, delete the user:

# userdel user1
Note – Never try to delete root user or change its UID.
Related Post