Set MOTD on Ubuntu 18.04

Modifying the message of the day text to remove all the stuff I don't want to see, and showing the name of my host when logging into my VM via SSH.

All the banner/message of the day files are stored in /etc/update-motd.d/ folder. They are ran in numerical order, as long as the file is set to be executable.

root@hostname:~# ll /etc/update-motd.d/
total 57
drwxr-xr-x  2 root root   10 Apr 22 21:32 ./
drwxr-xr-x 86 root root  170 Apr 22 21:33 ../
-rwxr-xr-x  1 root root 1233 Apr 22 21:18 00-header*
-rw-r--r-x  1 root root 1157 Aug  6  2018 10-help-text*
-rwxr-xr-x  1 root root 4646 Sep 27  2019 50-motd-news*
-rw-r--r-x  1 root root  604 Mar 21  2018 80-esm*
-rw-r--r-x  1 root root 3017 Mar 21  2018 80-livepatch*
-rwxr-xr-x  1 root root  299 May 18  2017 91-release-upgrade*

Files are listed above are displayed roughly below;

  • 00-header - basic system information:
    Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 5.3.18-2-pve x86_64)
  • 10-help-text:
 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
  • 50-motd-news: looks like this checks for news from the Ubuntu website and is updated periodically:
 * Kubernetes 1.18 GA is now available! See https://microk8s.io for docs or
   install it with:

     sudo snap install microk8s --channel=1.18 --classic

 * Multipass 1.1 adds proxy support for developers behind enterprise
   firewalls. Rapid prototyping for cloud operations just got easier.

     https://multipass.run/
  • 80-esm - looks like this will display extended security update information if this is enabled / supported on your system
  • 80-livepatch - displays a message about Livepatch, content will change if Livepatch is enabled:
 * Canonical Livepatch is available for installation.
   - Reduce system reboots and improve kernel security. Activate at:
     https://ubuntu.com/livepatch
  • 91-release-upgrade - presumably displays that your system is due an upgrade.

I don't want to see the information from 10-help-text, 50-motd-news, 80-esm, 80-livepatch, to stop these from running we just need to set the files as not executable with the chmod -x command.

Navigate to the folder, cd /etc/update-motd.d/, run the chmod -x command chmod -x 10-help-text 50-motd-news 80-esm 80-livepatch. To re-enable a message run chmod with the +x chmod +x 50-motd-news

Now to add the hostname using some ascii text, this can be done using a program call figlet which can be installed using apt install figlet. Or you can simply use DuckDuckGo with figlet followed by the text to generate the text. e.g https://duckduckgo.com/?q=figlet+slant+nginx - the 'slant' part of the text specifies the name of the font, a full list can be found on the figlet website

We then copy the figlet text from DDG and paste it into a new file on the system, I've called it hostname.asc - open the file with nano /etc/update-motd.d/hostname.asc and paste the text straight in, ensuring that it has maintained its formatting.

hostname.asc

                _
   ____  ____ _(_____  _  __
  / __ \/ __ `/ / __ \| |/_/
 / / / / /_/ / / / / _>  <
/_/ /_/\__, /_/_/ /_/_/|_|
      /____/

Then add another MOTD file in the update-motd.d folder, numbered so that it appears in the correct order. I've called my file 01-hostname. Open the file with nano /etc/update-motd.d/01-hostname and enter in the following text to output the hostname.asc file to screen on login:

01-hostname
#!/bin/sh
printf "$(cat /etc/update-motd.d/hostname.asc)"

As the file is not executable yet it still won't display on login - chmod will need to be used to make the file executable: chmod +x 01-hostname

After a reboot/logout and back in, when you try to login again you should get the updated motd: