Raspberry Pi – Custom SSH MOTD Banner

Once you login to a device via SSH the first thing you’ll be presented with is a banner of text. This is the MOTD (Message of The Day) and can actually be set to any text that you want.

You can even go a step further as we will in this guide, and make elements of the banner dynamic, so that you’re able to display useful information when you login, such as the:

  • System Uptime
  • Memory Consumption
  • Load Average / CPU Usage
  • Networking Info such as IP Address

Theres a great post on the Raspberry PI forums, where someone has created the below dynamic banner for each time that you login, which we will be using here as an example.


Perhaps one day this might get included into the standard operating system, but if you can’t wait like me it’s fairly simple to get it installed.

Install a Custom MOTD

The first step is to edit your bash profile, we’ll do this using the text editor “nano” and also prefix this with “sudo” to ensure we have the required permissions.

sudo nano /home/pi/.bash_profile

Once open you can simply paste in the code below, anywhere within that file. When you are done just press “CRTL + X” to close the file, and when prompted press “Y” to ensure your changes are saved.

let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)"
let secs=$((${upSeconds}%60))
let mins=$((${upSeconds}/60%60))
let hours=$((${upSeconds}/3600%24))
let 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 "$(tput setaf 2)
.~~.   .~~.    `date +"%A, %e %B %Y, %r"`
'. \ ' ' / .'   `uname -srmo`$(tput setaf 1)
.~ .~~~..~.
: .~.'~'.~. :   Uptime.............: ${UPTIME}
~ (   ) (   ) ~  Memory.............: `cat /proc/meminfo | grep MemFree | awk {'print $2'}`kB (Free) / `cat /proc/meminfo | grep MemTotal | awk {'print $2'}`kB (Total)
( : '~'.~.'~' : ) Load Averages......: ${one}, ${five}, ${fifteen} (1, 5, 15 min)
~ .~ (   ) ~. ~  Running Processes..: `ps ax | wc -l | tr -d " "`
(  : '~' :  )   IP Addresses.......: `/sbin/ifconfig eth0 | /bin/grep "inet addr" | /usr/bin/cut -d ":" -f 2 | /usr/bin/cut -d " " -f 1` and `wget -q -O - http://icanhazip.com/ | tail`
'~ .~~~. ~'    Weather............: `curl -s "http://rss.accuweather.com/rss/liveweather_rss.asp?metric=1&locCode=EUR|UK|UK001|NAILSEA|" | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3, \1/p'`
$(tput sgr0)"

Source: http://www.raspberrypi.org/phpBB3/viewtopic.php?t=23440

Technology enthusiastic with many ongoing online projects one of which is this personal blog PingBin. While also working full time within a data center designing and maintaining the network infrastructure.

7 comments On Raspberry Pi – Custom SSH MOTD Banner

  • Nice! that looks sweet.

    I don’t know about the rPi version but on a “normal” debian install you’d make that it’s own script and put it in /etc/update-motd.d

    If you would indulge an OCD sysadmin for a yarn:

    1. Add a #!/bin/sh to the head of your script

    2. Take your script and name it banner.sh

    3. Move your script to /etc/update-motd.d and add a number to the front of it like ##-banner.sh

    The number is the order. the higher the number the lower it will appear in the message

    4. run sudo chmod a+x /etc/update-motd.d/*-banner.sh

    There, a place for everything and everything in it’s place 🙂

    • if update-motd isn’t being used you can add this line to /etc/rc.local to get it working

      [ -d /etc/update-motd.d ] && echo -n “” > /etc/motd && for f in `ls /etc/update-motd.d | sort`; do echo -e `etc/update-motd.d/$f` >> /etc/motd; done

      • Thanks for the great info!

      • Thanks for the information on motd. I made a couple of changes to get the update-motd.d script to output to multiple lines.

        [ -d /etc/update-motd.d ] && echo -n > /etc/motd && for f in `ls /etc/update-motd.d | sort`; do /bin/bash `etc/update-motd.d/$f` >> /etc/motd; done

    • Using /etc/motd is definitely the proper way to do it, however on Raspbian there doesn’t seem to be a good way for it to update on login. The update-motd package isn’t available, and putting that line you provided (which is great) in rc.local will only update the motd on reboot, which won’t achieve the same effect if ssh’ing after boot. For that reason, simply printing to stdout from .bash_profile or /etc/profile seems to be the best way to achieve the same effect on the RPi.

  • Hi,
    it is very interesting MOTD.
    Most interesant part of it is getting a weather via CURL, and parsing it with SED. That’s where my head is not enough.

    Will you be able to customize the sed command that it will only display raw temperature number, eg. 27.

    Many thanks,

  • Putting it at the end of /etc/profile works great for all users, thanks!

Leave a reply:

Your email address will not be published.