Linux: Can not sudo, unkown user root (solution)


Mon Aug 29 2022 14:16:20 GMT+0000 (Coordinated Universal Time)

Saved by @marcopinero #bash

sudo -u \#0 vi /etc/passwd

WHY CAN'T I SUDO.. UNKNOWN USER ROOT Recently I came across an issue while trying to edit a file using sudo as root. sudo reported that the user 'root' was unknown. sudo vi /etc/root-owned-file sudo: unknown user: root A quick check revealed that for some reason a previous person had edited the /etc/passwd file and changed the 'root' owner to 'oot'. root:x:0:0:root:/root:bin/bash Was changed to oot:x:0:0:root:/root:/bin/bash So the root user did not exist on the host. This could have proven catastrophic as nothing could be edited via sudo. You can't login as the user 'oot' with the root passwd because there is no user 'oot' in /etc/shadow ###### HOW TO FIX: ############ You can use sudo to access files as a specific user by UID. in this case UID 0 for root. to fix the /etc/passwd file simply use sudo and edit /etc/passwd as the UID 0: sudo -u \#0 vi /etc/passwd you must 'escape' the pound sign in sudo with a \ before the UID of 0 This will allow you to edit /etc/passwd as UID 0 and correct the mistakes in /etc/passwd