Search code examples
macossudo

sudo on Mac: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set


I accidentally ‘ruined’ the filesystem’s permission structure by running chown Andy:staff /usr/bin on my Mac. Now sudoraises an error: sudo: /usr/bin/sudo must be owned by uid 0 and have the setui bit set

I tried the most popular method online: chown root:root /usr/bin/sudo && chmod 4755 /usr/bin/sudo But the shell said that root is an illegal user group. I do NOT want to reinstall the OS, so is there a way to fix this? Can anybody help me? Thanks!


Solution

  • From a recovery console, chown 0:0 /usr/bin/sudo && chmod 4555 /usr/bin/sudo

    Often, sudo is owned by group wheel. On Macs, I think it's staff. It doesn't matter, though, because group ID 0 (the one that's after the colon) can be specified even without knowing the name.

    But seriously, your filesystem is riskily and dangerously borked. You seriously should reinstall. (The reason the contents of /usr/bin aren't owned by users is so that any software or malware that runs as that user can't write to those programs, so that they can be relied on to operate the way they're supposed to. You're safer if you reinstall.)