Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 2 user accounts, foo and bar

I want to allow user foo to execute commands as root and any other user ie:

sudo su root -c'./run-my-script'

sudo su bar -c'./another-script'

sudo su another -c'./yet-another-script

I also want to allow user bar to execute commands as other user but only a subset and not root ie:

sudo su bar -c'./run-my-script'

but not

sudo su root -c'./run-my-script'

Is this possible ?

share|improve this question

Yes, it's certainly possible.

Firstly you need to fix your usage of sudo, to execute a command as a user other than root (the default) with sudo the syntax is: sudo -u username command

You can then lock down the users whose identity a user can assume via the /etc/sudoers config file, eg a fully privileged user looks like:


Whereas a user with restrictions looks like:

jim ALL=(admin,bill) ALL

Which means if I try and execute a command as a user who isn't in the list I get denied:

jim@mybox:~$ sudo -u nobody whoami
Sorry, user jim is not allowed to execute '/usr/bin/whoami' as nobody on mybox.
share|improve this answer
Thats great thanks. However I would also want to allow a user to su to specific other users also, is that possible? – sleepyjames Jan 17 '11 at 14:22
Read the answer above again? 'admin' and 'bill' are usernames, not groups. – DutchUncle Jan 17 '11 at 16:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.