Message of the Day

The message of the Day (MOTD) is a banner message displayed automatically to users when they log into a linux system via a terminal or SSH. its commonly used to display system information, security warnings, maintenance notifications, or any custom message an administrator wants to communicate to users.


The default MOTD message is stored in /etc/motd file, for dynamic MOTD updates are handled by scripts located in /etc/profile.d/

How to configure the MOTD

There are two different method/types for the message of the Day (MOTD)

  • Static Message

  • Dynamic Message 

Displaying a static MOTD


To create a simple, static message

Step1:

Edit the /etc/motd file

$ vi /etc/motd

Step2:

Add content to the file and save it

############################

Welcome to Linux Production Server

Unauthorized access is prohibited!

Contact IT at support@example.com for support

############################


Step3:

Verify the MOTD by logging out and logging in back.

Displaying a Dynamic MOTD


To create a dynamic MOTD message through scripts


Step1:

Create a custom script in /etc/profile.d/

$ vim /etc/profile.d/motd.sh

Step2:

Add/Write message script the file and save it.


echo "

#######################

You're using `hostname`

You're user name is `whoami`

`date`

#######################

This message is from /etc/profile.d/motd.sh

######################

 "


Step3: 

Make script executable:

$ chmod a+x /etc/profile.d/motd.sh


Step4:

Verify the MOTD by logging in the server from the new terminal/shell.


Enabling and Disabling MOTD in SSH configuration file.


If you want to disable the MOTD for SSH Logins

Step1:

Edit the SSH Configuration file /etc/ssh/sshd_config

Step2:

File and modify the following line as needed.

PrintMotd  yes/no


Step3: 

Reload the SSH Service:

$ systemctl reload sshd


Real-World Example of Dynamic MOTD


An advanced dynamic MOTD script to display system health:


#!/bin/bash

# /etc/profile.d/system_status.sh


echo "

-------------------------------------------

Welcome to `hostname`

-------------------------------------------

Date         : `date`

Uptime       : `uptime -p`

Memory Usage : `free -mh`

CPU Load     : `top -bn1 | grep "load average" | awk '{print $12, $13, $14}'`

-------------------------------------------

"

Summary


  • MOTD Location: /etc/motd for static messages and /etc/profile.d/ for dynamic scripts

  • Purpose: Display important system messages, warnings, or information of the system.

  • Dynamic Updates: Add scripts in /etc/profile.d/ for real-time updates.

  • SSH Config.: Control MOTD display with PrintMotd directive.


MOTD (Message Of The Day) is a simple yet powerful tool for Linux Administrators to communicate with users effectively.


No comments:

Post a Comment