為機器加上登入訊息,在 ubuntu 設置登入歡迎詞
source link: https://blog.niclin.tw/2019/08/08/ubuntu-welcome-banner/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
此文章操作示範採用 Ubuntu 18.04.2 LTS
有時候機器多了,為了避免分不清楚 staging / production 會操作錯誤,所以有幾種作法
- 建立空白檔案,例如
IS_PRODUCTION
放在登入後的家目錄 - 改登入歡迎訊息
- 增加 SSH 連線成功後訊息
第一種比較簡單就不多敘述了,這篇文章主要講 2 和 3 的操作方法
關閉機器登入時的廣告訊息
有些機器上會在登入時有廣告訊息,例如開 aws 之類的會有推銷訊息,什麼 k8s 組件啊之類的
可以將其關閉顯示
sudo vim /etc/default/motd-news
# 設置 0 為關閉
ENABLED=0
這樣就可以關閉了,如果要查看的話不用重新登入登出,可以直接輸入 sudo run-parts /etc/update-motd.d
可以查看目前的歡迎訊息
自製歡迎訊息
會執行 00 到 99,依照順序顯示
切到目錄 cd /etc/update-motd.d/
查看檔案
這裡面會發現前面有數字作 prefix 的檔案,範圍會是 00~99,依照數字順序顯示,一開始看到的 Welcome 訊息通常都在 00-header 上面。
舉例來說,我們可以客製化登入訊息,例如我會做一個登入訊息用的 footer 顯示
touch 99-footer
並且在裡面輸入
#!/bin/bash
echo "這是 Production"
並且修改檔案權限,這裡記住一定要改權限,不然 ubuntu 會讀不到
sudo chmod +x /etc/update-motd.d/99-footer
試著重新登入或是 sudo run-parts /etc/update-motd.d
應該就會看到了
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-45-generic x86_64)
...
...
227 packages can be updated.
125 updates are security updates.
*** System restart required ***
這是 Production
修改 SSH 登入 Banner
另一種方式則是在登入後直接顯示,這裡會顯示在歡迎訊息的上方
vim /etc/ssh/sshd_config
在最後一行增加
Banner /etc/ssh/sshd_banner
然後建立檔案
touch /etc/ssh/sshd_banner
在 sshd_banner 裡面輸入字串
"這是 Production"
接著重啟 sshd
/etc/init.d/ssh restart
斷線後重連就可以看到登入後的訊息了。
ssh root@your_host
"這是 Production"
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-45-generic x86_64)
...
...
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK