Custom MOTD for Debian
Step #1 – Prep
$ sudo apt-get install curl
$ sudo apt-get install lm-sensors
$ sudo apt-get install net-tools
$ sudo sensors-detect --auto
Step #2 – Remove the default MOTD:
sudo rm /etc/motd
Step #3 – Edit new motd file:
username=$(whoami) && sudo nano "/home/$username/.bash_profile"
Step #4 – Copy/paste script code:
#!/bin/bash
# deepmotd v1.3 - 17.12.2025
# Debian/Ubuntu x86 only
# deepmotd v1.1 - 01.12.2023
# deepmotd v1.2 - 17.12.2025
clear
# -------------------------
# Uptime
# -------------------------
upSeconds=$(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")
# -------------------------
# CPU Temperature via lm-sensors
# -------------------------
temp="N/A"
if command -v sensors &>/dev/null; then
temp=$(sensors | awk '/^Core 0:/ {print int($3)}' | tr -d '+°C')
[ -z "$temp" ] && temp=$(sensors | awk '/Package id 0:/ {print int($4)}')
fi
# Set color
if [ "$temp" != "N/A" ]; then
if [ $temp -lt 60 ]; then
color=$(tput setaf 2) # Green
elif [ $temp -lt 70 ]; then
color=$(tput setaf 3) # Yellow
else
color=$(tput setaf 1) # Red
fi
temp_display="$color$temp C"
else
temp_display="N/A"
fi
# -------------------------
# Username
# -------------------------
username=$(whoami)
# -------------------------
# Firewall (UFW)
# -------------------------
if sudo ufw status &>/dev/null; then
ufwports=$(sudo ufw status | grep -oE "[0-9]+/[a-z]+" | sed 's|/[a-z]\+||' | sort -n | uniq | tr '\n' ' ')
[ -z "$ufwports" ] && ufwports="N/A"
else
ufwports="Disabled"
fi
# -------------------------
# User accounts
# -------------------------
passwdusers=$(awk -F: '$3 >= 1000 && $3 < 65534 {printf "%s ", $1}' /etc/passwd)
# -------------------------
# Public IP
# -------------------------
public_ipv4=$(curl -s4 http://icanhazip.com/)
public_ipv6=$(curl -s6 http://icanhazip.com/)
[ -z "$public_ipv6" ] && public_ipv6="N/A"
# -------------------------
# Load averages
# -------------------------
read one five fifteen rest < /proc/loadavg
# -------------------------
# Memory usage
# -------------------------
memory_used=$(free -m | awk '/Mem/ {printf "%.2f", $3/1024}')
memory_total=$(awk '/MemTotal/ {printf "%.2f", $2/1024/1024}' /proc/meminfo)
# -------------------------
# Storage
# -------------------------
storage=$(df -h -x tmpfs -x vfat -x devtmpfs | awk 'NR==2 {print $5 " (" $3 " of " $2 ") used on " $1 }')
# -------------------------
# Network interface detection
# -------------------------
IFACE=$(ip -o link show | awk -F': ' '$2 !~ /^(lo|vir|wl|docker)/ {print $2; exit}')
[ -z "$IFACE" ] && IFACE="N/A"
# -------------------------
# MAC Address
# -------------------------
if [ "$IFACE" != "N/A" ]; then
MAC=$(cat /sys/class/net/$IFACE/address | tr 'a-f' 'A-F')
else
MAC="N/A"
fi
# -------------------------
# IPv4 LAN
# -------------------------
if [ "$IFACE" != "N/A" ]; then
IPV4=$(hostname -I | awk '{print $1}')
else
IPV4="N/A"
fi
# -------------------------
# IPv6 LAN
# -------------------------
if [ "$IFACE" != "N/A" ]; then
IPV6=$(ip -6 addr show dev $IFACE scope global | awk '/inet6/ {split($2,a,"/"); print a[1]; exit}')
[ -z "$IPV6" ] && IPV6="N/A"
else
IPV6="N/A"
fi
# -------------------------
# OS and Kernel
# -------------------------
OS=$(grep 'PRETTY_NAME' /etc/os-release | cut -d '"' -f 2)
KERNEL=$(uname -srm)
PROC=$(ps ax | wc -l | tr -d " ")
# -------------------------
# Display
# -------------------------
clear
cat <<EOF
$(tput setaf 3)$(date +"%A, %e %B %Y, %T")$(tput sgr0)
$(tput sgr0) OS.................: $OS
$(tput sgr0) Kernel.............: $KERNEL
$(tput sgr0) Uptime.............: $UPTIME
$(tput sgr0) Running Processes..: $PROC
$(tput sgr0) Load Averages......: $one (1min), $five (5mins), $fifteen (15mins)
$(tput sgr0) CPU Temperature....: $temp_display
$(tput sgr0) Memory.............: ${memory_used} GB (used) of ${memory_total} GB (total)
$(tput sgr0) Storage............: $storage
$(tput sgr0) IPv4 LAN...........: $IPV4
$(tput sgr0) IPv4 WAN...........: $public_ipv4
$(tput sgr0) IPv6 LAN...........: $IPV6
$(tput sgr0) IPv6 WAN...........: $public_ipv6
$(tput sgr0) MAC Address........: $MAC
$(tput sgr0) Firewall (UFW).....: $ufwports
$(tput sgr0) User Accounts......: $passwdusers
$(tput sgr0)
EOF
Now save using CTRL+O, and exit nano text editor with CTRL+X
Step #5 – Restart SSHD service:
sudo systemctl restart sshd
Update to new version:
If you have created motd file already and need to clear the file for updated code then use this command:
username=$(whoami) && sudo truncate -s 0 /home/$username/.bash_profile && sudo nano "/home/$username/.bash_profile"
Steps:
- Login SSH
- Run Command:
username=$(whoami) && sudo truncate -s 0 /home/$username/.bash_profile && sudo nano “/home/$username/.bash_profile” - Copy and past updated code above
- CTRL+ O (save) og CTRL+X (exit)
https://dev.to/bearlike/raspberry-pi-awesome-custom-motd-bpd