Problem:
There is no root user in /etc/passwd – I accidentally overwrote it.
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,
1 2 3 | $ sudo passwd root |
It will ask you to set the root password, set the password and login with root.
1 2 3 | $ su root |
The 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):
1 2 3 | root:x:0:0:root:/root:/bin/bash |
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:
1 2 3 4 5 6 7 8 9 | User name Encrypted password User ID number (UID) User's group ID number (GID) Full name of the user (GECOS) User home directory Login shell |
The following is an example of an /etc/passwd file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | root:!:0:0::/:/usr/bin/ksh daemon:!: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/false invscout:x:200:1::/var/adm/invscout:/usr/bin/ksh nuucp:x:6:5:uucp login user:/var/spool/uucppublic:/usr/sbin/uucp/uucico ishtiyaq:x:201:1::/home/ishtiyaq:/bin/bash |