7
4
I have some problems understanding sudo
. I am logged in on a terminal as an non-admin/non-root user. This "normal" user is not in the sudoers file (and shouldnt be, in my opinion).
Now I try to execute a command that needs admin/root privileges and also access to directories of my normal user – therefore I am not able
to simply su
into an admin or root user.
In my understanding sudo -u root
should do the trick – however
it doesn't accept the password for root
(or admin if I try with my normal
admin user). It only accepts the password of the "normal" user which seems
to indicate that the -u username
option doesn't work the way I expect it to
work.
My expectation is that sudo -u root some_command
executes some_command
with the privileges of root and therefore it asks also for the password of root.
Obviously not.
TL;DR: How do I execute any command that requires admin privileges AND has access to the files of the "logged in (normal) user" without adding the normal user to the sudoers file?
I have enabled the root user under Mac OS X 10.7.
Sudo doesn't always require password. Calling sudo updates timestamp and allows to run sudo without giving password for a couple of minutes (this varies between OSes). – solgar – 2017-01-10T14:44:06.677
Hi, thanks for the answer.
I am not sure if I do understand you correct. As far as I can tell if I su into root I will loose access to the files of the initially logged in user - however this is exactly what I need.
Let me be more concrete: I am using npm (node package manager) to install a self written package into the global package registry on my machine. For this to do i need access to "/usr/local/lib/node_modules/..." which the loggedin user (let say "robert") doesnt have. The package resides in "~/my_package". su doesnt help as it has no access to this folder (next comment) – robertj – 2011-09-13T21:29:25.227
and adding "robert" to the sudoers file seems like total overkill to me. – robertj – 2011-09-13T21:31:12.090
@robertj Root can access all users' files. So if you
su
without specifying a user, you're good. – Daniel Beck – 2011-09-14T08:03:21.360I'm running OS X 10.8.3 and 'su -c' is not recognized as a valid option for me...: "su: illegal option -- c" – Motsel – 2013-05-23T07:23:35.793
@Daps0l Fixed, try the changed command. – Daniel Beck – 2013-05-23T17:40:29.830
Thanks! Is it also possible to combine this with sudo AND only have to type in the (same) password 1 time? Something like this: su username -c 'sudo some_cmd' – Motsel – 2013-05-24T12:18:55.327
@Daps0l Not that I know of, except by allowing username to run
some_cmd
as root all the time (look forNOPASSWD
inman sudoers
). (If the down vote I received for this answer is yours, I'd appreciate if you could undo that) – Daniel Beck – 2013-05-24T13:39:05.127