VPSのDebianをunattended-upgradeで自動アップグレード

VPSをいくつか契約しています。システムのアップグレードは手動で行っています。
でも数日PCに触れないことなんかもあり最近の情勢からすると不安。ということでシステムの自動アップグレードを設定しました。

今回の対象はDebian trixie amd64環境。これまではapticronを動かしてパッケージの更新とダウンロードは自動化していました。
以前はcron-aptを使っていましたが、今回 unattended-upgradesを試してみました.

unattended-upgrades を導入

aptでunattended-upgradesを導入して設定します。

$ sudo apt install unattended-upgrades (1)
$ sudo dpkg-reconfigure unattended-upgrades (2)
Package configuration



  ┌───────────────────┤ Configuring unattended-upgrades ├───────────────────┐
  │                                                                         │
  │ Applying updates on a frequent basis is an important part of keeping    │
  │ systems secure. By default, updates need to be applied manually using   │
  │ package management tools. Alternatively, you can choose to have this    │
  │ system automatically download and install important updates.            │
  │                                                                         │
  │ Automatically download and install stable updates?                      │
  │                                                                         │
  │                    <Yes>                       <No>                     │
  │                                                                         │
  └─────────────────────────────────────────────────────────────────────────┘





Replacing config file /etc/apt/apt.conf.d/20auto-upgrades with new version
$ cat  /etc/apt/apt.conf.d/20auto-upgrades
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
  1. unattended-upgradesパッケージを導入

  2. dpkg-reconfigure で <Yes> を選択

unattended upgrades

メール通知を有効にする

$ sudo vi /etc/apt/apt.conf.d/50unattended-upgrades
$ sudo git -C /etc diff /etc/apt/apt.conf.d/50unattended-upgrades
diff --git a/apt/apt.conf.d/50unattended-upgrades b/apt/apt.conf.d/50unattended-upgrades
index 26f84e133..007af9182 100644
--- a/apt/apt.conf.d/50unattended-upgrades
+++ b/apt/apt.conf.d/50unattended-upgrades
@@ -92,13 +92,13 @@ Unattended-Upgrade::Package-Blacklist {
 // If empty or unset then no email is sent, make sure that you
 // have a working mail setup on your system. A package that provides
 // 'mailx' must be installed. E.g. "user@example.com"
-//Unattended-Upgrade::Mail "";
+Unattended-Upgrade::Mail "user@example.com"; (1)

 // Set this value to one of:
 //    "always", "only-on-error" or "on-change"
 // If this is not set, then any legacy MailOnlyOnError (boolean) value
 // is used to chose between "only-on-error" and "on-change"
-//Unattended-Upgrade::MailReport "on-change";
+Unattended-Upgrade::MailReport "always"; (2)

 // Remove unused automatically installed kernel-related packages
 // (kernel images, kernel headers and kernel version locked tools).
$ sudo unattended-upgrade --dry-run --debug (3)
$ sudo unattended-upgrade --debug
  1. 通知を送るメールアドレス

  2. 実行舞に通知。しばらく動かしたら on-change に変更予定

  3. 動作確認

apticronはアンインストール
$ sudo apt remove apticron

しばらく動かして見て問題なければ別のVPSにも反映しようと思います。

環境

$ dpkg-query -W unattended-upgrades
unattended-upgrades     2.12
$ lsb_release -dr
Description:    Debian GNU/Linux 13 (trixie)
Release:        13
$ arch
x86_64

Reposts

  • matoken :fox:

コメントを残す

メールアドレスが公開されることはありません。 ※ が付いている欄は必須項目です

Your post must include a link to this post.

How does this work?
Write a response on your own website and include a link to this post. Then submit your response’s URL here. Your response may appear here after moderation. To update or remove it, edit or delete your original post and submit the same URL again. Learn more about Webmentions.