15

Prior to OS X Catalina I could add a user to the sudoers by editing /etc/sudoers with an admin account.

With OS X Catalina, I can no longer do this as it seems that Catalina moved to a read-only root filesystem and so /etc/sudoers cannot be edited.

According to this official Apple User Guide, it appears that the sudoers file is now located at /private/etc/sudoers, but I am still unable to edit this file with an admin account.

What is the correct way to grant a user sudouers access in Catalina?

6
  • 2
    What do you mean by "can‘t be edited"? Doesn‘t sudo visudo work on Catalina any longer? What error do you get if you run this?
    – nohillside
    Commented Apr 21, 2020 at 5:03
  • Why was this down voted? It's a valid question any normal Mac user could possibly have. +1
    – Allan
    Commented Oct 12, 2020 at 15:31
  • @Allan The user claims that the behaviour changed with Catalina (which it didn't), and doesn't show the actual command used. So it's hard to see what exactly went wrong. The answer is good though, and of general use.
    – nohillside
    Commented Oct 12, 2020 at 17:02
  • 1
    It not clear and he’s mistaken, yes @nohillside, but down vote worthy? That I disagree with. We see way more question with less detail get flagged/closed, but not down voted. I just think there are some here too eager to down vote and I believe it’s off putting to new(er) users.
    – Allan
    Commented Oct 12, 2020 at 18:20
  • @Allan I share the feelings regarding the apparent focus on downvote (and now, I didn't downvote, but maybe the two users who upvoted my initial comment did).
    – nohillside
    Commented Oct 12, 2020 at 18:46

2 Answers 2

31

It turns out that even an admin user needs to use sudo to edit the sudoers file at /private/etc/sudoers so the following did the trick to open the file for edit:

$ sudo visudo /private/etc/sudoers

As usual, a user can be added to the list of sudoers by adding a line such as this:

username ALL=(ALL) ALL
4
  • Given this answers the question you can accept your own answer to mark it as solved.
    – Alex
    Commented Apr 21, 2020 at 4:35
  • 1
    ...was this not the case prior to Catalina? That’s odd! O_O Commented Oct 12, 2020 at 0:37
  • In Debian as an alternative you can add <username> to the sudo group with useradd. This does not seem to work on Unix/Mac, sudo is not in groups.
    – Timo
    Commented Apr 2, 2022 at 10:44
  • The sudoers in /etc and /private/etc seem identical, no difference with the diff tool.
    – Timo
    Commented Apr 2, 2022 at 13:04
9

If you want to be able to use sudo without typing a password:

sudo visudo

And add:

username        ALL = (ALL) NOPASSWD:ALL

Adding this gives any commands, including scripts, you execute in the terminal ability to run sudo without a prompt, which exposes you to increased risk of exploitation. Use with caution.

5
  • I advise extreme caution when doing this. This is horribly insecure because you are literally giving admin rights with no authentication.
    – Allan
    Commented Oct 12, 2020 at 3:43
  • Right. Use with care, especially when executing scripts. But I think giving people options is useful, rather than not useful, so the downvote was unjustified (whoever it was). Commented Oct 12, 2020 at 14:30
  • 1
    Between you, me and the lamp post, the excessive down votes by an unknown few in the community is irksome. I don't down vote unless egregious - like outright wrong and/or dangerous. This answer could benefit from text highlighting the potential risks, but IMO, it's not down vote worthy. However, +1 to offset.
    – Allan
    Commented Oct 12, 2020 at 15:28
  • 1
    Alright, I've added a warning. Commented Oct 12, 2020 at 15:39
  • This is the only solution to avoid password prompt. Adding the user to admin or wheel does not help.
    – Timo
    Commented Apr 2, 2022 at 12:53

You must log in to answer this question.

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