Skip to main content
edited tags
Link
nohillside
  • 104.5k
  • 42
  • 222
  • 275
Became Hot Network Question
Source Link
luckman212
  • 3.6k
  • 3
  • 29
  • 41

sudo / sudoers on macOS: regex not working but wildcards/globs are

System: macOS 14.6.1, M2 MacBook Air

I'm trying to use a regex pattern match in my suoders file. According to the man sudoers manpage as well as the online docs, that should be supported with sudo v1.9.10 or higher.

Running sudo --version on my system yields 1.9.13p2 so, should be ok there. Also, running the syntax check command below indicates that the file is being parsed successfully:

$ sudo visudo -c
/etc/sudoers: parsed OK

Here's an example line from my sudoers file which DOESN'T work:

luke  ALL=(ALL) NOPASSWD: /bin/launchctl asuser ^[0-9]+$ /usr/sbin/screencapture -D1 -p

And here's are two similar commands using regular wildcards/globs that DO work:

luke  ALL=(ALL) NOPASSWD: /bin/launchctl asuser ??? /usr/sbin/screencapture -D1 -p
luke  ALL=(ALL) NOPASSWD: /bin/launchctl asuser * /usr/sbin/screencapture -D1 -p

I've done as much debugging as I can but remain flummoxed. Anyone got thoughts?