The Message of the Day (MOTD) is the message that gets displayed to users when they log in to a Linux system via the command line or SSH. As a Linux system administrator, customizing this message can be useful for providing information, warnings, announcements, or branding to users. In this comprehensive guide, we‘ll cover everything you need to know to customize the MOTD on Linux.
An Overview of the MOTD in Linux
The MOTD display when a user logs in serves several potential purposes:
- Provide warnings or special instructions to users when needed
- Notify users of system changes or planned maintenance
- Display branding, contact info, or basic system details
- Announce company news or events to internal users
The MOTD is an effective way to communicate information to users because it forces them to see it when logging in, ensuring the message is delivered.
By default, most Linux distributions come with a pre-configured MOTD generated dynamically from scripts in the /etc/update-motd.d
directory. This displays info like the OS release, kernel version, and hardware stats. But the MOTD can be customized by admins as needed.
There are a few ways to configure a custom MOTD, covered next.
1. Create an /etc/motd File
The most basic way to set a static MOTD is by creating an /etc/motd
file. This file gets displayed as-is to all users after login.
For example, to create an MOTD with a simple branded message:
$ sudo nano /etc/motd
MyCompany Server 9.2
Contact admin@mycompany.com for assistance
After writing the message, save and close the file. The next time someone SSHs in, they will see:
MyCompany Server 9.2
Contact admin@mycompany.com for assistance
user@host:~$
With this method, the MOTD will stay static rather than show dynamic system info. But the file can be edited again at any time to make changes.
2. Customize the /etc/motd.tail File
Most modern Linux distros actually ignore a standalone /etc/motd
file and instead generate the MOTD dynamically on each login from scripts and templates.
These distros have an /etc/motd.tail
file that gets appended to the dynamically generated MOTD content. So this file can be used to add custom static content.
For example:
$ sudo nano /etc/motd.tail
--------------------
MyCompany Server 9.2
Contact admin@mycompany.com for assistance
--------------------
This will add the message after all the default system info, kernel version lines, etc.
Using /etc/motd.tail
allows you to retain dynamic MOTD generation, while still inserting custom content.
3. Create Scripts in /etc/update-motd.d
The most flexible way to generate a custom MOTD is by creating scripts in the /etc/update.motd.d
directory.
When generating the MOTD text, the system runs all executable scripts in this directory in lexical order (based on file names) and concatenates the output.
For example, to add a branded banner message, you could create /etc/update-motd.d/99-banner
:
#!/bin/bash
cat <<"EOF"
_ _ _ _ ___ ____ _____ __ __
| | | | \ | |_ _/ ___|_ _| \/ |
| |_| | \| || |\___ \ | | | |\/| |
\___/|_|\_\__| |___/ |_| |_| | | |
|_| |_|
------------------------------------
MyCompany Server 9.2
Contact admin@mycompany.com for assistance
EOF
The advantage here is you can create scripts that perform dynamic actions to generate MOTD content. For example, showing disk usage, number of updates available, number of logged in users, or anything else.
And the order files get concatenated in is controlled by the prefix in the script filenames. Use a prefix like 00-
or 01-
to display info towards the top.
In most Linux distros, you‘ll also want to remove executable permissions on the existing scripts to avoid duplicate content:
$ sudo chmod -x /etc/update-motd.d/*
Now only your custom scripts will execute when generating the MOTD text.
4. Leverage a MOTD Generator Tool
Rather than writing MOTD scripts from scratch, there are also some handy tools that can generate dynamic MOTDs:
- molly-guard – Generates MOTD with system stats and ASCII art
- pam_motd – Dynamic MOTDs with system info summaries
- update-motd – Universal MOTD script with many built-in options
For example, to use pam_motd, just install the package:
$ sudo apt install pam_motd # Ubuntu/Debian
$ sudo yum install pam_motd # RHEL/CentOS
This will automatically create a dynamic MOTD including summary info like:
hostname.domain.com running Linux x.x.x-xxx-generic
Uptime: x days y hours z minutes
3 packages can be updated, 0 updates are security updates
New release ‘20.04.2 LTS‘ available.
Last login: Mon Jan 14 11:38:01 2020 from 192.168.0.1
Very handy without much effort! Each tool provides configuration files to customize further as well.
5. Display a Random MOTD from a Folder
Another neat trick for customizing the MOTD is to create a folder with multiple MOTD text files, and randomly display one at each login.
For example:
$ sudo mkdir /etc/update-motd.d/motd
$ sudo nano /etc/update-motd.d/motd/00-header
$ sudo nano /etc/update-motd.d/motd/01-footer
Then add a script to randomly cat one of the files:
#!/bin/bash
FILES=/etc/update-motd.d/motd/*
cat /dev/urandom | md5sum | cut -d‘ ‘ -f1 > /tmp/.rand
num=$(cat /tmp/.rand)
let "num %= $(ls $FILES | wc -l)"
cat $FILES | sed -n ${num}p
When users log in, this will show a random MOTD from your message pool. Useful for periodically changing the MOTD content shown to keep it fresh.
Persisting the MOTD Across Terminal Sessions
One caveat of the MOTD is that it only displays once upon initial shell login. If a user opens any additional terminals, the MOTD won‘t repeat.
To persist it across all terminal sessions, you can install and configure motd-news:
$ sudo apt install motd-news
$ sudo nano /etc/default/motd-news
DISPLAY_HEADER=y
This will continually rerun the MOTD command and display the message at the top of every terminal.
Customizing the MOTD Banner Color/Style
If you want to get really fancy with your MOTD customization, there are also some ways to configure the styling of the message:
ANSI Color Codes
You can insert ANSI color codes into MOTD scripts to change text color, make text bold/dim, even add background colors.
For example:
#!/bin/bash
echo -e "\033[1;31mMyCompany Server 9.2\033[0m" # Bold red text
echo -e "\033[44mContact admin@company.com\033[0m" # Blue background
You can reference an ANSI cheat sheet for different formatting codes.
ASCII Art Banners
For a really flashy MOTD, you can integrate ASCII art banners into your scripts. Sites like patorjk.com or figlet.org let you generate ASCII art fonts.
For example:
_ _ _ _ __ __
| | | | ___| | | ___ \ \ / /__ ___
| |_| |/ _ \ | |/ _ \ \ \ /\ / / _ \/ __|
| _ | __/ | | (_) | \ V V / __/\__ \
|_| |_|\___|_|_|\___/ \_/\_/ \___||___/
Integrating ASCII banners instantly makes your MOTD stand out!
Wrapping Up
Customizing the message of the day is a simple way to deliver important, inspiring, or brand-reinforcing information to users everytime they log in.
The options covered provide extensive flexibility:
- Static banners using
/etc/motd
- Appending messages with
/etc/motd.tail
- Dynamic script generation in
/etc/update-motd.d/
- Leveraging MOTD generator tools for out-of-box options
- Randomized MOTD display for variety
Taking advantage of these features allows crafting a customized MOTD experience for any Linux environment. Both server admins and desktop users can benefit.
So try spicing up your Linux login banners today! Feel free to share any other creative MOTD customizations in the comments below.