Sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set [OSX]

macos

So i was in teamviewer with my newbie developer who was trying to install some node js packages, npm install. he was having some issues with some libraries, he changed the permission of my mac sudo.

All the solutions I'm searching online are mostly related to ubuntu where they are suggesting this 1. Log out as the current user, then log back in as root. 2. Execute chown root:root /usr/bin/sudo && chmod 4755 /usr/bin/sudo 3. Log out as root, then log back in as the current user.

which simply doesn't work in mac. any solution other than re-installing?

Best Answer

Did you disable system integrity protection? If enabled, it's should've prevented you from messing with /usr/bin/sudo (and will also prevent fixing it except by reinstalling). I strongly recommend leaving SIP turned on; I can't think of any good reason you'd need to bypass it for a node.js setup (and plenty of bad reasons). You'll need to have it off to fix /usr/bin/sudo (and undo any other normally-forbidden changes you made), but I recommend turning it back on after you fix that.

You should be able to fix sudo with /Applications/Utilities/Script\ Editor.app. Create a new "document" (script), and enter this:

do shell script "chown root:wheel /usr/bin/sudo; chmod 4511 /usr/bin/sudo" with administrator privileges

...then click Run in the toolbar. It'll prompt for your admin password, and (if all goes well) will set the ownership and permissions back to normal.

Related Question