Wednesday, September 14, 2016

How to display welcome message if user has logged in from a particular IP (or host)?

1. Edit /etc/ssh/sshd_config and change "PrintLastLog" to "no". Save file and restart sshd

2. If you want to display this message for a specific user edit (or create) ~user/.bash_profile and add these lines at the end of the file:

==========cut here==========
REMOTE_IP=`echo $SSH_CONNECTION | cut -f1 -d " "`
if [ $REMOTE_IP == '10.5.226.172' ] ;
then echo "So, it's you again..." ;
else echo "Hi, stranger...";
fi
==========cut here==========

3. If you want this for all users, the same snippet goes to /etc/profile of in a new file in /etc/profile.d

No comments:

Post a Comment