I had updated my sudoers file to make some command run with root privileges by default without the need to use sudo and entering my password. I used the command sudo visudo and added this line to it:

<my_username> ALL=(ALL) NOPASSWD: <path/to/command --arguments>

But whenever I update macOS, my sudoers file is reset to its defaults. A folder named Relocated Items appears on my Desktop and it always includes the following file: /Users/Shared/Relocated Items/Configuration/private/etc/sudoers. This happens on macOS Catalina, and also on macOS Big Sur.

Screen shot from Relocated Items folder

How can I prevent the sudoers file resetting to its defaults with every macOS update?

  • 1
    How do you update macOS? Just by running the Installer from Finder or by doing a full install via Recovery?
    – nohillside
    Aug 5, 2020 at 7:11
  • 3
    Don't modify /etc/sudoers, but add a file to /etc/sudoers.d instead. sudoers is configured to read files in that path and apply any rules defined in them. I'd recommend that you name files in /etc/sudoers.d after the user they apply to, for example, if your username is behdad, /etc/sudoers.d/behdad. You can create the file with sudo visudo -f /etc/sudoers.d/behdad.
    – jaume
    Aug 5, 2020 at 7:32
  • 1
    What @nohillside said. I update all the time without having sudoers touched in any way
    – Allan
    Aug 5, 2020 at 7:56
  • @nohillside I update macOS using the .pkg file downloaded from Apple Support website. I sometimes update using Software Update in System Preferences. In short, I don't do a clean install.
    – Behdad
    Aug 8, 2020 at 15:32
  • 1
    Interesting. I‘ve been doing this for years and never had an issue with the sudoers file. But the answer below offers a safe way for custom modifications, I might change to that as well.
    – nohillside
    Aug 8, 2020 at 16:19

1 Answer 1


Modifying most of the files in /etc leaves you open to them being replaced during OS updates. That's why most of the ones you usually need to change have the facility to add files to a directory instead.

If you look in /etc you will see a directory called sudoers.d and the last line of the sudoers file is #includedir /private/etc/sudoers.d so any file of commands you put into the directory will be read. Files in the directory will not be overwritten when you update.

You may notice directories with similar names in /etc that fill the same function for other parts of the system.

  • 1
    Thanks for your answer. So my understanding is that any valid text file in the sudoers.d folder (by visudo standards) is inserted at the place of #includedir in the /etc/sudoers file, right?
    – Behdad
    Aug 8, 2020 at 15:30
  • 1
    Correct @Behdad Aug 11, 2020 at 3:42

You must log in to answer this question.

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