Linux: Find Out Apache User Name

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

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
🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
2 comments… add one
  • raice Oct 23, 2013 @ 7:04

    thank you! This was the final step I needed

  • Olubodun Jun 12, 2017 @ 9:50

    You are really doing a great job here man, thumbs up to you

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.