I am supposed to clear all users that have the ID of 0 other than root. For example, my passwd file contains a user root with ID 0 and a user homer with ID 0.
I tried something like
grep :x:0: passwd | grep -v root:x: | awk -F : '{ print $1 }' | xargs userdel
but I received error userdel: user homer is currently logged in even though I am logged in as root, not homer. This error comes from them sharing and ID, I presume.
Is there any way around this? Should I just edit the passwd and shadow files? Otherwise, is there a way to force id 0 to be unique so that we can guarantee no other users will be created with id 0? Thanks.
"homer" and "root" are the same account. You can have multiple usernames for a single account. See also https://unix.stackexchange.com/questions/49993/another-account-with-same-uid-as-root-gets-prompted-to-set-new-password-for-root
You'll want vipw
and vipw -s
to fix this. Editing directly with vim
or sed
is a bad idea.
Consider https://serverfault.com/ or https://unix.stackexchange.com/ for future questions of this type.