0

I was trying something and execute the below command

sudo mv /etc/passwd /etc/passwd.bak

Now I am getting the below error whenever I am trying to run sudo

sudo: you do not exist in the passwd database

I am not an expert in Linux stuff. Anyone has any idea how can I recover it?

1 Answer 1

1
  1. Boot a live Linux that will give you ability to act as root. (Alternatively pass init=/bin/bash in your current bootloader to boot your current Linux to an elevated shell.)

  2. Mount the filesystem holding the troublesome file. Example:

    mount /dev/sdb2 /mnt
    

    You need to know which device to mount; helpful commands: lsblk, fdisk -l. This step will be more complex if you're using LVM, encryption and/or such.

  3. Rename the file back. Example:

    mv /mnt/etc/passwd.bak /mnt/etc/passwd
    
  4. Unmount the filesystem, this should sync the change. Example:

    umount /mnt
    
  5. Reboot; boot the fixed OS normally.

1
  • Alternatively, couldn't the OP append 1 to the boot command (in grub?) so that it boots to single user run level ... and then mv the passwd file back?
    – rickhg12hs
    Aug 6, 2020 at 20:46

You must log in to answer this question.

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