检查执行 apache 服务器的用户

检查执行 apache 服务器的用户
root@ip-172-31-38-0:/var/www# ps aux | egrep '(apache|httpd)'
root      1086  0.0  0.3  88480  3160 ?        Ss   Mar08   0:09 /usr/sbin/apache2 -k start
www-data  1089  0.0  0.8 445500  8840 ?        Sl   Mar08   0:56 /usr/sbin/apache2 -k start
www-data  1090  0.0  0.8 445564  8832 ?        Sl   Mar08   0:56 /usr/sbin/apache2 -k start
root     12072  0.0  0.0   8160   932 pts/0    S+   19:20   0:00 egrep --color=auto (apache|httpd)

sum1 能否告知有关 root 运行的 1086 apache 进程。这是一个安全问题吗?

答案1

不,这是正常的。在基于 Debian 的系统上,apache2 以 root 身份启动。然后它分叉并以非特权用户身份运行(通常是www-data)。实际工作由这些进程完成。

只有特权进程才能绑定到 1024 以下的端口。因此,至少要绑定到默认的 80 和 443 端口,它必须以 root 身份运行。

除其他事项外,原始进程还会读取 SSL 证书私钥,而这些私钥通常只能由 root 读取。来自/usr/share/doc/apache2/README.Debian.gz

The SSL key file should only be readable by root; the certificate file may be
globally readable. These files are read by the Apache parent process which runs
as root, and it is therefore not necessary to make the files readable by the
www-data user.

所以,这是有记录的行为。

答案2

不。Apache 始终以“root”身份启动,然后使用“setuid”生成子进程,这些子进程实际上负责处理 apache 用户的请求。

如果您想在特权端口(即低于端口 1024 的端口)上创建监听套接字,则必须以 root 身份执行此操作(或更准确地说:使用用户 ID 0)。端口 80 和 443 用于 SSL。

所以...如果您不信任 Apache 绑定到套接字,则您不应该在您的服务器上运行 Web 服务器。

例如参见http://www.thegeekstuff.com/2011/03/apache-hardening/

相关内容