想要禁用Ubuntu 20.04的所有自动升级,只需要修改两个文件:
-
/etc/apt/apt.conf.d/10periodic
: 这个文件控制APT的周期性任务。你需要编辑这个文件并设置所有选项为"0",这将禁止任何定期的任务。你可以使用以下命令快速完成此操作,也可以用编辑器修改:
echo -e "APT::Periodic::Update-Package-Lists \"0\";\nAPT::Periodic::Download-Upgradeable-Packages \"0\";\nAPT::Periodic::AutocleanInterval \"0\";\nAPT::Periodic::Unattended-Upgrade \"0\";" | sudo tee /etc/apt/apt.conf.d/10periodic
vi /etc/apt/apt.conf.d/10periodic
-
/etc/apt/apt.conf.d/20auto-upgrades
:这个文件控制是否自动安装更新。你需要编辑这个文件并设置所有选项为"0"。你可以使用以下命令快速完成此操作:
echo -e "APT::Periodic::Update-Package-Lists \"0\";\nAPT::Periodic::Unattended-Upgrade \"0\";" | sudo tee /etc/apt/apt.conf.d/20auto-upgrades
vi /etc/apt/apt.conf.d/20auto-upgrades
改完之后最好重启系统:
reboot
请注意,这些操作需要管理员权限,所以需要使用sudo
来执行。另外,禁用自动更新可能会使你的系统暴露在未修复的安全漏洞下,所以请确保你有其他的方式来手动管理和应用重要的安全更新。
参考文章:ubuntu20.04关闭内核自动更新、禁止/取消系统自动更新的方法
(下面勿看,可能是错误的)
👇👇👇
下面有点乱,总结一下,运行下面几条命令就行:
systemctl status unattended-upgrades.service # 查看服务状态
systemctl disable unattended-upgrades.service #禁止开机启动无人更新
systemctl stop unattended-upgrades.service #停止无人更新服务
systemctl status apt-daily.timer # 查看服务状态
systemctl disable apt-daily.timer #禁止自动下载
systemctl stop apt-daily.timer #停止自动下载
systemctl status apt-daily.service # 查看服务状态
systemctl disable apt-daily.service #禁止自动下载
systemctl stop apt-daily.service #停止自动下载
systemctl status apt-daily-upgrade.timer # 查看服务状态
systemctl disable apt-daily-upgrade.timer #禁止自动更新
systemctl stop apt-daily-upgrade.timer #停止自动更新
systemctl status apt-daily-upgrade.service # 查看服务状态
systemctl disable apt-daily-upgrade.service #禁止自动更新
systemctl stop apt-daily-upgrade.service #停止自动更新
systemctl daemon-reload #最后执行
#服务有可能是.timer也有可能是.service
参考文章:ubuntu禁用自动更新,开启grub选择界面,自动更新导致软件和驱动异常修复
这是我新装服务器各个自动升级服务初始状态:
root@ky:~#
root@ky:~# systemctl status unattended-upgrades.service
● unattended-upgrades.service - Unattended Upgrades Shutdown
Loaded: loaded (/lib/systemd/system/unattended-upgrades.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2023-12-13 05:49:08 UTC; 25min ago
Docs: man:unattended-upgrade(8)
Main PID: 1510 (unattended-upgr)
Tasks: 2 (limit: 76665)
Memory: 12.0M
CGroup: /system.slice/unattended-upgrades.service
└─1510 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
Dec 13 05:49:08 ky systemd[1]: Started Unattended Upgrades Shutdown.
root@ky:~#
root@ky:~#
root@ky:~# systemctl status apt-daily.timer
● apt-daily.timer - Daily apt download activities
Loaded: loaded (/lib/systemd/system/apt-daily.timer; enabled; vendor preset: enabled)
Active: active (waiting) since Wed 2023-12-13 05:49:06 UTC; 26min ago
Trigger: Wed 2023-12-13 13:05:59 UTC; 6h left
Triggers: ● apt-daily.service
Dec 13 05:49:06 ky systemd[1]: Started Daily apt download activities.
root@ky:~#
root@ky:~#
root@ky:~# systemctl status apt-daily.service
● apt-daily.service - Daily apt download activities
Loaded: loaded (/lib/systemd/system/apt-daily.service; static; vendor preset: enabled)
Active: inactive (dead)
TriggeredBy: ● apt-daily.timer
Docs: man:apt(8)
root@ky:~#
root@ky:~#
root@ky:~# systemctl status apt-daily-upgrade.timer
● apt-daily-upgrade.timer - Daily apt upgrade and clean activities
Loaded: loaded (/lib/systemd/system/apt-daily-upgrade.timer; enabled; vendor preset: enabled)
Active: active (waiting) since Wed 2023-12-13 05:49:06 UTC; 26min ago
Trigger: Thu 2023-12-14 06:26:23 UTC; 24h left
Triggers: ● apt-daily-upgrade.service
Dec 13 05:49:06 ky systemd[1]: Started Daily apt upgrade and clean activities.
root@ky:~#
root@ky:~#
root@ky:~# systemctl status apt-daily-upgrade.service
● apt-daily-upgrade.service - Daily apt upgrade and clean activities
Loaded: loaded (/lib/systemd/system/apt-daily-upgrade.service; static; vendor preset: enabled)
Active: inactive (dead) since Wed 2023-12-13 06:01:44 UTC; 14min ago
TriggeredBy: ● apt-daily-upgrade.timer
Docs: man:apt(8)
Process: 1828 ExecStartPre=/usr/lib/apt/apt-helper wait-online (code=exited, status=0/SUCCESS)
Process: 1841 ExecStart=/usr/lib/apt/apt.systemd.daily install (code=exited, status=0/SUCCESS)
Main PID: 1841 (code=exited, status=0/SUCCESS)
Dec 13 06:01:39 ky systemd[1]: Starting Daily apt upgrade and clean activities...
Dec 13 06:01:44 ky systemd[1]: apt-daily-upgrade.service: Succeeded.
Dec 13 06:01:44 ky systemd[1]: Finished Daily apt upgrade and clean activities.
root@ky:~#
禁用各个服务并全部停止:
root@ky:~#
root@ky:~# systemctl disable unattended-upgrades.service
Synchronizing state of unattended-upgrades.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable unattended-upgrades
Removed /etc/systemd/system/multi-user.target.wants/unattended-upgrades.service.
root@ky:~#
root@ky:~#
root@ky:~# systemctl stop unattended-upgrades.service
root@ky:~#
root@ky:~# systemctl disable apt-daily.timer
Removed /etc/systemd/system/timers.target.wants/apt-daily.timer.
root@ky:~#
root@ky:~# systemctl stop apt-daily.timer
root@ky:~#
root@ky:~# systemctl disable apt-daily.service
root@ky:~#
root@ky:~# systemctl stop apt-daily.service
root@ky:~#
root@ky:~# systemctl disable apt-daily-upgrade.timer
Removed /etc/systemd/system/timers.target.wants/apt-daily-upgrade.timer.
root@ky:~#
root@ky:~# systemctl stop apt-daily-upgrade.timer
root@ky:~#
root@ky:~# systemctl disable apt-daily-upgrade.service
root@ky:~#
root@ky:~# systemctl stop apt-daily-upgrade.service
root@ky:~#
再次查看各个服务状态:
root@ky:~#
root@ky:~# systemctl status unattended-upgrades.service
● unattended-upgrades.service - Unattended Upgrades Shutdown
Loaded: loaded (/lib/systemd/system/unattended-upgrades.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:unattended-upgrade(8)
Dec 13 05:49:08 ky systemd[1]: Started Unattended Upgrades Shutdown.
Dec 13 06:17:09 ky systemd[1]: Stopping Unattended Upgrades Shutdown...
Dec 13 06:17:09 ky systemd[1]: unattended-upgrades.service: Succeeded.
Dec 13 06:17:09 ky systemd[1]: Stopped Unattended Upgrades Shutdown.
root@ky:~#
root@ky:~#
root@ky:~# systemctl status apt-daily.timer
● apt-daily.timer - Daily apt download activities
Loaded: loaded (/lib/systemd/system/apt-daily.timer; disabled; vendor preset: enabled)
Active: inactive (dead)
Trigger: n/a
Triggers: ● apt-daily.service
Dec 13 05:49:06 ky systemd[1]: Started Daily apt download activities.
Dec 13 06:17:24 ky systemd[1]: apt-daily.timer: Succeeded.
Dec 13 06:17:24 ky systemd[1]: Stopped Daily apt download activities.
root@ky:~#
root@ky:~# systemctl status apt-daily.service
● apt-daily.service - Daily apt download activities
Loaded: loaded (/lib/systemd/system/apt-daily.service; static; vendor preset: enabled)
Active: inactive (dead)
Docs: man:apt(8)
root@ky:~#
root@ky:~# systemctl status apt-daily-upgrade.timer
● apt-daily-upgrade.timer - Daily apt upgrade and clean activities
Loaded: loaded (/lib/systemd/system/apt-daily-upgrade.timer; disabled; vendor preset: enabled)
Active: inactive (dead)
Trigger: n/a
Triggers: ● apt-daily-upgrade.service
Dec 13 05:49:06 ky systemd[1]: Started Daily apt upgrade and clean activities.
Dec 13 06:17:49 ky systemd[1]: apt-daily-upgrade.timer: Succeeded.
Dec 13 06:17:49 ky systemd[1]: Stopped Daily apt upgrade and clean activities.
root@ky:~#
root@ky:~# systemctl status apt-daily-upgrade.service
● apt-daily-upgrade.service - Daily apt upgrade and clean activities
Loaded: loaded (/lib/systemd/system/apt-daily-upgrade.service; static; vendor preset: enabled)
Active: inactive (dead)
Docs: man:apt(8)
Dec 13 06:01:39 ky systemd[1]: Starting Daily apt upgrade and clean activities...
Dec 13 06:01:44 ky systemd[1]: apt-daily-upgrade.service: Succeeded.
Dec 13 06:01:44 ky systemd[1]: Finished Daily apt upgrade and clean activities.
root@ky:~#
目前以下服务和定时器都已经被禁用并处于非活动状态:
- unattended-upgrades.service
- apt-daily.timer
- apt-daily.service
- apt-daily-upgrade.timer
- apt-daily-upgrade.service
"Loaded"行中的"disabled"表示服务已被禁用,"Active"行中的"inactive (dead)"表示服务当前未运行。所以,是的,这些服务都已被禁用。
关于禁用开机自启服务直接修改配置文件和使用systemctl
命令的区别
在Ubuntu 20.04中,禁用开机自启服务有多种方式,包括直接修改配置文件和使用systemctl
命令。这两种方式各有优点和适用场景。
-
修改配置文件:这是一种更直接的方法,它直接改变了服务的配置。这通常涉及到编辑特定服务的配置文件,并改变其中的某些参数。这种方法的好处是你可以精确地控制服务的行为,而不仅仅是启动或不启动。然而,这需要对系统服务的配置有深入的理解,并且如果不小心可能会导致错误。
-
使用
systemctl
命令:systemctl
是Systemd系统的主要管理工具,用于控制Linux系统中的服务。使用systemctl disable <service>
命令可以禁止一个服务在开机时启动。这是一种比较简单和安全的方式,因为它通过系统的标准接口进行操作,不需要直接编辑配置文件。然而,它只能控制服务是否在开机时启动,而不能改变服务的其他行为。
总的来说,如果只想禁止一个服务在开机时启动,那么使用systemctl
命令就足够了。如果你想更细致地控制服务的行为,那么你可能需要编辑配置文件。
文章目录
Ubuntu 20.04禁用自动更新全指南
Ubuntu 20.04默认设置了自动更新,这在许多情况下是有用的,特别是对于安全更新。然而,如果你想要手动控制何时进行系统更新,或者在具有有限网络连接的环境中工作,你可能会希望关闭自动更新。本文将详细介绍如何在Ubuntu 20.04上禁用自动更新。
目录
理解Ubuntu的自动更新
在深入研究如何禁用Ubuntu 20.04的自动更新之前,我们需要先理解自动更新机制。Ubuntu使用名为unattended-upgrades
的软件包来处理自动更新。这个软件包默认安装在Ubuntu上,并且默认设置为每天检查并安装安全更新1。
不过,要注意的是,虽然这项功能可以帮助保持系统的安全性,但是它也可能在某些情况下引起问题。例如,在网络连接有限的情况下,自动下载和安装更新可能会消耗大量的网络资源。此外,如果新的更新引入了与你的系统不兼容的更改,它也可能会导致问题。
通过命令行禁用自动更新
一种禁用Ubuntu 20.04自动更新的方法是使用命令行。这需要修改unattended-upgrades
软件包的配置文件。以下是步骤:
1. 打开终端
在图形界面上,你可以通过按下Ctrl + Alt + T
快捷键来打开一个新的终端窗口。
2. 编辑50unattended-upgrades
文件
使用文本编辑器打开/etc/apt/apt.conf.d/50unattended-upgrades
文件。例如,可以使用nano
编辑器:
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
3. 修改配置
在文件中找到以下行:
Unattended-Upgrade::InstallOnShutdown "false";
并将其更改为:
Unattended-Upgrade::InstallOnShutdown "true";
这将使得只有在关机时才会进行无人值守的升级。
4. 保存并关闭文件
如果你正在使用nano
编辑器,可以按Ctrl + X
,然后按Y
,最后按Enter
来保存并关闭文件。
5. 禁用自动更新服务
最后,你需要禁用自动更新服务。在终端中输入以下命令:
sudo systemctl disable --now unattended-upgrades.service
以上步骤将会禁用Ubuntu 20.04的自动更新功能。
通过GUI禁用自动更新
如果你更喜欢图形用户界面(GUI),也可以通过系统设置来禁用自动更新。以下是步骤:
-
打开“软件和更新”
点击左上角的"Show Applications"按钮,然后在搜索栏中输入“Software & Updates”并点击它。
-
更改设置
在打开的窗口中,切换到"Updates"标签页。在"Automatically check for updates:“下拉菜单中,选择"Never”。
-
应用更改
点击"Close"按钮应用更改。系统可能会提示你输入密码以确认更改。
这样,你就通过GUI禁用了Ubuntu 20.04的自动更新。
可能遇到的问题与解决方法
虽然以上步骤通常足够禁用Ubuntu 20.04的自动更新,但在某些情况下,你可能还会遇到一些问题。例如,尽管你已经禁用了自动更新,但系统仍然会自动检查更新。这是因为apt-daily
和apt-daily-upgrade
服务仍然在运行。
要解决这个问题,你可以禁用这两个服务。在终端中输入以下命令:
sudo systemctl disable --now apt-daily.service apt-daily.timer
sudo systemctl disable --now apt-daily-upgrade.service apt-daily-upgrade.timer
如果你想恢复自动更新,只需将disable
更改为enable
即可。
总结
本文详细介绍了如何在Ubuntu 20.04上禁用自动更新,无论是通过命令行还是GUI。虽然自动更新有其优点,但在某些情况下,手动控制更新可能更为理想。只需记住,定期检查并安装安全更新仍然是非常重要的,尤其是在公共网络环境中。
“AutomaticUpdates - Ubuntu Community Help Wiki.” https://help.ubuntu.com/community/AutomaticUpdates. Accessed 25 Sep. 2021. ↩︎