Customize your Login Screen via Linux's Message of the Day (Ubuntu/CentOS)

Nov 17, 2016

Length: 04:48

See how you can customize the screen you see when you login to give you important information quickly.

Command Rundown

We can configure the Message of the Day, which is useful for displaying data to us on login. When you have a lot of servers to log into, this can be VERY handy.

The information you put here can be specific to your use case. At work, I output the customer information that's specific to the server I log into.

However we can use it to get some general information as well. Let's make a script for that. Here's the contents of a shell script I've named

#! /usr/bin/env bash

# Basic info
HOSTNAME=`uname -n`
ROOT=`df -Ph | grep xvda1 | awk '{print $4}' | tr -d '\n'`

# System load
MEMORY1=`free -t -m | grep Total | awk '{print $3" MB";}'`
MEMORY2=`free -t -m | grep "Mem" | awk '{print $2" MB";}'`
LOAD1=`cat /proc/loadavg | awk {'print $1'}`
LOAD5=`cat /proc/loadavg | awk {'print $2'}`
LOAD15=`cat /proc/loadavg | awk {'print $3'}`

echo "
 - Hostname............: $HOSTNAME
 - Disk Space..........: $ROOT remaining
 - CPU usage...........: $LOAD1, $LOAD5, $LOAD15 (1, 5, 15 min)
 - Memory used.........: $MEMORY1 / $MEMORY2
 - Swap in use.........: `free -m | tail -n 1 | awk '{print $3}'` MB

Now we can use that.


Ubuntu makes this pretty easy. We can simply throw the above script into the directory /etc/update-motd.d/.

sudo mv /etc/update-motd.d/05-info
sudo chmod +x /etc/update-motd.d/05-info

Once you log out and back in, we'll see that info!


CentOS takes just a little more work to setup.

  1. We need to turn off (yes, off) SSH's PrintMotd option by editing /etc/ssh/sshd_config:
PrintMotd no

This stops printing from the plaintext /etc/motd and lets us print our own content.

We just need to restart sshd as so that takes affect:

sudo service sshd restart

Now we'll place our shell script into /etc/profile.d.

sudo mv /etc/profile.d/

Then once we login, we'll see the output of our script!