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

31

13

How can I check the user and group for the nginx daemon in Ubuntu?

Or what's the syntax to find the user and group for a deamon running in Ubuntu?

Prakash Moturu

Posted 2012-03-09T13:07:22.183

Reputation: 335

1I don't understand the question. You seem to have found out the user and group for the nginx daemon just fine. – Der Hochstapler – 2012-03-09T13:12:04.593

how to find the user and group for the nginx deamon – Prakash Moturu – 2012-03-09T13:13:09.867

Answers

41

Simply use ps while it is running:

oliver@ubuntuServer:~$ ps aux|grep nginx|grep -v grep
root     17119  0.0  0.1  57492  1156 ?        Ss   14:22   0:00 nginx: master process /usr/sbin/nginx
www-data 17120  0.0  0.1  57804  1572 ?        S    14:22   0:00 nginx: worker process
www-data 17121  0.0  0.1  57804  1572 ?        S    14:22   0:00 nginx: worker process
www-data 17122  0.0  0.1  57804  1572 ?        S    14:22   0:00 nginx: worker process
www-data 17123  0.0  0.1  57804  1572 ?        S    14:22   0:00 nginx: worker process

As you can see in the first column, the initial nginx master process is started with the root user account. This process will spawn the workers under the www-data user account. This would be the one you care about.

If nginx isn't running, you can just as well pull the information from the configuration file like so:

oliver@ubuntuServer:~$ grep user /etc/nginx/nginx.conf
user www-data;

Der Hochstapler

Posted 2012-03-09T13:07:22.183

Reputation: 77 228

So if I want to restart nginx in this case, I need to do it with root user or www-data user? Sometimes I get a open() "/run/nginx.pid" failed (13: Permission denied)... – Augustin Riedinger – 2016-04-21T13:19:55.373

@AugustinRiedinger You should probably use sudo service nginx restart – Der Hochstapler – 2016-04-21T14:08:36.063

17

To answer the "and group" part of the question for the running process, use the supgrp (names of supplementary groups) format specifier too. Try:

 ps -eo pid,comm,euser,supgrp | grep nginx

jwd630

Posted 2012-03-09T13:07:22.183

Reputation: 281

1

ps -eo user,comm | grep nginx will give you the user who running nginx.

top or htop can be used to find the user of a process, too.

then you could find the group of a user use: groups USERNAME

Mengdi Gao

Posted 2012-03-09T13:07:22.183

Reputation: 1 316

1Note, however, that effective and supplementary groups of a running process may not match these of user account for various reasons. Given CAP_SETGID capability (which root usually has), process can modify both effective GID and supplementary group list. Because of this, ps solution is better. – WGH – 2016-06-07T20:37:01.883

how to delete the userroot nginx www-data nginx www-data nginx www-data nginx www-data nginx – Prakash Moturu – 2012-03-09T13:21:40.777

why you want to delete user www-data? running web server daemon with this user is expected result. ok, you can delete it uses userdel command. – Mengdi Gao – 2012-03-09T13:27:33.797

1

I always do 'ps aux | grep whatever' but I'm not an admin. If the above is right and 'ps' tells you what you need to know, do that. Then you have to do 'kill ###' not 'kill name' (### meaning eg 17119 from above). Assuming you want to kill it. It's daemon, not deamon, btw.

conspiritech

Posted 2012-03-09T13:07:22.183

Reputation: 389