Determine a daemon's user and group in Ubuntu

The Goal

To find the user and group under which a daemon runs in Ubuntu. You would need this information for a myriad of reasons, the most common reason I require this information is to set permissions on files and folders that the daemon requires access to.

The Process

To obtain the user and group under which nginx run run the following command:
# ps aux|grep nginx|grep -v grep
root     30635  0.0  0.0  96136  2908 ?        Ss   19:33   0:00 nginx: master process /usr/sbin/nginx
www-data 30636  0.0  0.1  96764  5256 ?        S    19:33   0:00 nginx: worker process
www-data 30637  0.0  0.0  96492  3632 ?        S    19:33   0:00 nginx: worker process
www-data 30639  0.0  0.0  96492  3632 ?        S    19:33   0:00 nginx: worker process
www-data 30640  0.0  0.0  96492  3632 ?        S    19:33   0:00 nginx: worker process

The first column shows that the nginx master process is started with the root user account. This process spawns the worker processes which run under the context  of the www-data user account.

You can also grep the nginx.conf file to get this information:
# grep user /etc/nginx/nginx.conf
user www-data;

You can see that the output confirms that the www-data is the user account under which nginx runs.

One more command to get the same information:

# ps -eo pid,comm,euser,supgrp | grep nginx
30635 nginx           root     root
30636 nginx           www-data www-data
30637 nginx           www-data www-data
30639 nginx           www-data www-data
30640 nginx           www-data www-data

I run these commands quite often when configuring Linux systems at work and also when working on home IT projects.

Reference(s)

How to determine the user and group of a deamon in Ubuntu?

Comments