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

推荐订阅源

W
WeLiveSecurity
T
Tenable Blog
Project Zero
Project Zero
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
S
Schneier on Security
Scott Helme
Scott Helme
S
Securelist
Know Your Adversary
Know Your Adversary
Vercel News
Vercel News
IT之家
IT之家
V
V2EX
F
Fortinet All Blogs
Simon Willison's Weblog
Simon Willison's Weblog
K
Kaspersky official blog
博客园_首页
T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
Spread Privacy
Spread Privacy
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
有赞技术团队
有赞技术团队
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
Hugging Face - Blog
Hugging Face - Blog
博客园 - 三生石上(FineUI控件)
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CXSECURITY Database RSS Feed - CXSecurity.com
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
S
SegmentFault 最新的问题
AWS News Blog
AWS News Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost

Linux – Ed_'s Blog

UPower – 将笔记本电池当成UPS使用 – yywr's Blog Samba 服务基本用法 – yywr's Blog Crontab 使用笔记 – yywr's Blog Linux 程序开机启动并保活:Systemd 进程守护管理工具 – yywr's Blog Linux 下自动挂载 Samba /CIFS 共享文件夹 – yywr's Blog Ubuntu 开机自动挂载第二块硬盘 – yywr's Blog 重装了家里的服务器系统 – yywr's Blog Ubuntu 笔记本合盖子不休眠的方法 – yywr's Blog
给 Debian 开了自动安全更新 – yywr's Blog
yywr · 2026-06-15 · via Linux – Ed_'s Blog

Skip to content

由于AI的关系,最近各种漏洞满天飞,但又无能为力,唯一能做就是利用 AI 做些以前做起来非常费劲的安全措施了

在 Debian/Ubuntu 系统中,使用 unattended-upgrades 工具可以实现仅自动安装安全更新,这是官方推荐的标准方案(来自AI整理)

  • 自动安装安全更新
  • 普通功能更新仍然手动
  • 自动清理旧包
  • 避免自动重启导致业务中断 也没什么重要业务,就重启吧

Debian 自动更新其实由两部分组成:

组件作用
apt-daily.timer自动刷新软件源缓存
apt-daily-upgrade.timer自动安装更新
unattended-upgrades真正执行自动升级(核心包)
/etc/apt/apt.conf.d/配置目录

第一步:安装与启用

大多数系统可能已安装,你可以通过以下命令确保安装并开启:

# 1. 安装工具
sudo apt update && sudo apt install unattended-upgrades -y

# 2. 启用自动更新(交互界面选 Yes)
sudo dpkg-reconfigure --priority=low unattended-upgrades

第二步:配置更新源(核心)

编辑配置文件,确保系统只从安全仓库拉取补丁

sudo nano /etc/apt/apt.conf.d/50unattended-upgrades

找到 Unattended-Upgrade::Allowed-Origins 部分,只保留 -security 这一行,其余带 -updates 的行请保持注释状态(行首有 //):

Unattended-Upgrade::Allowed-Origins {
    "${distro_id}:${distro_codename}-security";
    // "${distro_id}:${distro_codename}-updates";   // 必须注释,避免安装功能更新
    // "${distro_id}:${distro_codename}-backports";
};

补充说明:Debian 系统有时会使用不同的匹配模式,如 origin=Debian,codename=${distro_codename},label=Debian-Security,原理相同,只启用 Security 相关条目即可。

不要开启:”${distro_id}:${distro_codename}”; 否则会自动安装普通更新。

第三步:设置执行频率

编辑自动升级任务文件:

sudo nano /etc/apt/apt.conf.d/20auto-upgrades

确保或修改内容如下(1 代表每天执行):

APT::Periodic::Update-Package-Lists "1"; #每天更新软件列表
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::Unattended-Upgrade "1"; #每天自动升级
APT::Periodic::AutocleanInterval "7";

第四步:可选的高级配置

如果希望内核更新后自动重启(慎重开启),可在 50unattended-upgrades 文件末尾添加:

Unattended-Upgrade::Automatic-Reboot "true"; #自动重启
Unattended-Upgrade::Automatic-Reboot-Time "02:00"; #重启时间
Unattended-Upgrade::Remove-Unused-Dependencies "true"; #自动清理旧包
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true"; #自动清理旧 kernel
Unattended-Upgrade::SyslogEnable "true"; #开启日志,位置/var/log/unattended-upgrades/;unattended-upgrades.log;unattended-upgrades-dpkg.log

第五步:验证配置

运行试运行命令,检查系统是否会获取安全更新:

sudo unattended-upgrade --dry-run -d

查看日志可确认运行状态:

sudo cat /var/log/unattended-upgrades/unattended-upgrades.log

确认自动任务存在:

systemctl list-timers --all 'apt-daily*'
#应该看到:
# * apt-daily.timer
# * apt-daily-upgrade.timer