问题
Ubuntu系统的软件有可能存在安全漏洞,为了避免安全问题,需要对软件打补丁,配置自动打补丁可以解放双手
解决方法
通过unattended-upgrades
可以自动更新Ubuntu软件安全漏洞
安装unattended-upgrades
apt -y install unattended-upgrades
配置50unattended-upgrades
50unattended-upgrades
的文件位子在/etc/apt/apt.conf.d/50unattended-upgrades
- 禁止更新dev版本
Unattended-Upgrade::DevRelease "false";
- 启用邮箱提示
Unattended-Upgrade::Mail "<邮箱地址>";
- 自动移除不需要的依赖
Unattended-Upgrade::Remove-Unused-Dependencies "true";
- 启用自动重启并设置凌晨2点自动重启,(安全更新安装至内核后可能需要自动重启)
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "02:00";
配置20auto-upgrades
20auto-upgrades
的文件位子在/etc/apt/apt.conf.d/20auto-upgrades
20auto-upgrades配置是用来控制更新间隔,设置一天一次就行,该文件可能不存在,需要自己手动创建
echo -e '\nAPT::Periodic::Update-Package-Lists "1";\nAPT::Periodic::Unattended-Upgrade "1";' >> /etc/apt/apt.conf.d/20auto-upgrades
测试
在应用配置更改后,你可以手动运行 unattended-upgrades
来测试配置是否正确:
unattended-upgrade --dry-run --debug
这将模拟自动更新过程,但不实际应用任何更新。
查看日志
可以在文件夹/var/log/unattended-upgrades
里查看日志
也可以通过下面命令直接查看系统日志,但我这里查看不到
grep -i unattended-upgrade /var/log/syslog