In this tutorial you learn how to modify the welcome message of your Linux system. This message is shown when you login via SSH.
The simplest way of modification is to edit the content of the /etc/motd
file. This however only works for text changes and not if you like to calculate some of the displayed values.
To add dynamic content to the message of the day you start by disabling MOTD, remove the MOTD content file as well as the default MOTD script file:
systemctl disable motd
rm -f /etc/motd
rm /etc/update-motd.d/10-uname
Next, we add our own MOTD script file. The number in front defines the order in which the script files are executed.
touch /etc/update-motd.d/10-info
chmod a+x /etc/update-motd.d/*
Now we can add our own content to this file. I found a code snipped1 to display a nice raspberry:
#!/bin/bash
echo "$(tput setaf 2)
.~~. .~~.
'. \ ' ' / .'$(tput setaf 1)
.~ .~~~..~.
: .~.'~'.~. :
~ ( ) ( ) ~
( : '~'.~.'~' : )
~ .~ ( ) ~. ~
( : '~' : ) $(tput sgr0)Raspberry Pi$(tput setaf 1)
'~ .~~~. ~'
'~'
$(tput sgr0)"
sh /etc/update-motd.d/10-info
or start a new SSH session.
For my home server I display the name of my server in ASCII art that I generated using an ASCII art generator2 followed by a summary of the system information:
#!/bin/sh
upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)"
secs=$((${upSeconds}%60))
mins=$((${upSeconds}/60%60))
hours=$((${upSeconds}/3600%24))
days=$((${upSeconds}/86400))
UPTIME=`printf "%d days, %02dh%02dm%02ds" "$days" "$hours" "$mins" "$secs"`
# get the load averages
read one five fifteen rest < /proc/loadavg
echo "
_____ _____
| | |___ _____ ___ | __|___ ___ _ _ ___ ___
| | . | | -_| |__ | -_| _| | | -_| _|
|__|__|___|_|_|_|___| |_____|___|_| \_/|___|_|
`uname -srmo`
`date -u`
Last login.........: `lastlog -u pi | awk 'NR==2 {$1=$2=$3=""; print $0}' | awk '$1=$1'` from `lastlog -u pi | awk 'NR==2 {print $3}'`
Uptime.............: ${UPTIME}
Temperature........: `/opt/vc/bin/vcgencmd measure_temp | awk -F '[/=]' '{print $2}'`
Load Averages......: ${one} (1 minute) ${five} (5 minutes) ${fifteen} (15 minutes)
Memory.............: `free -h | awk 'NR==2 {print $4}'` (Free) / `free -h | awk 'NR==2 {print $2}'` (Total)
Root Drive.........: `df -h -x tmpfs -x vfat -x devtmpfs | awk 'NR==2 {print $5 " (" $3 "/" $2 ") used on " $1 }'`
Media Drive........: `df -h -x tmpfs -x vfat -x devtmpfs | awk 'NR==3 {print $5 " (" $3 "/" $2 ") used on " $1 }'`
Media Drive 2......: `df -h -x tmpfs -x vfat -x devtmpfs | awk 'NR==4 {print $5 " (" $3 "/" $2 ") used on " $1 }'`
IP Addresses.......: `ifconfig eth0 | grep "inet " | awk '{print $2}'` / `ifconfig eth0 | grep "inet6" | awk 'NR==1 {print $2}'`
"
In case you like to remove the last login information that are added by the SSH agent you can disable it by editing the /etc/ssh/sshd_config
and adding the following line:
PrintLastLog no