![clamsmtpd 不会以 clamsmtpd.conf 中指定的用户启动](https://linux22.com/image/196959/clamsmtpd%20%E4%B8%8D%E4%BC%9A%E4%BB%A5%20clamsmtpd.conf%20%E4%B8%AD%E6%8C%87%E5%AE%9A%E7%9A%84%E7%94%A8%E6%88%B7%E5%90%AF%E5%8A%A8.png)
自从我将服务器从 Debian Stretch 升级到 Debian Buster 以来,尽管我指定在文件中的用户clamsmtpd
下运行,但它始终在该用户下运行。这是该文件的内容:clamsmtp
clamav
/etc/clamsmtpd.conf
# ------------------------------------------------------------------------------
# SAMPLE CLAMSMTPD CONFIG FILE
# ------------------------------------------------------------------------------
#
# - Comments are a line that starts with a #
# - All the options are found below with their defaults commented out
# The address to send scanned mail to.
# This option is required unless TransparentProxy is enabled
OutAddress: 10025
# The maximum number of connection allowed at once.
# Be sure that clamd can also handle this many connections
#MaxConnections: 64
# Amount of time (in seconds) to wait on network IO
#TimeOut: 180
# Address to listen on (defaults to all local addresses on port 10025)
Listen: 127.0.0.1:10026
# The address clamd is listening on
ClamAddress: /var/run/clamav/clamd.ctl
# A header to add to all scanned email
Header: X-AV-Checked: ClamAV using ClamSMTP
# Directory for temporary files
TempDirectory: /var/spool/clamsmtp
# PidFile: location of PID file
PidFile: /var/run/clamsmtp/clamsmtpd.pid
# Whether or not to bounce email (default is to silently drop)
#Bounce: off
# Whether or not to keep virus files
#Quarantine: off
# Enable transparent proxy support
#TransparentProxy: off
# User to run as
#User: clamsmtp
User: clamav
# Virus actions: There's an option to run a script every time a
# virus is found. Read the man page for clamsmtpd.conf for details.
使用重新启动服务service clamsmtp restart
并发出命令后ps -eaf
,我可以看到在用户/usr/sbin/clamsmtpd
下运行clamsmtp
。有什么线索可以阻止守护进程使用其配置文件中指定的值吗?
答案1
由于我发布了这个问题,我发现了这个文件/etc/systemd/system/multi-user.target.wants/clamsmtp.service
,其中包含启动 clamsmtp 服务的参数:
[Unit]
Description=virus-scanning SMTP proxy clamsmtp
Documentation=man:clamsmtpd(8)
After=network.target local-fs.target
[Service]
Type=forking
User=clamsmtp
Group=clamsmtp
RuntimeDirectory=clamsmtp
ExecStart=/usr/sbin/clamsmtpd
[Install]
WantedBy=multi-user.target
请注意 User 参数,它指定在哪个用户下运行此服务。我将该行切换到User=clamav
,重新启动服务,clamsmtpd
现在正在用户下运行clamav
。
我还发现了为什么没有考虑User
中指定的参数。/etc/clamsmtpd.conf
在里面clamsmtpd.conf 手册页,它对参数说了以下内容User
:
用户:运行的用户。如果指定此选项,则 clamsmtpd(8) 必须以 root 身份启动。然后它将放弃 root 权限并以指定用户身份运行。用户可以是名称或数字用户 ID。
由于该服务不是以 root 身份启动的,因此无法切换到指定用户。