Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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'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
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

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
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 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

You should be able to do the following

runuser -l <username> -c <command>


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


share|improve this answer

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.