Americas

  • United States
sandra_henrystocker
Unix Dweeb

How to use the motd file to get Linux users to pay attention

How-To
Aug 29, 20175 mins
LinuxSystem Management

Configuring login messages on Linux servers is more complex and dynamic. Let's look at the message of the day setup on an Ubuntu server to decipher how the process works.

It seems only decades ago that I was commonly sending out notices to my users by editing the /etc/motd file on the servers I managed. I would tell them about planned outages, system upgrades, new tools and who would be covering for me during my very rare vacations.

Somewhere along the stretch of time since, message of the day files seem to have faded from common usage — maybe overwhelmed by an excess of system messages, emailed alerts, texts, and other notices that have taken over, the /etc/motd file has. Or maybe not.

+ Also on Network World: Half a dozen clever Linux command line tricks +

The truth is the /etc/motd file on quite a number of Linux systems has simply become part of a larger configuration of messages that are fed to users when they log in. And even if your /etc/motd file is empty or doesn’t exist at all, login messages are being delivered when someone logs into a server via a terminal window — and you have more control over what those messages are telling your users than you might realize.

Here’s an example of the messages that might be displayed on an Ubuntu server when someone logs in:

login as: jdoe
jdoe@192.168.0.7's password:
Welcome to Ubuntu 17.04 (GNU/Linux 4.10.0-32-generic i686)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

 * What are your preferred Linux desktop apps?  Help us set the default
   desktop apps in Ubuntu 18.04 LTS:
   - https://ubu.one/apps1804

10 packages can be updated.
0 updates are security updates.

Last login: Fri Aug 28 18:41:49 2017 from 192.168.0.11

As you can see, there’s quite a lot of information there — details about the OS, some pointers showing where you can go to get more information on the OS, an appeal for your opinion on useful desktop alls, and some notices about package and security updates. Some of these messages are aimed at sysadmins. Others are useful for all users.

Even though no /etc/motd file existed on this server when these login messages were captured, the system has a lot to tell us and any user who logs in.

$ ls -l /etc/motd
ls: cannot access '/etc/motd': No such file or directory

Instead, the configuration of login messages is much more complicated and dynamic than it was when the /etc/motd file came into being and was then used for many years as a primary way to communicate with users. Now, let’s take a look at where all of this information is coming from today — at least on one very popular Linux platform. For Ubuntu, one place to start looking is a directory named /etc/update-motd.d.

root@stinkbug:/etc/init.d# ls -l /etc/update-motd.d
total 36
-rwxr-xr-x 1 root root 1239 Aug 25 11:40 00-header
-rwxr-xr-x 1 root root 1157 Jun 14  2016 10-help-text
-rwxr-xr-x 1 root root 4196 Feb 15  2017 50-motd-news
-rwxr-xr-x 1 root root   97 Jan 27  2016 90-updates-available
-rwxr-xr-x 1 root root  299 Apr 11 11:55 91-release-upgrade
-rwxr-xr-x 1 root root  129 Aug  5  2016 95-hwe-eol
-rwxr-xr-x 1 root root  142 Jul 12  2013 98-fsck-at-reboot
-rwxr-xr-x 1 root root  144 Jul 12  2013 98-reboot-required

Each of these files has a role to play in building the sequence of login messages that is displayed. Looking first at a file called /etc/default/motd-news, the command shown below picks out the operative lines (non-blank and not comments), we see this:

# cat /etc/default/motd-news | grep -v ^# | grep -v "^$"
ENABLED=1
URLS="https://motd.ubuntu.com"
WAIT=5

Change the ENABLED setting to 0 and the motd.ubuntu.com message will no longer be included in the login messages. You can examine what the motd-news is right now by putting the URL into a browser, but expect that it will change from time to time.

The 00-header file composes the line describing the OS release by sourcing the /etc/lsb-release file and using what it finds to construct a message like this:

Welcome to Ubuntu 17.04 (GNU/Linux 4.10.0-32-generic i686)

The 10-help-text file add these lines:

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

The 50-motd-news file adds the content of this URL

https://motd.ubuntu.com

The 90-updates-available file contributes the lines about package and security updates using the /var/lib/update-notifier/updates-available file.

You can insert text that you want included in the login messages by creating or editing the /etc/motd file. Of course, if your users simply gloss over the login messages because they become more or less routine, you might want to highlight messages that you really want them to notice. I sometimes set mine up to look something like this:

****************************
*     Pay attention!       *
*                          *
* This server will be down *
*   over the weekend for   *
*    required upgrades     *
****************************

Message of the day files can turn out to be message of the month files or message of the moment files, depending on how you want to use them. The content can be routine or very important. Getting users to notice included content will depend on getting their attention and educating them about what to expect.

sandra_henrystocker
Unix Dweeb

Sandra Henry-Stocker has been administering Unix systems for more than 30 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She lives in the mountains in Virginia where, when not working with or writing about Unix, she's chasing the bears away from her bird feeders.

The opinions expressed in this blog are those of Sandra Henry-Stocker and do not necessarily represent those of IDG Communications, Inc., its parent, subsidiary or affiliated companies.