0
1

sshでUbuntuにログインしたとき、motdと呼ばれるシステムのメッセージが表示される。
これに含まれるESM(ubuntu pro)の宣伝がうざったいので取り除く。
ただしaptのアップデート件数などはほしいので、motdを全部丸ごとOFFにするのではなく、
ESMの宣伝だけを取り除きたい。

つまりどうしたいか

自分のubuntuのmotdを確認すると次のようになっていた。
人やシステムの状態によってはもっと多いかもしれない。

Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 6.5.0-35-generic x86_64)

  * Documentation:  https://help.ubuntu.com
  * Management:     https://landscape.canonical.com
  * Support:        https://ubuntu.com/pro

System information as of Wed Jun 12 14:16:26 JST 2024

  System load:  0.27                Processes:             28
  Usage of /:   53.1% of 250.92GB   Users logged in:       0
  Memory usage: 2%                  IPv4 address for eth0: xxx.xxx.xxx.xxx
  Swap usage:   0%

Expanded Security Maintenance for Applications is not enabled.

0のアップデートはすぐに適用されます。

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status

Last login: Wed Jun 12 15:46:27 2024 from xxx.xxx.xxx.xxx

これを

Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 6.5.0-35-generic x86_64)

0のアップデートはすぐに適用されます。

Last login: Wed Jun 12 15:46:27 2024 from xxx.xxx.xxx.xxx

くらいにまで減らしたい。

motdの生成されるしくみ

このmotdの内容はrun-parts /etc/update-motd.d/で確認できる。
「ubuntu motd ESM」などで検索して出てくるこの記事とかを読むと、/etc/pam.d/sshdを編集すると丸ごと葬り去れることがわかる。

しかしこの記事の目的として、aptのアップデート件数などは表示させたいので、もう少し別のことを行う必要がある。

update-motd.dをいじる

上記の記事でも書かれているが、motdで見かける多くのものは/etc/update-motd.dにスクリプトが集積されていて、ログインするたびに出力が/run/motd.dynamicに反映されている。
共有サーバーの管理者とかで、使用者に独自のメッセージを表示させる場合なども、このディレクトリにファイルを追加することで実現できる。
/etc/update-motd.d/の中身は以下の通り。環境によって多少の違いがあるかもしれない。

$ cd /etc/update-motd.d/
$ ls -1 /etc/update-motd.d/
00-header
10-help-text
50-motd-news
50-landscape-sysinfo
85-fwupd
88-esm-announce
90-updates-available
91-contract-ua-esm-status
91-release-upgrade
92-unattended-upgrades
95-hwe-eol
98-fsck-at-reboot
98-reboot-required

まずは記事に従ってディレクトリ内部のファイルで出力が邪魔なものをchmod -xとかで実行しないようにする。
ファイル名に何か追記する形でもよい。

sudo chmod -x 10-help-text 50-motd-news 88-esm-announce 91-contract-ua-esm-status 50-landscape-sysinfo

実行しないようにしたファイルの詳細は以下の通り

  • 10-help-text:
    ubuntuのドキュメントのリンクを表示する。ヘッダーの次に実行され、
    * Documentation: https://help.ubuntu.comといった(空白行込みで)5行も出力している部分。
    邪魔なのでいらない。
  • 50-motd-news:
    https://motd.ubuntu.comの内容を表示する。
    筆者の環境では元から実行されても空白だった。
    表示されるメッセージはesmに限らないが、どちらにせよ大抵宣伝なのでいらない。
  • 88-esm-announce:
    /var/lib/ubuntu-advantage/messages/motd-esm-announceの内容を表示する。
    いらない。
  • 91-contract-ua-esm-status:
    /var/lib/ubuntu-advantage/messages/以下の主にUbuntu Proの状態を表示する。
    いらない。
  • 50-landscape-sysinfo:
    システムのload averageとかを表示する。これは必要なら残しておいてもいい。
    筆者はscreenFetchを使いたかったので、今回これも対象に含めた。

ここまでやった結果をrun-parts /etc/update-motd.d/で確認する。

Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 6.5.0-35-generic x86_64)

Expanded Security Maintenance for Applications is not enabled.

0のアップデートはすぐに適用されます。

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status

なんてこった。一番忌々しいESMの宣伝がまだ残ってる...
何がこれを出力しているのか確認するため、/etc/update-motd.d/にあるファイルを一つ一つ実行していく。
/etc/update-motd.d/90-updates-availableを実行したとき、

Expanded Security Maintenance for Applications is not enabled.

0のアップデートはすぐに適用されます。

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status

と表示される。
つまり、アップデート件数の前後にある最も忌々しいESMの宣伝は90-updates-availableが単独で出しているのである。

90-updates-availableからESMの宣伝を取り除く

この節がこの記事の一番メインの内容です。
90-updates-availableそのものに、ESMの宣伝の出力を抑制するオプションはない。
ファイルの中身はpythonスクリプトなので、中身を編集してどうにかすることもできるが、実は簡単な方法がある。

90-updates-availableはあらかじめ生成された/var/lib/update-notifier/updates-availableを表示しており、そのファイルはaptが呼び出されたときや定期的な実行によって/usr/lib/update-notifier/apt_check.py --human-readableが生成している。
/usr/lib/update-notifier/apt_check.pyはESMの宣伝を出力を抑制するオプション--no-esm-messageを持っており、空ファイル/var/lib/update-notifier/hide-esm-in-motdが存在するときに有効になる。

なので結論として、

sudo touch /var/lib/update-notifier/hide-esm-in-motd

で空ファイルを生成することで、ようやくmotdからESMの宣伝を葬り去ることができる。

すぐに反映されない場合は、/var/lib/update-notifier/updates-availableを一度削除しapt updateによって再生成させると反映される。

sudo rm /var/lib/update-notifier/updates-available
sudo apt update

めでたしめでたし。

参考文献

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1