Thursday, 21 May 2020

Add color to Message of the Day (MOTD in Centos/RHEL

Introduction

In this quick article, I'll demonstrate how to add some color to your message of the day (MOTD) which is some text that is displayed on the screen when you first log in.

We'll not be using the /etc/motd file for this so this file should be empty.

We'll create a script in /etc/profile.d/ that contains the text we'd like to print. Here I've named the script login-info.sh.

[ssuri@lab-node:~] $ cat /etc/profile.d/login-info.sh
#! /usr/bin/env bash

GREEN="\033[01;32m"
YELLOW="\033[01;33m"
MAGENTA="\033[01;35m"
CYAN="\033[01;36m"
NC="\033[00m"

echo -e "${GREEN}================================${NC}"
echo -e "${YELLOW}Welcome to the Ansible LAB Box${NC}"
echo -e "${GREEN}================================${NC}"
[ssuri@lab-node:~] $

I've used escape sequences with the echo command to display text in green and yellow colors when printed.

Next, we need to add the following line in /etc/ssh/sshd_config file and restart the sshd service.

PrintMotd no

That's it. The next time we login we'll be greeted with a colorful login message.

Conclusion

I've used green and yellow colors in this example but you can use a different color sequence. You may also use the output of commands within the script to make the login message more informative.

No comments:

Post a Comment

Using capture groups in grep in Linux

Introduction Let me start by saying that this article isn't about capture groups in grep per se. What we are going to do here with gr...