Linux: Find Out Apache User Name

Posted on in Categories , , , , , , last updated March 31, 2017

How do I find out my Apache web server username under Linux operating system or CentOS Linux server using the command line?

There are various methods to find out your Apache web-server user or group name who is running httpd server on Linux operating system.

lsof command

Run the following command:

lsof -i
lsof -i | less
lsof -i | grep :http

Sample outputs:

apache2   4122             root    4u  IPv6  32570      0t0  TCP *:http (LISTEN)
apache2   4125         www-data    4u  IPv6  32570      0t0  TCP *:http (LISTEN)
apache2   4126         www-data    4u  IPv6  32570      0t0  TCP *:http (LISTEN)
apache2   4127         www-data    4u  IPv6  32570      0t0  TCP *:http (LISTEN)
apache2   4128         www-data    4u  IPv6  32570      0t0  TCP *:http (LISTEN)
apache2   4129         www-data    4u  IPv6  32570      0t0  TCP *:http (LISTEN)

Where,

  1. apache2 (1st column) – Apache service / server name
  2. 4122 (2nd column) – Apache server PID
  3. www-data (3rd column) – Apache server username for PID. This gives you apache username.

httpd.conf file

Another method is to go through config file httpd.conf and find out user and group name:

egrep -iw --color=auto 'user|group' /etc/httpd/conf/httpd.conf
egrep -iw --color=auto '^user|^group' /etc/httpd/conf/httpd.conf

Sample oututs:

User apache
Group apache

ps and grep command

Type the following command:
$ ps aux | egrep '([a|A]pache|[h|H]ttpd)'
OR
$ ps aux | egrep --color '([a|A]pache|[h|H]ttpd)'
Sample outputs:

Fig.01: Finding out what user Apache is running as using ps command
Fig.01: Finding out what user Apache is running as using ps command

From the above output it is clear that Apache2 is running as www-data user on my Debian Linux 8.x server. You can just grab user name with the following bash kung-fu:

ps aux | egrep '([a|A]pache|[h|H]ttpd)' | awk '{ print $1}' | uniq | tail -1

Sample outputs:

www-data

Using apachctl command for finding out what user Apache is running as?

Type the following command
apachectl -S
Sample outputs:

VirtualHost configuration:
*:80                   nas01.nixcraft.net.in (/etc/apache2/sites-enabled/000-default.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/lock/apache2" mechanism=fcntl 
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex proxy: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

2 comment

Leave a Comment