最准确的方法是运行 systemctl list-unit-files --type=service --state=enabled,它直接读取 systemd 单元文件启用标记,不依赖运行状态或依赖关系,完整列出真正配置为开机自启的服务。

最准确的方法是运行 systemctl list-unit-files --type=service --state=enabled。它直接读取 systemd 单元文件的启用标记,不依赖当前是否运行、也不受其他服务拉起影响,能完整列出所有真正配置为开机自启的服务。
查看全部自启动服务(含状态)
执行以下命令可看到每个服务的启用状态(enabled/disabled/masked/static):
- systemctl list-unit-files --type=service —— 显示所有服务单元及其开机自启状态
- 加 | grep enabled 可快速筛选已启用项,但注意 static 类型服务虽显示 enabled,实则不能独立启用,建议用 awk 过滤:
systemctl list-unit-files --type=service | awk '$2 == "enabled" && $1 !~ /@/'
只看真正参与开机启动的服务
排除模板服务(如 getty@.service)和静态服务(static),聚焦可被 systemctl enable/disable 控制的常规服务:
- systemctl list-unit-files --type=service --state=enabled —— 仅输出明确设为 enabled 的服务名
- 该结果不含 @ 符号的服务(如 sshd.service、nginx.service),更贴近运维实际需求
检查单个服务是否真被设为自启动
用 systemctl is-enabled 判断最可靠,返回值明确无歧义:
- systemctl is-enabled nginx.service → 返回 enabled 才算成功配置
- 返回 disabled 表示未启用;masked 表示被硬屏蔽;static 表示只能被依赖触发,不能单独启用
- 别只看 systemctl status nginx 中 “Loaded” 行末尾写的 enabled,那只是快照,可能滞后或误判
注意兼容性与常见误区
在主流 systemd 系统(Ubuntu 22.04+、CentOS 8+、Debian 11+)上:
- chkconfig --list 和 /etc/rc.d/rc3.d/ 下的 Sxx* 链接基本无效,只是兼容残留
- /etc/rc.local 若存在且有执行权限,会被作为 rc-local.service 拉起,但默认不启用,需手动 systemctl enable rc-local.service
- 图形界面用户级自启项(如 gnome-keyring)不属于系统服务范畴,要用 systemctl --user is-enabled 查











