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,223

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
  • 74,764
  • Hi man, can you please tell me how to write the order to Remount your system as read/write. And how to Edit your /etc/passwd file with nano.I am a new user of ubuntu. thanks a lot – kindlong Sep 23 '17 at 14:31
  • @kindlong I already do - it's the command at the end of the line after the period. – Thomas Ward Sep 23 '17 at 14:31
  • Also good to point out that uid 0 is reserved for root only. You can't use that uid again. – xR34P3Rx Sep 23 '17 at 14:40
  • @kindlong You're welcome! Feel free to upvote my answer and accept it if it solved your problem! (That way the system knows the question has been resolved) – Thomas Ward Sep 23 '17 at 15:01
  • @kindlong if the answer solved your problem kindly accept it with the accept button to the left of the answer – George Udosen Sep 23 '17 at 17:00