How to change the message of the day (motd) on Linux

How to change the message of the day (motd) on Linux

In this tutorial I will show you, how to change the message of the day (motd) on Linux server.

When you fist log in to a terminal on a Unix system, Linux included, you are usually greeted by that system’s message of the day(MOTD). The message of the day, gives you important information about the system or just messages from the system admin. Of course, if you are are the system admin, it’s up to you to set that message. If it’s your own system, you can get creative with your message and include any information that you choose.

First off, you can easily set a plain text message of the day on most systems by adding some text to the /etc/motd file. That’s boring, though, you can do a lot more than that.

Debian/Ubuntu

Debian and Ubuntu systems handle things in their own way. They have a directory at /etc/update-motd.d/with different shell scripts, each of which displays a different piece of information. They’re organized in ascending numeric order and will execute in just that order. Take a look at way they’re set up.

00-header

Because the number at the font is 00 it will execute first. With it being the header, that’s a good thing.

You’re free to modify these files or stop them from running. Each one is just a shell script, so there’s nothing vital that can’t be modified or outright removed.

You can also add it your own scripts and insert them in the correct order with the numbering system. Again, because they are just scripts, you’re free include anything that you can output in to a terminal window.

For example, if you wanted to add in a footer that greets your users, you could do something like this in a file called, 99-footer.

#! /bin/bash

figlet -f slant Welcome!

Make sure that it’s executable, and the next time you log in to a terminal session or over SSH, you’ll see it appended to the bottom of your usual message of the day.

#! /bin/bash

HOSTNAME=`uname -n`

KERNEL=`uname -r`

CPU=`uname -p`

figlet -f digital Welcome to $HOSTNAME!

echo “You’re running $KERNEL on $CPU

There really isn’t any limit to what you can do.

Everyone Else

Just about every other distribution does it a different way. They use a different file located at  /etc/profile.d/motd.sh.

Once again, that file is a shell script that you can use to do just about anything. Since you aren’t encumbered by a lot of the other stuff that Ubuntu throws in there, you can really get creative. Try using a script to display a random quote each time you log in.

#! /bin/bash

MSGS=(“Quote 1” “Quote 2” “Quote 3” “Quote 4”)

MSG=${MSGS[$RANDOM % ${#MSGS[@]} ]}

figlet -f small $MSG;

echo “\n”;

Alternatively, use a fortune command to generate a random quotes for you. Example:

#! /bin/bash

figlet -f small $( fortune )

If you want to simplify and/or streamline things, you might even consider using Neofetch in your script to display all your system information in a well-organized block.

neofetch;
echo “\n”;

The choice is, once again, yours.

Conclusion:

There’s not a whole lot to say. You have free reign to make your system’s message of the day whatever you choose. Once again, if you can script it, you can do it. So, feel free to get creative and experiment.

 
Enjoyed this video?
How to change the message of the day (motd) on Linux
"No Thanks. Please Close This Box!"