惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
Hugging Face - Blog
Hugging Face - Blog
L
LINUX DO - 热门话题
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
D
Docker
C
Cyber Attacks, Cyber Crime and Cyber Security
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
T
Tenable Blog
P
Privacy International News Feed
Google DeepMind News
Google DeepMind News
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
Arctic Wolf
C
Cybersecurity and Infrastructure Security Agency CISA
C
Cisco Blogs
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
The Hacker News
The Hacker News
Project Zero
Project Zero
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threatpost
V
Visual Studio Blog
The GitHub Blog
The GitHub Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
Jina AI
Jina AI
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
MongoDB | Blog
MongoDB | Blog
U
Unit 42
Scott Helme
Scott Helme
A
About on SuperTechFans
WordPress大学
WordPress大学
F
Fortinet All Blogs
大猫的无限游戏
大猫的无限游戏
G
GRAHAM CLULEY
Latest news
Latest news
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Schneier on Security

博客园 - 松山居士

部署Hermes-Agent和SenseNova-Skills WSL迁移OpenEuler虚拟机 采用Ollama本地布署DeepSeekCoderV2 Loongnix Server 23.2安装Docker及常用镜像 Ollama导出和导入DeepSeek预训练大模型 Win10上模拟LoongArch虚拟机安装Deepin系统 查看exe启动命令和参数 Visual Studio C++设置EXE和DLL在不同路径 JMeter做WEB和API自动化测试 PG数据库常用DDL VSCode+XMake开发环境搭建备忘 C++库管理Conan使用备忘 Python多版本管理Anaconda备忘 Win10上模拟LoongArch虚拟机并搭建Qt5开发环境 解决向日葵无人值守自启动的权限问题 强制去掉Qt的运行环境信息 QGIS插件开发备忘 Linux shell 实用命令备忘 WIN10配置FX DocuCentre-IV C2260 PCL6打印机 VMWare虚拟磁盘整理与收缩 解决启用C++17后byte重定义的问题(byte ambiguous ) 解决Deepin安装Flatpak程序时不能创建临时文件的错误
ubuntu用root账户启动服务指定脚本
松山居士 · 2026-06-16 · via 博客园 - 松山居士

ubuntu默认使用非root账号登录,如果要实现root账户开机自启动指定脚本,可以采用service的方式实现。

1、创建服务文件

sudo vim /etc/systemd/system/your-service-name.service

内容为:

[Unit]
Description=你的服务描述
After=network.target   # 确保在网络服务启动后启动,可按需调整

[Service]
Type=simple            # 服务的类型,常用的是 simple 或 forking
User=root              # 关键:指定以 root 用户运行
Group=root             # 关键:指定以 root 用户组运行
ExecStart=/path/to/your/command.sh  # 你的程序或脚本的绝对路径
Restart=on-failure     # 可选:服务意外退出时自动重启
RestartSec=3           # 可选:重启前等待秒数

[Install]
WantedBy=multi-user.target # 表示在系统进入多用户模式时启动此服务

2、启用服务

# 1. 重新加载 systemd 配置,让系统识别新的服务文件
sudo systemctl daemon-reload

# 2. 设置服务开机自启
sudo systemctl enable your-service-name.service

# 3. 立即启动服务
sudo systemctl start your-service-name.service

# 4. 查看服务运行状态,确认是否成功
sudo systemctl status your-service-name.service

如果服务启动失败,可以用以下方法排查。

sudo journalctl -u your-service-name.service -f