Saturday, February 23, 2013

Does sudo -u work in Mountain Lion?

This is a weird one.

According to what I read online and in the Man pages, I should also be able to do something like this (where Fred is Admin account):
sudo -u Fred ls
That should ask for Fred's password then execute ls with Fred's privileges.

Except it doesn't. It runs against my non-admin account and fails. As though it were ignoring the -u flag. Instead I have to run
su Fred
to execute as Fred, then run sudo.

I can't find anyone else who complains about this, so I assume I'm doing something wrong.
Note to test this you have to run from a non-admin account.

Update 8/23/2016: I can't get sudo to work at all in El Capitan for a non-admin users. Says: "error retrieving current directory: getcwd: cannot access parent directories: Permission denied."


openid said...

My understanding is that if the user you are trying to run sudo as is not in the sudoers file (admins are in there by default on OS X), then I don't think any sudo command will work at all.

openid said...

This openid login thing isn't working the way it used to... weird.