1
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?

More than 3 years have passed since last update.

特定のuserにだけ表示するmotd

Posted at

TL;DR

みんな大好きPAMの出番だ。

# Show motd for admin
session     [success=1 default=ignore] pam_succeed_if.so user != admin quiet
session     optional      pam_motd.so motd=/etc/motd.admin

はじめに

厳密には本稿のやり方は「/etc/motdに加えて追加MOTDを表示している」だけなので注意してください。

表示イメージ
$(追加MOTDの表示)
Last Login: ...
$(/etc/motdの表示)

sshログインの場合は以下の設定を行えば追加MOTDだけの表示になります。

/etc/ssh/sshd_config
PrintMotd no
PrintLastLog no

検証

/etc/motdは空の状態かsshd_configで無効化されている前提になります。

設定

AA作るの面倒なのでfiglet入れます。

[root@svr02 ~]# yum -y install epel-release
[root@svr02 ~]# yum -y install figlet
[root@svr02 ~]# echo -e "\e[31m$(figlet -f slant ADMINISTRATOR)\e[m" > /etc/motd.admin
[root@svr02 ~]# cat /etc/motd.admin
    ___    ____  __  ________   _____________________  ___  __________  ____
   /   |  / __ \/  |/  /  _/ | / /  _/ ___/_  __/ __ \/   |/_  __/ __ \/ __ \
  / /| | / / / / /|_/ // //  |/ // / \__ \ / / / /_/ / /| | / / / / / / /_/ /
 / ___ |/ /_/ / /  / // // /|  // / ___/ // / / _, _/ ___ |/ / / /_/ / _, _/
/_/  |_/_____/_/  /_/___/_/ |_/___//____//_/ /_/ |_/_/  |_/_/  \____/_/ |_|

今回はsshログインに対して追加表示させるので/etc/pam.d/sshdの最後にルールを追加する。
pam_motdはsessionでしか使えないので注意。

/etc/pam.d/sshd
+# Show motd for admin
+session     [success=1 default=ignore] pam_succeed_if.so user != admin quiet
+session     optional      pam_motd.so motd=/etc/motd.admin

1行目:adminユーザ以外は1行分ルールをスキップする。
2行目:motdとして/etc/motd.adminを表示する。

動作確認

vagrantユーザでログイン
❯ ssh vagrant@192.168.1.12
Warning: Permanently added '192.168.1.12' (ECDSA) to the list of known hosts.
[vagrant@svr02 ~]$
adminユーザでログイン
❯ ssh admin@192.168.1.12
Warning: Permanently added '192.168.1.12' (ECDSA) to the list of known hosts.
    ___    ____  __  ________   _____________________  ___  __________  ____
   /   |  / __ \/  |/  /  _/ | / /  _/ ___/_  __/ __ \/   |/_  __/ __ \/ __ \
  / /| | / / / / /|_/ // //  |/ // / \__ \ / / / /_/ / /| | / / / / / / /_/ /
 / ___ |/ /_/ / /  / // // /|  // / ___/ // / / _, _/ ___ |/ / / /_/ / _, _/
/_/  |_/_____/_/  /_/___/_/ |_/___//____//_/ /_/ |_/_/  |_/_/  \____/_/ |_|

[admin@svr02 ~]$

コンソールログインでもやりたい

/etc/pam.d/loginに同様に設定を入れれば可能ですが、CentOSのコンソールログインでLast LoginとMOTDの表示を無効化する方法を探せなかったので冒頭で言及した通り表示がキモいことになります。
とはいえ、コンソールログインをするケースは緊急事態かつ熟練の管理者に限られるので、このようなMOTDの表示をしたいケースはあまりないかなと思っています。

1
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
1
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?