How to change MOTD (Message of the Day) in Linux

Published on March 24, 2023 · Updated on March 24, 2023
How to change MOTD (Message of the Day) in Linux

The MOTD (Message of the Day) is a customizable message that is displayed to users when they log in to a Linux system. The MOTD can be used to display system information, notifications, or other custom messages. In this tutorial, we will show you how to change the MOTD in Linux.

Setting a Basic Text MOTD in Linux

The easiest way to change the MOTD in Linux is to edit the /etc/motd file. This file contains the default MOTD message that is displayed to users when they log in.

To edit the MOTD message, open a terminal and run the following command:

sudo nano /etc/motd

Edit the text in the file to display your custom message. Save and close the file.

The next time a user logs in, they will see the updated MOTD message.

How to Append Additional Information to MOTD Message

You can also append additional information to the default MOTD message by editing the /etc/update-motd.d/ directory. This directory contains scripts that are executed to generate the MOTD message.

To add additional information to the MOTD message, create a new script in the /etc/update-motd.d/ directory. For example, you can create a new script called 99-custom:

sudo nano /etc/update-motd.d/99-custom

Add the following lines to the script to display additional information:

#!/bin/bash
echo "Welcome to my Linux system"
echo "System uptime: $(uptime)"

Make the script executable:

sudo chmod +x /etc/update-motd.d/99-custom

The next time a user logs in, they will see the updated MOTD message with the additional information.

Custom Login Script in /etc/profile

Another way to customize the MOTD message is to create a custom login script in the /etc/profile file. This script will be executed when a user logs in.

To create a custom login script, open the /etc/profile file in a text editor:

sudo nano /etc/profile

Add the following lines to the file to display a custom message:

echo "Welcome to my Linux system"
echo "System uptime: $(uptime)"

Save and close the file.

The next time a user logs in, they will see the custom message.

Create a Custom MOTD or Login Banner in Linux

You can also create a custom MOTD or login banner in Linux by using ASCII art or other graphics. There are several ways to do this.

How to Make ASCII Art Login Banner

One way to create an ASCII art login banner is to use the figlet command. The figlet command can be used to create large ASCII art text.

To install the figlet command, run the following command:

sudo apt-get install figlet

Create a custom banner using figlet:

figlet "Welcome to my Linux system"

Copy the output of the figlet command and paste it into the /etc/motd file or the /etc/profile file.

The next time a user logs in, they will see the custom banner.

Using neofetch To Create a Custom Login Banner

Another way to create a custom login banner is to use neofetch. neofetch is a command-line tool that displays system information in a visually appealing way.

To install neofetch, run the following command:

sudo apt-get install neofetch

Create a custom login banner using neofetch:

neofetch --ascii /path/to/custom/ascii-art

Replace /path/to/custom/ascii-art with the path to your custom ASCII art file.

Copy the output of the neofetch command and paste it into the /etc/motd file or the /etc/profile file.

The next time a user logs in, they will see the custom banner.

How to Disable MOTD Message

If you want to disable the MOTD message, you can delete or rename the /etc/motd file. This will prevent the default MOTD message from being displayed.

sudo rm /etc/motd

Alternatively, you can remove execute permission from all scripts in the /etc/update-motd.d/ directory:

sudo chmod -x /etc/update-motd.d/*

This will prevent the scripts from being executed and the MOTD message from being generated.

Conclusion

In this tutorial, we have shown you how to change the MOTD message in Linux. You can set a basic text MOTD message, append additional information to the MOTD message, create a custom login script, or create a custom login banner using ASCII art or neofetch. If you want to disable the MOTD message, you can delete or rename the /etc/motd file or remove execute permission from all scripts in the /etc/update-motd.d/ directory.

Load Comments