3

I deleted my /etc/passwd with my fat fingers.

I saw that there is a /etc/passwd- that looks like a backup file but I cannot copy it to restore the original one since I can't sudo anymore.

My volume is encrypted.

Is there a way to recover it from the backup copy?

EDIT: After rebooting to apply the fix, the passwd- file was empty...
I should have done a copy of it while it was still possible.
So, am I screwed?

1
  • 2
    Boot from a recovery disk, mount the partition then cp the file. Commented Jan 24, 2022 at 12:54

1 Answer 1

4

Boot with init=/bin/bash at the Grub prompt. Supply the encryption password when prompted. Run the following commands:

mount -o remount,rw /
cp -a /etc/passwd- /etc/passwd
mount -o remount,ro /
reboot

If your system uses SELinux, you may need to run touch /.autorelabel.

Akternatively, boot from a recovery disk, mount the partition then cp the file. – @Bib

5
  • I will do it at the end of my day since now I am still using my active session to work. Is it gonna be fine with the encrypted volume? When you mention boot with init=/bin/bash, can you be more specific? Thanks a lot for the help!
    – zakrapovic
    Commented Jan 24, 2022 at 13:47
  • @zakrapovic See e.g. askubuntu.com/questions/1102836/… for more dtailed instructions to reach a root shell Commented Jan 24, 2022 at 13:49
  • You'll be fine since you're using initrd which will ask for a decryption password and will set up your root partition for you. Commented Jan 24, 2022 at 13:56
  • Your solution should have worked, but after rebooting the passswd- file was empty. I should have copied it. So I don't have anmore any original of the file. Am I screwed for good?
    – zakrapovic
    Commented Jan 24, 2022 at 18:01
  • Please boot into recovery again and post the output of ls -la /etc/passwd* and cat /etc/passwd-. Commented Jan 25, 2022 at 10:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .