If you read our previous article Debian Jessie Dynamic MOTD, then you may be wondering how this can be accomplished on your fresh new Debian Stretch setup. This is what is presented to the user in terminal when a log on occurs using our previous article.
This feature is very nice as it will give you a quick look at useful information. Unfortunately, Debian Server does not include the dynamic MOTD. First you will need to install some prerequisites and build the directory structure. To do so, run the following commands in terminal. If you would like to add update notification, I have written another article detailing the steps at Debian MOTD Update Notifier.
# install lsb-release sudo apt-get install lsb-release # install figlet to enable ASCII art sudo apt-get install figlet # create directory mkdir /etc/update-motd.d/ # change to new directory cd /etc/update-motd.d/ # create dynamic files touch 00-header ; touch 10-sysinfo; touch 90-footer # make files executable chmod +x /etc/update-motd.d/* # remove MOTD file rm /etc/motd
Once the above commands have been run, you can move on to populating the files you created. Below you can copy and paste.
Header (00-header
)
#!/bin/sh # # 00-header - create the header of the MOTD # Copyright (c) 2013 Nick Charlton # Copyright (c) 2009-2010 Canonical Ltd. # # Authors: Nick Charlton <hello@nickcharlton.net> # Dustin Kirkland <kirkland@canonical.com> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. [ -r /etc/lsb-release ] && . /etc/lsb-release if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then # Fall back to using the very slow lsb_release utility DISTRIB_DESCRIPTION=$(lsb_release -s -d) fi figlet $(hostname) printf "\n" printf "Welcome to %s (%s).\n" "$DISTRIB_DESCRIPTION" "$(uname -r)" printf "\n"
Once the above commands have been run, you can move on to populating the files you created. Below you can copy and paste.
Sysinfo (10-sysinfo
)
#!/bin/bash # # 10-sysinfo - generate the system information # Copyright (c) 2013 Nick Charlton # # Authors: Nick Charlton <hello@nickcharlton.net> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. date=`date` load=`cat /proc/loadavg | awk '{print $1}'` root_usage=`df -h / | awk '/\// {print $(NF-1)}'` memory_usage=`free -m | awk '/Mem:/ { total=$2; used=$3 } END { printf("%3.1f%%", used/total*100)}'` swap_usage=`free -m | awk '/Swap/ { printf("%3.1f%%", $3/$2*100) }'` users=`users | wc -w` time=`uptime | grep -ohe 'up .*' | sed 's/,/\ hours/g' | awk '{ printf $2" "$3 }'` processes=`ps aux | wc -l` ip=`hostname -I | awk '{print $1}'` echo "System information as of: $date" echo printf "System Load:\t%s\tIP Address:\t%s\n" $load $ip printf "Memory Usage:\t%s\tSystem Uptime:\t%s\n" $memory_usage "$time" printf "Usage On /:\t%s\tSwap Usage:\t%s\n" $root_usage $swap_usage printf "Local Users:\t%s\tProcesses:\t%s\n" $users $processes echo /usr/lib/update-notifier/update-motd-reboot-required /usr/lib/update-notifier/apt-check --human-readable echo
Footer (90-footer
)
#!/bin/sh # # 99-footer - write the admin's footer to the MOTD # Copyright (c) 2013 Nick Charlton # Copyright (c) 2009-2010 Canonical Ltd. # # Authors: Nick Charlton <hello@nickcharlton.net> # Dustin Kirkland <kirkland@canonical.com> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. [ -f /etc/motd.tail ] && cat /etc/motd.tail || true
Once these files are populated with the above, you should now be able to logout and then log back in either using putty or on the console and you will be presented with something that looks like below.
I cannot get the ip address to show and is there a way to show available updates?
Link to Debian MOTD Update Notifier was provided in article above. As for the IP maybe see comments.
I’ve just got the IP address working on Debian 9 by replacing the line for:
ip=`hostname -I`
Well for me Debian 8 3.16.0-5-amd64 #1 SMP Debian 3.16.51-3+deb8u1 (2018-01-08) I had to edit /etc/pam.d/sshd to contain the following in order to get the /etc/update-motd.d/* scripts to work.
#session optional pam_motd.so motd=/run/motd.dynamic
session optional pam_motd.so motd=/run/motd
session optional pam_motd.so noupdate
basicly I’m seeing that pam_motd is running from /run/motd NOT /run/motd.dynamic
found this answer here: https://unix.stackexchange.com/questions/246436/how-to-set-a-dynamic-message-of-the-day-motd-in-debian-jessie-8-2-for-ssh/246770
sure wish the documentation on the wiki for debian explained this better would have saved me some tracking down a solution effort. Anyway hope this helps cheers!!
Thanks Matt! Appreciate the update.
Thanks for the tutorial, I have a very similar configuration on my Debian Jessie Servers. Unfortunately, after upgrading to Debian Stretch the MOTD is not generated anymore from the scripts in /etc/update-motd.d/
Do I have to enable that somehow so that PAM will generate the MOTD-file? I noticed that the configuration in /etc/pam.d/login has changed after the upgrade to this:
session optional pam_motd.so motd=/run/motd.dynamic
session optional pam_motd.so noupdate
But it also does not work with the old configuration.
Check if you have file called .hushlogin in your home directory. If that file exists, motd won’t be shown no matter what your settings are. This file is defined in /etc/login.defs.
Not working at all..
Low quality comment buddy. How about you tell us exactly what is not working?
Hi and thanks for this !
As you will see in your pasted output, the line used to calculate the memory usage always reports 0. This is due to a change in `free -m` output that now reports all memory info on the same line (no separate line for buffers/cache)
`free -m` also now reports the “used memory” as being “total used memory – memory for buffers – memory for cache”. So changing the following line in 10-sysinfo does the trick
memory_usage=`free -m | awk ‘/Mem:/ { total=$2; used=$3 } END { printf(“%3.1f%%”, used/total*100)}’`
Cheers
Thanks for the update Oliver 🙂
My pleasure 😉