I was working on some SFTP via filezilla to allow download and reupload of some file I took owner ship via ROOT and chown -R 'myusername' /etc and chmod 777 my user account for -R /etc

Now I got timed out and tried to login to root again and it gives me error sudo: /etc/sudoers is owned by uid 1000, should be 0 sudo: no valid sudoers sources found, quitting sudo: unable to initialize policy plugin I have access to the /etc and 777 on all the files and also can access them via FTP so please suggest how to restore access to the root account Also the root as no password at this time so i cant run the general pkexec or visudo commands.

Please suggest a solution and also if there is a way to manually reset the /etc/shadow or passwd files.

I think it is slightly different than the indicated duplicate Becuse i changed the permissions on the files too. Also if i run chown root:root /etc/ it will give me chown root:root /etc chown: changing ownership of '/etc': Operation not permitted

Thank You!

marked as duplicate by muru, karel, Eric Carvalho, Pilot6, MadMike Jun 9 '18 at 12:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • also i ran ls -al /etc | grep sudoers THis returned : -rwxrwxrwx 1 offc offc 755 Jul 4 2017 sudoers drwxrwxrwx 2 offc root 4096 Jun 8 01:22 sudoers.d – Franc Giovanni Jun 8 '18 at 2:23
  • ls -al /etc/sudoers.d returned drwxrwxrwx 2 offc root 4096 Jun 8 01:22 . drwxrwxrwx 109 offc root 4096 Jun 8 02:14 .. -rwxrwxrwx 1 offc root 126 Mar 4 01:50 90-cloud-init-users -rwxrwxrwx 1 offc root 958 Mar 30 2016 README -r--r----- 1 root root 47 Jun 8 01:32 waagent – Franc Giovanni Jun 8 '18 at 2:29

Probably the easiest way to fix this will require a reboot. Here's two solutions that come to mind:

  1. Boot ubuntu livecd and mount the device that has /etc. Then do a chown -R root:root /path/to/etc.

  2. If yo don't have a livecd or way to boot the livecd, try this. Reboot your computer. When you get to the grub prompt edit the boot entry on the line with the linux command to append break=bottom (this may require you hold the <shift> key while booting). Then hit the <F10> key to boot the modified boot entry. This will give you a root shell in the initrd where the rootfs and /dev is mounted. Next do /bin/chroot /root to chroot into the rootfs. If /etc is not on the rootfs, then mount the device at say /tmp. Then you can do chown -R root:root /path/to/etc. If you mounted /etc, be sure to unmount it when done, and then exit the chroot and the initrd shell to continue booting normally. Your /etc files should have all root permission.

  • Thank you for your prompt response This is on a Azure VM I am not sure how we can reset it upon reboot – Franc Giovanni Jun 8 '18 at 4:47
  • I have no experience with Azure, but some googling suggests that you can create a new temporary VM that runs the livecd. Then attach the harddrive with the bad /etc and use method 1. Method 2 might be able to be used by attaching to the VM via a virtual serial port. – crass Jun 8 '18 at 5:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.