Display a message to a user when logging in through SSH

If you have ever wanted to display a message to your users when the log in through ssh, you just need to edit a couple of files.  The first one is:

vim /etc/motd

This file has the text that will be displayed when an authorized user logs in through SSH.  The next change we need to make is to the SSH configuration file, which tell it to display the MOTD (message of the day).  The file can be found here, on a CentOS 5 system:

vim /etc/ssh/sshd_config

Look for the line containing PrintMotd and change the value to yes.  Make sure it is also uncommented.  If you wish to have a custom message for each user, it can be done a couple of different ways, however, I will only show you one.  We will create a new directory, and within that directory, give each user that has SSH access a file to use for a custom message.  Then, we need to edit the login script that the users use, in this case, bashrc, to include the per user file.

mkdir /etc/usermotd  <– makes the directory that we will use

vim /etc/usermotd/username <– this is where you would add the text you wish to display.

vim /etc/bashrc <– edit the bash file to include our new user motd

You need to add the below to the bottom of the bashrc file:

if [ -f /etc/usermotd/${USER} ]; then
cat /etc/usermotd/${USER};
fi

Save your file, then test it out.