LoginSignup
2
3

More than 5 years have passed since last update.

EC2のログイン時にサーバの名前を表示する

Posted at

AWSのEC2のサーバに多数ログインする様になってくるとどのサーバに居るのか。というのは大事な情報になってきます。
勿論プロンプトに[ec2-user@redmine ec2-user]と表示されて、今はredmineサーバにいるよという事などがわかるのですが

sshでEC2にログインするとEC2にログインしたよと、最初に

       __|  __|_  )
       _|  (     /   Amazon Linux AMI
      ___|\___|___|

この様に表示されます。

せっかくなのでここをサーバの名前にしました。

ここに出ているのは、/etc/motdのファイルの中身なのですが
/etc/cron.d/update-motdファイルで設定されているcronで書き換えられます。
なので、/etc/update-motd.d/30-banner ファイルを書き換えます。

今回はredmineサーバなので、こちらで文字を作って設定しました

/etc/update-motd.d/30-banner
#!/bin/sh
version=$(rpm -q --qf '%{version}' system-release)
cat << EOF
 ______    _______  ______   __   __  ___   __    _  _______ 
|    _ |  |       ||      | |  |_|  ||   | |  |  | ||       |
|   | ||  |    ___||  _    ||       ||   | |   |_| ||    ___|
|   |_||_ |   |___ | | |   ||       ||   | |       ||   |___ 
|    __  ||    ___|| |_|   ||       ||   | |  _    ||    ___|
|   |  | ||   |___ |       || ||_|| ||   | | | |   ||   |___ 
|___|  |_||_______||______| |_|   |_||___| |_|  |__||_______|
https://aws.amazon.com/amazon-linux-ami/$version-release-notes/
EOF

その後、毎日cronで動いている

sudo /sbin/start update-motd

コマンドを実行して/etc/motdを書き換えます。

これでログイン時にサーバの名前が出てくる様になりました!

Last login: Tue Jun 26 12:06:13 2018 from (伏せ)
 ______    _______  ______   __   __  ___   __    _  _______ 
|    _ |  |       ||      | |  |_|  ||   | |  |  | ||       |
|   | ||  |    ___||  _    ||       ||   | |   |_| ||    ___|
|   |_||_ |   |___ | | |   ||       ||   | |       ||   |___ 
|    __  ||    ___|| |_|   ||       ||   | |  _    ||    ___|
|   |  | ||   |___ |       || ||_|| ||   | | | |   ||   |___ 
|___|  |_||_______||______| |_|   |_||___| |_|  |__||_______|
https://aws.amazon.com/amazon-linux-ami/2018.03-release-notes/

バナーツールを知った記事: https://qiita.com/yuhtanak/items/fffb264078c3473b059c

2
3
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
2
3