0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

motdファイルを編集してUbuntuサーバログイン時のメッセージを変える

Posted at

はじめに

sshを使ってUbuntuサーバにログインすると、初期設定では以下のようなメッセージが表示されます。

Welcome to Ubuntu 24.04 LTS (GNU/Linux 6.8.0-52-generic x86_64)

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

Expanded Security Maintenance for Applications is not enabled.

334 updates can be applied immediately.
13 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable

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

Last login: Sun Feb 16 21:56:52 2025 from xxx.xxx.xxx.xxx

これだとかなり冗長なうえ、少し寂しいです。一応ドキュメントやアップデートの情報なども載っているのですが、毎回表示されるのはちょっと面倒です。

そこで今回は、Ubuntuサーバへのログイン時に表示されるメッセージを変更する方法を紹介します。

motdファイル

Ubuntuサーバにログインすると表示されるメッセージは、/etc/motdというファイルに記述することができます。sudo権限を使って編集してあげましょう。

$ sudo nano /etc/motd

このファイルには好きな文字データを書き込むことができるので、サーバの名前や業務を書いたり、自分で決めたお知らせを書いたりすることができます。

また、アスキーアートなどを書き込むことができるので、色々と工夫してみるのも面白いかもしれません。

例えば、このサイトで画像からアスキーアートを生成することができます。

ほかにも、飾り文字などを使っても面白いと思います。

/etc/pam.d/sshdファイル

motdファイルを編集すると、ログイン時に自分で決めたメッセージが表示されるようにはなるのですが、デフォルトのメッセージが表示されたままになっています。

なので、以下のファイルを編集し、デフォルトのメッセージを非表示にしましょう。

$ sudo nano /etc/pam.d/sshd

このファイルの、以下の行を探してコメントアウトしてください。

session    optional     pam_motd.so  motd=/run/motd.dynamic

dynamicという単語の通り、これはサーバへのSSHログインがあったときにメッセージを動的に生成して表示させるというものです。

この行をコメントアウトすることで、motdファイルに書いたメッセージと、最終ログイン日時とIPアドレスの表示のみになります。

おわりに

今回は、Ubuntuサーバへのログイン時に表示されるメッセージを変更する方法を紹介しました。

自分でサーバを設営している場合、ログイン時にも少し工夫を加えてみたくなりますよね。そういう時にこのような設定が一役立つはずです。

では、また次回の記事でお会いしましょう。

参考文献

第755回 UbuntuにおけるMOTDの仕組みのすべて | gihyo.jp

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?