可通过systemctl list-unit-files --type=service --state=enabled准确查看已启用的开机启动服务,该命令以state=enabled为权威依据;也可用list-dependencies按target筛选、is-enabled检查单个服务、chkconfig作兼容性参考。

如果您需要确认哪些服务被配置为随系统启动而自动运行,可通过 systemd 的单元文件状态进行准确判定。以下是多种可靠方法来查看 Linux 系统中已启用的开机启动服务。
一、列出所有已启用的服务单元
systemctl list-unit-files 命令直接读取 /usr/lib/systemd/system 和 /etc/systemd/system 下的 .service 文件,并依据其 enable/disable 状态标识是否参与开机启动。该命令输出结果以 state=enabled 为权威依据,不依赖当前运行状态。
1、打开终端,执行以下命令:
2、输入 systemctl list-unit-files --type=service --state=enabled
3、系统将输出所有标记为开机启用的服务名称及其对应路径和状态。
二、按目标(target)筛选启用服务
systemd 将服务归类到特定 target(如 multi-user.target),启用服务即在对应 target 的 .wants 目录下创建符号链接。此方式可验证服务实际挂载位置。
1、执行命令查看 multi-user.target 下启用的服务:
2、输入 systemctl list-dependencies --reverse --all multi-user.target | grep '\.service$'
3、该命令回显所有被 multi-user.target 依赖且为 service 类型的单元,即典型开机启动项。
三、检查单个服务的启用状态
针对特定服务,可使用 is-enabled 子命令快速判断其是否被设置为开机自启,返回值为 enabled 或 disabled,无额外输出干扰。
1、在终端中运行:
2、输入 systemctl is-enabled servicename.service(将 servicename 替换为实际服务名,如 sshd)
3、若返回 enabled,表示该服务已配置为开机启动;若返回 disabled,则未启用。
四、结合 chkconfig 兼容性检查(仅限 SysV 兼容层)
部分系统仍保留 SysV init 脚本兼容机制,chkconfig 可读取 /etc/init.d/ 下脚本的 LSB 头部信息并映射至 runlevel。注意:此方式不反映原生 systemd 服务的真实启用状态,仅作辅助参考。
1、确认 chkconfig 已安装:
2、执行 which chkconfig,若返回路径则继续
3、运行 sudo chkconfig --list | grep ':on$',筛选出在任一运行级别中标记为 on 的服务










