sudo: unknown user: root (Linux/ubuntu/Debian/CentOS)
Problem:
Section titled “Problem:”There is no root user in /etc/passwd - I accidentally overwrote it.
Solution:
Section titled “Solution:”Download ubuntu Live CD Image and create bootable pendrive or CD. Then boot the system with this pendrive/cd. Now, Open terminal and edit the /etc/passwd file. But, It may not allow to edit this file because it can not be edited by any user except root. So, you have to login with root. Follow these instructions to login with root,
$ sudo passwd rootIt will ask you to set the root password, set the password and login with root.
$ su rootThe passwd file you have to edit will not be there in /etc/passwd location, It is in /media/root/etc/passwd. If linux partition is not mounted then mount it. Now, Put the following into the first line of /media/root/etc/passwd (which is /etc/passwd file for your original os):
root:x:0:0:root:/root:/bin/bashKnow more about /media/root/etc/passwd
Section titled “Know more about /media/root/etc/passwd”Traditionally, the /etc/passwd file is used to keep track of every registered user that has access to a system. The /etc/passwd file is a colon-separated file that contains the following information:
User nameEncrypted passwordUser ID number (UID)User's group ID number (GID)Full name of the user (GECOS)User home directoryLogin shellThe following is an example of an /etc/passwd file:
root:!:0:0::/:/usr/bin/kshdaemon:!:1:1::/etc:bin:!:2:2::/bin:sys:!:3:3::/usr/sys:adm:!:4:4::/var/adm:uucp:!:5:5::/usr/lib/uucp:guest:!:100:100::/home/guest:nobody:!:4294967294:4294967294::/:lpd:!:9:4294967294::/:lp:x:11:11::/var/spool/lp:/bin/falseinvscout:x:200:1::/var/adm/invscout:/usr/bin/kshnuucp:x:6:5:uucp login user:/var/spool/uucppublic:/usr/sbin/uucp/uucicoishtiyaq:x:201:1::/home/ishtiyaq:/bin/bash