How can I run a webserver on boot without root rights (as another user)? I could just add it in rc.local, but it's run under root user.
2 Answers
How can i run a webserver on boot without root rights (as another user)?
Why? What are you trying to achieve?
The first thing Apache does after becoming a daemon and listeing on a port is to setuid to the user defined in the config files - i.e. it does not run with root rights.
It's impossible to start a daemon listening on a port below 1024 unless you are root - but its perfectly possible to start it listening on, say port 8000, and also quite possible to set up iptables to proxy port 80 requests to port 8000 - but only root processes can setuid to a different uid - so you'll need to change your Apache config so that either it doesn't call setuid, or it only calls setuid to the current uid.
If you are concerned about security then there are lots of other things you should consider doing before you try to repair a security hole which is effectively non-existant.
C.
![](../../users/profiles/35483.webp)
- 19,931
- 1
- 29
- 49
Search for the following section in the httpd config file:
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User daemon
Group daemon
and change the 'daemon' user and group to the required user name.
![](../../users/profiles/10206.webp)
- 8,235
- 1
- 30
- 44
![](../../users/profiles/9478.webp)
- 159
- 1
- 1