clamsmtpd 不会以 clamsmtpd.conf 中指定的用户启动

clamsmtpd 不会以 clamsmtpd.conf 中指定的用户启动

自从我将服务器从 Debian Stretch 升级到 Debian Buster 以来,尽管我指定在文件中的用户clamsmtpd下运行,但它始终在该用户下运行。这是该文件的内容:clamsmtpclamav/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 身份启动的,因此无法切换到指定用户。

相关内容