Change the login message

To know which server is own login, we should show welcome message before login. This article illustrates how to set display messages before/after login on the banner.

Before Login
To show welcome message before login, you should edit ssh configure file, /etc/ssh/sshd_cofig. Add banner message which is follows. We add a banner text file to /etc/profile.d, and specify this file path in the ssh configure file. The path, /etc/profile.d, stores all files that are executed when the user login.
[root@centos-6 ~]# vim /etc/ssh/sshd_config
# no default banner path
Banner /etc/profile.d/banner.txt

The file, banner.txt, can be whatever file you want and store in anywhere. However, we store it in the /etc/profile.d. Then edit the file and put in whatever welcome message you want.
,--.   ,--.       ,--.                              
| | | | ,---. | | ,---. ,---. ,--,--,--. ,---.
| |.'.| || .-. :| || .--'| .-. || || .-. :
| ,'. |\ --.| |\ `--.' '-' '| | | |\ --.
'--' '--' `----'`--' `---' `---' `--`--`--' `----'

After all settings, you need to restart sshd before your changes take effect.
[root@centos-6 ~]# service sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]

When you connect to the server, the welcome message will show in the terminal.
newmac:~ user$ ssh nick1811@192.168.0.90
,--. ,--. ,--.
| | | | ,---. | | ,---. ,---. ,--,--,--. ,---.
| |.'.| || .-. :| || .--'| .-. || || .-. :
| ,'. |\ --.| |\ `--.' '-' '| | | |\ --.
'--' '--' `----'`--' `---' `---' `--`--`--' `----'
nick1811@192.168.0.90's password:


After Login
In this part, I will show you how to set display message after login. To change the display message, you should edit /etc/motd. But in this article, we do not revise /etc/motd. We add a file, motd.sh, into the path, /etc/profile.d. All of files in this path will be automatically executed by /etc/profile when the user login.
[root@centos-6 ~]# vim /etc/profile.d/motd.sh
#!/bin/bash
echo -e "
######################
# Welcome to Cent OS #
######################
"

So you can see the result after this setting.
Last login: Tue May 17 11:27:49 2016 from 192.168.1.138

######################
# Welcome to Cent OS #
######################

[nick1811@centos-6 ~]$
profile-image
Hello, My name is Nick, Taiwanese🇹🇼. I like to develop iOS Apps and use Unix-based operating systems. And, I love reading and traveling to fill to my life. This blog recorded all technical articles which I have faced and solved problems. Please leave your comment to discuss with me.
comments powered by Disqus