debian, linux, raspberrypi, shell

Customize your MOTD login message in Debian and Ubuntu

This is a little guide to display dynamic login messages on a Debian system.

This is one of those things where the internet has plenty of resources, but they are mostly outdated and contradictory. Even typing man motd in Debian is a sad experience.

It is not a difficult thing to do but it can be a big waste of time to sort out the contradictions.

Hopefully, this post will help get the big picture from one single place.

Short history

Ancient times

Time ago, most distributions just printed the contents of /etc/motd upon login.

MOTD stands for message of the day (although it was static), and was put in place at installation time, only to be changed at upgrade time maybe.

Some distributions such as Arch keep operating this way.

Ubuntu came along

Then, Ubuntu Intrepid Ibex (2008) introduced a package update-motd, which consisted of

  • a script called update-motd.
  • an entry in /etc/cron.d calling update-motd every 10 minutes.
  • a folder /etc/update-motd.d

The script runs all the scripts in /etc/update-motd.d using run-parts, then stores all output in /var/run/motd.

/etc/motd was then made into a symbolic link to /var/run/motd

And pam_motd copied it

Then, PAM thought that that was actually a cool idea and copied it from Ubuntu. In modern Linux, PAM is in charge of login authentication.

SSH uses the pam_motd module

Ok, now we have yet another file, /run/motd.dynamic.

We can see that they almost literally copied the code.

For this reason, even in Debian if we create the folder /etc/update-motd.d, which does not exist by default, it will be run at every login in the same way as if we had Ubuntu’s update-motd package installed.

Confusing huh? Well it gets worse because over time, Debian and Ubuntu have changed things, like the scripts populated in /etc/update-motd.d and the use of special files.

Files involved

  • /etc/motd – The classic, static file. Does not exist anymore in Ubuntu 16.04 LTS, not even as a symbolic link to /var/run/motd. If it is created, however its contents will be printed too.
  • /var/run/motd – This was used by Ubuntu’s first implementation. It is not used anymore. It is just ignored by PAM.
  • /var/run/motd.dynamicThis is what is shown on login currently. It is updated by /etc/init.d/motd at every boot. It is also updated by PAM by running the scripts in /etc/update-motd.d/, if they exist.
  • /etc/motd.tail – The Ubuntu package used to populate /etc/update-motd.d. One of them would cat the contents of this file so it was easy to add static content. That script does not exist in the package anymore, so the file does not have the intended effect.

How to then?

Okay, so once we understand why Google confuses us, it is pretty easy to customize our MOTD.

First, make sure to disable /etc/init.d/motd,  as it writes to /var/run/motd.dynamic.

In my Raspbian Jessie, for instance it already came disabled. Just in case

Then, just delete current static MOTD, create /etc/update-motd.d folder and place scripts in it.

Scripts are run by run-parts, so they need not have an extension. They must start with digits so they will be run in order.

Finally, you can opt to get rid of the “last login” message if you want

This is a simple example

Next login we will get

Some ideas

FIGlet

You can use good old FIGlet. It will take your input and create some text based ASCII art.

You can even get “fonts” for it here

System info

You can play with lm-sensors to get information such as fan speed or temperature.

Also, you can print any of the typical system info provided by standard tools.

adapted from here.

Here is one example output

Termpix

You can get even fancier using tools like termpix. This tool creates ASCII art from pictures, and shows better if we have half block capable fonts available.

This is what I used for the MOTD in NextCloudPi.

landscape-sysinfo

This one is Ubuntu only.

Banner

Boxes

Another classic

List all different designs with

lolcat

You can spice up your creations with trippy rainbow colors with lolcat

Play with it

No need to risk your system. Test your ideas in a Docker container.

You can use ownyourbits minidebian container.

, and the official Ubuntu container.

References

https://wiki.ubuntu.com/UpdateMotd

https://wiki.debian.org/motd

Author: nachoparker

Humbly sharing things that I find useful
[ github dockerhub ]

One Commnet on “Customize your MOTD login message in Debian and Ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *