35

How can I fix the following error with sudo?

/etc$ sudo
sudo: /etc/sudoers.d is world writable
usage: sudo [-D level] -h | -K | -k | -V
usage: sudo -v [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-u user
            name|#uid]
usage: sudo -l[l] [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-U user
            name] [-u user name|#uid] [-g groupname|#gid] [command]
usage: sudo [-AbEHknPS] [-r role] [-t type] [-C fd] [-D level] [-g
            groupname|#gid] [-p prompt] [-u user name|#uid] [-g groupname|#gid]
            [VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-r role] [-t type] [-C fd] [-D level] [-g
            groupname|#gid] [-p prompt] [-u user name|#uid] file ...
4
  • looks like changing permissions on /etc is a bad thing serverfault.com/questions/364677/why-is-chmod-r-777-destructive serverfault.com/questions/221447/…
    – zadubz
    Dec 29, 2014 at 0:00
  • try pkexec chmod 555 /etc/sudoers
    – user573993
    Jul 29, 2016 at 10:52
  • 1
    If "pkexec chmod 555 /etc/sudoers.d" does not work for you due to pkexec having a permission promblem, get the PID of the shell you are running pkexec in suing "echo $$" then log in another window and do a " pkttyagent --process XXX" with the XXX replaced with the PID of the other shell. Once that is running, retry the pkexec in other shell Feb 29, 2020 at 23:59
  • Thank you, @CullenFluffyJennings. That worked for me. Keep safe...
    – Jonathan
    Apr 19, 2021 at 13:17

3 Answers 3

48

Run pkexec chmod 0755 /etc/sudoers.d

pkexec will use a different method of using root permissions, bypassing the issue.
And the chmod will fix the permissions.

5
  • 3
    did not help :( Oct 15, 2014 at 14:34
  • @demure , which password i have to use? Oct 12, 2016 at 14:34
  • I have tried pkexec chmod 0755 /etc Feb 21, 2017 at 14:05
  • 1
    Error executing command as another user: Not authorized if I could switch to the root user I wouldn't need to do this in the first place... Mar 4, 2017 at 0:14
  • This will not work if you are not running a graphical environment Feb 29, 2020 at 23:53
40

Run this 2 commands with (555) permissions:

pkexec chmod 555 /etc/sudoers
pkexec chmod 555 /etc/sudoers.d/README
7
  • Worked for me. Fantastic! Jul 29, 2017 at 5:54
  • worked for me great Oct 26, 2017 at 9:29
  • its worked for me :) May 28, 2019 at 5:34
  • 1
    works great on LTS 16.04
    – cvocvo
    Aug 8, 2019 at 16:49
  • This will not work if you are not running a graphical environment Feb 29, 2020 at 23:53
12

Did you try going into recovery mode and switching the permissions back to 775 for sudoers? I tried it and it worked.

1) Get into Ubuntu Recovery

2) Do mount -rw -o remount /

3) Then chmod 775 -R /etc/sudoers and chmod 775 -R /etc/sudoers.d/.

This time it should work.

4) Then do a sudo apt-get install of any package to test before you leave recovery mode. Late reply but I encountered the issue recently and tried this. It worked fine atleast for the world writable issue.

4
  • What do you mean by "Get into Ubuntu Recovery"? Once I'm at the recovery menu do I select root? That gets me to a root shell that is in recovery but this doesn't seem to work. Mar 4, 2017 at 0:34
  • I got sudo to work by using live USB, mounting in /mnt, and chroot /mnt
    – qwr
    Aug 24, 2018 at 23:10
  • thanks Gdcrocx. its work
    – Imon
    Dec 14, 2021 at 11:46
  • after I execute the commands you wrote in recovery mode and restart, they are no more valid.
    – Asqan
    Sep 11, 2022 at 10:58

You must log in to answer this question.

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