8

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.

user379468
  • 181
  • 1
  • 1
  • 2

4 Answers4

12
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>
Grant
  • 17,859
  • 14
  • 72
  • 103
6

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.

MDMarra
  • 100,734
  • 32
  • 197
  • 329
  • 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= --inh=cap_net_bind_service` or the setup described at http://wiki.apache.org/httpd/NonRootPortBinding should work. – Gerald Combs Nov 08 '12 at 19:05
  • @GeraldCombs very true indeed. Updated to qualify the restriction a little more generally. – MDMarra Nov 08 '12 at 19:07
1

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

James
  • 128
  • 3
  • 15
0

You can run as user using -u. This will not open programs as you are "logged in" as that user, so you will have to specify the whole path.

Example

jupyter notebook

Becomes this, if the normal user is Ubuntu:

sudo -u ubuntu /home/ubuntu/.local/bin/jupyter notebook

Find the location of Jupyter:

which jupyter
#Result: /home/ubuntu/.local/bin/jupyter
Punnerud
  • 101
  • 2