温馨提示×

cmatrix centos如何设开机启动

小樊
38
2026-09-30 04:27:15
栏目: 智能运维

在 CentOS 上让 cmatrix(字符矩阵屏保效果)开机启动,常见有几种方式,取决于你想要的“开机启动”效果:


一、登录后自动运行(推荐,适合桌面/终端用户)

方法 1:写入 ~/.bashrc(当前用户登录终端后自动运行)

echo "cmatrix" >> ~/.bashrc

⚠️ 注意:

  • 只在 打开终端或登录 shell 时运行
  • 会占用当前 shell,退出即结束

方法 2:使用 systemd 用户服务(更规范)

1. 创建用户 service

mkdir -p ~/.config/systemd/user
vi ~/.config/systemd/user/cmatrix.service

内容:

[Unit]
Description=cmatrix autostart

[Service]
ExecStart=/usr/bin/cmatrix
Restart=always
StandardInput=tty
TTYPath=/dev/tty1

[Install]
WantedBy=default.target

2. 启用

systemctl --user enable cmatrix

(适合服务器 tty 登录)


二、系统开机直接进入 cmatrix(服务器场景)

方法 3:修改 getty 登录 shell(不推荐新手)

编辑:

vi /etc/systemd/system/getty@tty1.service.d/override.conf
[Service]
ExecStart=
ExecStart=-/usr/bin/cmatrix

然后:

systemctl daemon-reexec

⚠️ 风险:可能无法正常登录系统


三、图形界面(GNOME/KDE)开机启动

方法 4:开机启动项(GUI)

  1. 打开 “启动应用程序”
  2. 添加:
    • 名称:cmatrix
    • 命令:cmatrix

或在终端:

cp /usr/share/applications/cmatrix.desktop ~/.config/autostart/

四、检查 cmatrix 是否已安装

which cmatrix

没有就装:

yum install cmatrix -y

(CentOS 7 / 8 / Stream 均可)


推荐方案总结

场景 推荐方式
服务器 tty systemd user service
桌面用户 启动应用程序
简单测试 ~/.bashrc

如果你能说明是 CentOS 几 + 是否有桌面 + 是否服务器,我可以给你最精确的配置。

0 踩