Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm using drupal and Aegir. Aegir automates many tasks of site creation. Aegir has control of Apache, I'm logen in as root, and I want to restart the Apache server, but I want to do it on Aegirs behalf. Unfortunately I do not know the Aegir password, so basically I'm wondering how to sudo something as another user.

share|improve this question
add comment

3 Answers

sudo -u <username> <command>

sudo accepts a user parameter, which will run it as that user.

Alternatively, since you are root:

su <username> -c <command>
share|improve this answer
add comment

su aegir is what you're looking for, assuming the username is aegir. man su will give you more info on the su command.

That user likely won't be able to actually restart Apache if it's running on port 80, unless specifically configured to be allowed to do so. By default, root is the only user that can bind a service to a low port number.

share|improve this answer
2  
You don't need root if either your process or the httpd executable have the cap_net_bind_service capability. Something like capsh --uid=<aegir_uid> --inh=cap_net_bind_service or the setup described at wiki.apache.org/httpd/NonRootPortBinding should work. –  Gerald Combs Nov 8 '12 at 19:05
    
@GeraldCombs very true indeed. Updated to qualify the restriction a little more generally. –  MDMarra Nov 8 '12 at 19:07
add comment

You should be able to do the following

runuser -l <username> -c <command>

e.g

runuser -l Aegir -c service httpd restart

But if you are root you can just su to the user with out a password.

su -l Ageir

J

share|improve this answer
add comment

Your Answer

 
discard

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.