0

Today I did a stupid thing. I used sudo gedit /etc/passwd changed

x:1000:1000:kai:/home/linuxidc:/bin/bash 

this from 1000 to 0.

Then after I restart only can login as a guest. No default username in the list.
Please help get the default username back.

Thomas
  • 6,433

1 Answers1

3

Without booting to a LiveUSB or LiveCD/DVD, we can actually borrow some of the steps from this answer on resetting a lost password to get to a recovery console, and then make changes to the system and reboot afterwards.

To summarize the steps (everything from 1 to 4 is from the other question; 5 and 6 are the different steps to do):

(1) Boot up the system, and after you see the BIOS screen press and hold "Shift" - you'll get the GRUB prompt.

(2) Use the 'recovery mode' option for your kernel - if it doesn't show up it's probably under the section for "Other Ubuntu versions" or one of the other items on Grub.

(3) Once in recovery mode, select the 'root' option by using the down arrow on your keyboard, and then hit Enter. You'll end up with a command line prompt for the root user.

(4) Remount your system as read/write with this command: mount -o remount,rw /

(5) Edit your /etc/passwd file with nano (use this command: nano /etc/passwd). Once you've edited the specific line for your user and reset it to 1000 for the UID and GID, hit Ctrl+O, then hit Enter, and then Ctrl+X.

(6) You should now be at the root terminal prompt again. Reboot with shutdown -r now or reboot.

You should then be able to login again, and have fixed your blunder. Don't go messing with your UID or GID, because setting yourself to 0 will break things and is horribly insecure and should never be done. (The 0 UID is for root, and root alone - DO NOT USE IT FOR ANY OTHER USER!)

Thomas Ward
  • 78,878