Back in the old days, before graphical interfaces, system administrators would leave a message for users by using the Message of the Day "MOTD" file. These days the motd still exists but is rarely ever used. I personally haven't seen someone use the motd file since 2011, when Bob the Unix admin retired at the age of 71. He was still sharp as a tack, but I digress. The motd option is still available in most modern Linux systems. In this fun article we will show you how to set the motd and even create a nice custom login banner with ascii art and system information.

Setting a Basic Text MOTD in Linux

You can easily set a basic text based message of the day by editing the /etc/motd file. Any text that you place in the file will be displayed upon login by any user.

Example:

$ cat /etc/motd
 #######################################
 # THIS IS A TEST MESSAGE IN /etc/motd #
 #######################################

Now when someone logs in via the terminal or ssh they will see the message.

$ ssh 10.0.0.2
 [email protected]'s password: 
  #######################################
  # THIS IS A TEST MESSAGE IN /etc/motd #
  #######################################
 Last login: Fri May 17 19:41:58 2019 from 192.168.122.164

This should work on any Unix or Linux machine regardless of distro. I have tested it on Ubuntu 18.04.2, Fedora 30, CentOS 7 and Red Hat 8.

Custom Login Script in Etc Profile

Another, more flexible, option is to create a script and place it in the /etc/profile.d/ folder. Any script in this folder will run when a user logs in.

Using a script in /etc/profile.d allows you almost limitless possibilities. I used an ascii art generator to create my server name, then added some color to it, and made this nifty little login banner. I later added the lastlog and uptime commands to show me some information about the server.

Here is an example of the script I made running when I log into my server named Fenrir.

Animated gif showing custom login script for Linux with Ascii art

How to Make Ascii Art Login Banner

If you are interested in making something like the above, follow these steps.

Use an online ascii art generator to create your desired art and copy all of the characters to the clipboard. Create a file and paste in the characters copied above and save the file.

Now run the following command and replace filename with the name of the file you created in the previous step. This will generate your login script.

echo '#!/bin/bash'; while IFS= read -r line; do echo "echo '$line'"; done < filename > mymotd.sh

Now copy mymotd.sh to /etc/profile.d and make it executable.

sudo cp mymotd.sh /etc/profile.d/ && chmod +x /etc/profile.d/mymotd.sh

Now when you log in, you will see the banner in your terminal. You can modify this file anyway you like.

Using neofetch To Create a Custom Login Banner

The neofetch utility is a command line tool that displays the distribution logo and system information for whatever system it is installed on. You can use this as a neat way to create a custom login banner.

neofetch ran on Fedora 30 showing system information

Installing neofetch Utility

You can install neofetch easily with most package managers.

To install neofetch on Fedora:

$ sudo dnf install neofetch

To install neofetch on Ubuntu:

sudo apt-get install neofetch

Using neofetch

Although neofetch has a ton of options, you only need to invoke it without any arguments to get a nice looking ascii logo and some system information (as seen above).

$ neofetch

To use neofetch as your login banner simply run the following command to create a script that runs at login.

sudo bash -c $'echo "neofetch" >> /etc/profile.d/mymotd.sh && chmod +x /etc/profile.d/mymotd.sh'

The Ubuntu/Debian Specify Method

Ubuntu and Debian users can use a method that is specific to these distributions. Ubuntu uses scripts in the /etc/update-motd.d directory to show you information when you login by default. Here is a screenshot from a fresh Ubuntu 18 install.

Screenshot of default Ubuntu motd showing system information

You can edit or add a file to the /etc/update-motd.d folder to run different scripts. To create a custom login banner or motd you can simply use the techniques above and place your scripts here. Each script starts with a double digit number that determines the run order. For example 00 runs first, 99 runs last.

root@UbunutDev:/etc/update-motd.d# ls -l
 total 44
 -rwxr-xr-x 1 root root 1220 Apr  9  2018 00-header
 -rwxr-xr-x 1 root root 1157 Apr  9  2018 10-help-text
 -rwxr-xr-x 1 root root 4264 Aug 20  2018 50-motd-news
 -rwxr-xr-x 1 root root  604 Mar 21  2018 80-esm
 -rwxr-xr-x 1 root root 3017 Mar 21  2018 80-livepatch
 -rwxr-xr-x 1 root root   97 Jun 27  2018 90-updates-available
 -rwxr-xr-x 1 root root  299 May 18  2017 91-release-upgrade
 -rwxr-xr-x 1 root root  129 Jun 27  2018 95-hwe-eol
 -rwxr-xr-x 1 root root  142 Jun 27  2018 98-fsck-at-reboot
 -rwxr-xr-x 1 root root  144 Jun 27  2018 98-reboot-required

Conclusion

Creating a custom login banner or motd is a lot of fun and looks pretty cool. You can also use it the old fashioned way to show users important information they need to know. Bob the Unix admin used the motd to tell people when the system would be down for maintenance or to scold users who did something he didn't approve of.

I hope I covered everything in this article. If you have any questions or comments you can leave them below. Have fun!

Resources and Links