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 Answers1

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

  • 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 Jan 24 '22 at 13:47
  • @zakrapovic See e.g. https://askubuntu.com/questions/1102836/after-accidentally-renaming-etc-how-do-i-rename-it-back/1102854#1102854 for more dtailed instructions to reach a root shell – Gilles 'SO- stop being evil' Jan 24 '22 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. – Artem S. Tashkinov Jan 24 '22 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 Jan 24 '22 at 18:01
  • Please boot into recovery again and post the output of ls -la /etc/passwd* and cat /etc/passwd-. – Artem S. Tashkinov Jan 25 '22 at 10:46