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
  • 1
    Boot a 'live' system, mount & navigate to that directory & fix from there. – guiverc Apr 20 '20 at 02:40
  • how do i boot a live system?' – Tryin to learn Apr 20 '20 at 05:13
  • Insert Ubuntu install media into thumb-drive, and boot the device. I would check the media is flawless first, but I don't take risks. Refer https://discourse.ubuntu.com/t/try-ubuntu-before-you-install-it/14014 (it's just booting your install media & using the Try Ubuntu option). You haven't provided release details (most require the '*Check disk for defects*' to be manually started, latest does it automatically) – guiverc Apr 20 '20 at 05:16
  • 1
    If there were any files in /etc that weren't owned by root (I don't know if there are or not) you may encounter future difficulties. – Organic Marble Apr 20 '20 at 17:16
  • 2
    Does this answer your question? [Set myself as owner of /etc with chown command now getting all kinds of errors](https://askubuntu.com/questions/300641/set-myself-as-owner-of-etc-with-chown-command-now-getting-all-kinds-of-errors) – muru Apr 21 '20 at 15:43

3 Answers3

3

Try this command

pkexec chown root:root /etc/sudoers /etc/sudoers.d -R
berkancetin
  • 248
  • 2
  • 7
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,279
  • 9
  • 31
  • 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
  • 293,910
  • 41
  • 570
  • 710