3

My OS is Ubuntu 12.10, and my account is called acgtyrant, and its UID is 1000. For the need of researching, I changed my UID from 1000 to 1010 in /etc/passwd, and then I found my files' master changed to a number:1000, which prove my suppose. But when I try to change my UID back, I found I can't edit the passwd file any more! Because when I try to run sudo vim /etc/passwd, the Bash told me sudo: unknown uid 1000: who are you?.

So how to solve it? Acctually I am a chinese student, so forgive my poor English please.

BuZZ-dEE
  • 13,993
  • 18
  • 63
  • 80
acgtyrant
  • 185
  • 2
  • 2
  • 6
  • I haven't got a LiveCD to hand to test this - but suggest that you boot from a LiveCD and choose to 'test Ubuntu' rather than install it. Then open a terminal and edit the passwd file. – Clive van Hilten Feb 27 '13 at 08:07

3 Answers3

4

Press shift during boot then select recovery and drop to a root shell.

Now mount the file system read-write

mount -o rw,remount /

So far you are following the instructions on how to reset your password from here

Finally don't change your password but simply edit the file

vipw

To edit /etc/passwd or vipw -s to edit /etc/shadow

Similarly use vigr to edit /etc/group and vigr -s to edit /etc/gshadow

Standard editors such as nano and vim do not check the file structure before saving so may make problems worse.

reboot and all should be OK

Warren Hill
  • 21,832
  • 28
  • 67
  • 88
  • 1
    Cautionary note: use `vipw` on a live system. For the recovery system this method may be just alright. Use `vigr` for the `group` file. Use the option `-s` to edit the respective shadow files. – 0xC0000022L Feb 27 '13 at 13:53
  • @0xC0000022L Thanks for pointing this out. I was not aware of the vipw command but just looked it up. Its safer. – Warren Hill Feb 27 '13 at 14:04
  • @acgtyrant If this solved your problem please accept the answer. It makes it easier for others with a similar problem to find. It also doesn't hurt my reputation score :-D. – Warren Hill Mar 01 '13 at 10:59
  • @Warren Hill As your wish. – acgtyrant Mar 05 '13 at 10:59
  • Thanks a lot! After booting in safe mode, I was simply able to edit /etc/passwd again with plain ol' `vi`, which is what caused this problem in the first place :) – NonameSL Sep 19 '20 at 17:04
2

Maybe try something like this:

usermod -u UID_number username
Ntc
  • 1,294
  • 3
  • 10
  • 10
1

two things: have a "backup" user

already have a root password setup $ sudo passwd root

login with backup user account, then.

su

now as root, nano /etc/passwd change your uid and gid back to original, most likely 1000:1000

user735853
  • 11
  • 1