無論何時登錄公司的某些生產系統,你都會看到一些登錄消息、警告或關于你將登錄或已登錄的服務器的信息,如下所示。這些是登錄導語login banner。
在本文中,我們將教你如何配置它們。
你可以配置兩種類型的提示信息。
用戶登錄前顯示的提示信息(在你選擇的文件中配置,例如 /etc/login.warn)
用戶成功登錄后顯示的提示信息(在 /etc/motd 中配置)
如何在用戶登錄前連接系統時顯示消息
當用戶連接到服務器并且在登錄之前,這個消息將被顯示給他。意味著當他輸入用戶名時,該消息將在密碼提示之前顯示。
你可以使用任何文件名并在其中輸入信息。在這里我們使用 /etc/login.warn 并且把我們的消息放在里面。
1
2
3
4
5
|
# cat /etc/login.warn !!!! welcome to kerneltalks test server !!!! this server is meant for testing linux commands and tools. if you are not associated with kerneltalks.com and not authorized please dis-connect immediately. |
現在,需要將此文件和路徑告訴 sshd 守護進程,以便它可以為每個用戶登錄請求獲取此標語。對于此,打開 /etc/sshd/sshd_config 文件并搜索 #banner none。
這里你需要編輯該配置文件,并寫下你的文件名并刪除注釋標記(#)。
1
|
banner /etc/login .warn |
保存文件并重啟 sshd 守護進程。為避免斷開現有的連接用戶,請使用 hup 信號重啟 sshd。
1
2
3
4
5
|
root@kerneltalks # ps -ef | grep -i sshd root 14255 1 0 18:42 ? 00:00:00 /usr/sbin/sshd -d root 19074 14255 0 18:46 ? 00:00:00 sshd: ec2-user [priv] root 19177 19127 0 18:54 pts /0 00:00:00 grep -i sshd root@kerneltalks # kill -hup 14255 |
就是這樣了!打開新的會話并嘗試登錄。你將看待你在上述步驟中配置的消息。
你可以在用戶輸入密碼登錄系統之前看到此消息。
如何在用戶登錄后顯示消息
消息用戶在成功登錄系統后看到的當天消息message of the day(motd)由 /etc/motd 控制。編輯這個文件并輸入當成功登錄后歡迎用戶的消息。
1
2
3
4
5
6
|
root@kerneltalks # cat /etc/motd w e l c o m e welcome to the testing environment of kerneltalks. feel free to use this system for testing your linux skills. in case of any issues reach out to admin at [email protected]. thank you. |
你不需要重啟 sshd 守護進程來使更改生效。只要保存該文件,sshd 守護進程就會下一次登錄請求時讀取和顯示。
你可以在上面的截圖中看到:黃色框是由 /etc/motd 控制的 motd,綠色框就是我們之前看到的登錄導語。
你可以使用 cowsay、banner、figlet、lolcat 等工具創建出色的引人注目的登錄消息。此方法適用于幾乎所有 linux 發行版,如 redhat、centos、ubuntu、fedora 等。