Bootstrap

ubuntu设置系统自动更新

在Ubuntu中设置系统自动更新可以通过以下步骤完成:

1. 安装 unattended-upgrades

unattended-upgrades 是用于自动安装安全更新的工具。

sudo apt update
sudo apt install unattended-upgrades

2. 配置自动更新

编辑配置文件 /etc/apt/apt.conf.d/50unattended-upgrades

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

找到并修改以下部分:

Unattended-Upgrade::Allowed-Origins {
    "${distro_id}:${distro_codename}";
    "${distro_id}:${distro_codename}-security";
    "${distro_id}ESM:${distro_codename}";
};

确保安全更新已启用:

Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "02:00";

3. 启用自动更新

编辑配置文件 /etc/apt/apt.conf.d/20auto-upgrades

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

添加以下内容:

APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Unattended-Upgrade "1";

4. 重启服务

重启 unattended-upgrades 服务以应用更改:

sudo systemctl restart unattended-upgrades

5. 检查状态

确认服务已启用并运行:

sudo systemctl status unattended-upgrades

6. 查看日志

日志文件位于 /var/log/unattended-upgrades/,可用于检查更新情况。

总结

通过以上步骤,Ubuntu系统将自动安装安全更新,并在需要时自动重启。

;