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.
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.
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.
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
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
11 Comments
Join Our Newsletter
Categories
- Bash Scripting (17)
- Basic Commands (50)
- Featured (7)
- Just for Fun (5)
- Linux Quick Tips (98)
- Linux Tutorials (65)
- Miscellaneous (15)
- Network Tools (6)
- Reviews (2)
- Security (32)
- Uncategorized (1)
How do i display a note after all the neofetch system information has been displayed?
Add a line to the bottom of the .sh file you created.
echo "Your message here"
This is a great tutorial and explains everything great. thanks!
After some testing I have found that scripts in
/etc/update-motd.d/
shouldn't have an extension in order to work, for example/etc/update-motd.d/90-custom
. Also if you use this folder it'sroot
who executes the scripts.However, if you put your script in
/etc/profile.d/
you have to add an extension to work properly, ie/etc/profile.d/90-custom.sh
.I moved mymotd.sh to /etc/update-motd.d and gave it a 00 prefix, yet it still showed up on the last line after I logged in. Why is this?
What is in your script and are there other scripts in the /etc/update-motd.d folder?
Hey there!
Which font did you use to create the banner for your Server named "fenir"?
The font was called "poison" and can be found here: http://www.network-science.de/ascii/
P.S. This is a much better ASCII art generator because you don't need to click 'do it' button to test every change, you can simply click on 'test all' and every version will be created for you.
http://www.patorjk.com/software/taag
How can I issue the clear command so that anything prior on the screen will be removed before my mymotd.sh is displayed?
If you are using a script you can use the "clear" command.