2

Yesterday I accidentally changed the owner of /etc folder group using this command:

sudo chown -R pts:apache /etc

I did this to upload a file from my end. Later when I tried to change it back to root:root it showed this error:

sudo: /etc/sudo.conf is owned by uid 1001, should be 0
sudo: /etc/sudo.conf is owned by uid 1001, should be 0
sudo: /etc/sudoers is owned by uid 1001, should be 0
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

I can't use sudo anymore because of this.

How do I fix this? Thanks.

plr108
  • 121

3 Answers3

3

Try this command

pkexec chown root:root /etc/sudoers /etc/sudoers.d -R
1

These three methods are working in this case:

  • Boot from LiveCD (Ubuntu installation media with Try Ubuntu without installing option), mount your root partition in liveCD and change owner of /etc folder using it:

    $ sudo mount -t ext4 -o rw /dev/sda1 /mnt
    $ sudo chown -R root:root /mnt/etc
    

    Reboot

  • Or, if you know root's password:

    $ su 
    # chown -R root:root /mnt/etc
    

    Tested both variants and both are working.

  • berkancetin's method also works:

    $ pkexec chown root:root /etc/sudoers /etc/sudoers.d -R
    $ sudo chown -R root:root /etc
    $ ls -ailh / | grep etc
    1046529 drwxr-xr-x 139 root root  12K кві 22 12:38 etc
    

For files and directories that are owned not by root (as Rinzwind mentioned), you could run:

sudo chown root:daemon /etc/at.deny
sudo chown -R root:bind /etc/bind
sudo chown -R root:dip /etc/chatscripts
sudo chown -R root:lp /etc/cups
sudo chown root:shadow /etc/*shadow*
sudo chown -R root:landscape /etc/landscape
sudo chown mpd:audio /etc/mpd.conf
sudo chown -R postgres:postgres /etc/postgresql
sudo chown -R root:dip /etc/ppp
sudo chown -R smmta:smmsp /etc/mail

The list of files and directories in /etc/ owned not by root, you could get from other working ubuntu machine with almost the same configuration.

Gryu
  • 7,559
  • 9
  • 33
  • 52
1

Not all files in /etc are root:root.

You can use the command provided by Gryu or berkancetin but need to change some files:

-rw-r----- 1 root  daemon   144 Oct 21  2013 at.deny
drwxr-sr-x 2 smmta smmsp   4096 Apr  1  2016 mail  
-rw-r----- 1 root  shadow  1110 Aug 10  2018 gshadow 
drwxr-s--- 2 root  dip     4096 Apr 28  2019 chatscripts
-rw-r----- 1 root  shadow  1462 Aug  5  2019 shadow

There can be more (as this list is from one of my machines)

Rinzwind
  • 299,756