When you SSH into an Ubuntu server, the welcome message (Message of the Day or MotD) is generated by several components working together:
1. /etc/motd - Static message file
2. /etc/update-motd.d/ - Dynamic message scripts
3. PAM modules that control message display
The modern Ubuntu systems use dynamic MOTD generation through scripts in /etc/update-motd.d/. Here's how to list them:
ls -la /etc/update-motd.d/
total 40
drwxr-xr-x 2 root root 4096 Jul 12 2021 .
drwxr-xr-x 142 root root 12288 Mar 15 09:30 ..
-rwxr-xr-x 1 root root 122 Aug 14 2019 00-header
-rwxr-xr-x 1 root root 982 Aug 14 2019 10-help-text
-rwxr-xr-x 1 root root 1315 Aug 14 2019 50-motd-news
-rwxr-xr-x 1 root root 154 Aug 14 2019 80-esm
-rwxr-xr-x 1 root root 704 Aug 14 2019 80-livepatch
-rwxr-xr-x 1 root root 4417 Aug 14 2019 90-updates-available
-rwxr-xr-x 1 root root 982 Aug 14 2019 98-reboot-required
-rwxr-xr-x 1 root root 526 Aug 14 2019 98-fsck-at-reboot
To modify the system load information (like removing memory usage display), edit the header script:
sudo nano /etc/update-motd.d/00-header
Find and comment out the memory-related lines:
# Fetch memory usage
#memory_used=$(free -m | awk 'NR==2{printf "%.2f%%", $3*100/$2 }')
#memory_available=$(free -m | awk 'NR==2{printf "%sMB", $2 }')
Add your own script to the MOTD directory (make sure it's executable):
sudo nano /etc/update-motd.d/99-custom
#!/bin/sh
echo ""
echo "=== Custom Server Message ==="
echo "Maintenance Window: Every Sunday 2-4 AM UTC"
echo "Contact: admin@example.com"
exit 0
sudo chmod +x /etc/update-motd.d/99-custom
If you prefer static messages only:
sudo chmod -x /etc/update-motd.d/*
sudo nano /etc/motd
Welcome to Production Server
Authorized Use Only
All activities are logged
For more sophisticated messages based on system state:
#!/bin/bash
if [ $(cat /proc/loadavg | cut -d' ' -f1 | awk '{printf "%.0f", $1}') -gt 2 ]; then
echo "WARNING: High system load detected!"
fi
If changes don't appear:
- Check script permissions:
ls -la /etc/update-motd.d/ - Test script execution:
run-parts /etc/update-motd.d/ - Verify PAM configuration:
/etc/pam.d/sshd
The login message you see when SSH-ing into Ubuntu servers is controlled by the Message of the Day (MOTD) system. This consists of several components that generate different parts of the message:
/etc/update-motd.d/ - Directory containing executable scripts that generate dynamic content
/etc/motd - Static message file (deprecated in modern Ubuntu)
/run/motd.dynamic - Combined output from all MOTD scripts
The dynamic MOTD system in Ubuntu uses these important files:
/etc/default/motd-news - Controls Ubuntu news updates
/etc/legal - Contains legal notices
/etc/update-motd.d/00-header - System information header
/etc/update-motd.d/10-help-text - Help information
/etc/update-motd.d/50-motd-news - Ubuntu news
/etc/update-motd.d/90-updates-available - Package updates
/etc/update-motd.d/98-reboot-required - Reboot notices
To customize specific parts of the message, edit the corresponding script in /etc/update-motd.d/. For example, to modify the system information section:
sudo nano /etc/update-motd.d/00-header
The script uses simple bash commands to generate output. For instance, the memory usage information comes from:
printf " Memory usage: %s" "$(free -m | awk 'NR==2 { printf "%.1f%%", $3*100/$2 }')"
You can create new scripts in /etc/update-motd.d/ following these conventions:
#!/bin/sh
# Add your custom content here
echo "Custom Server Message"
echo "Current time: $(date)"
Remember to:
1. Name files with two-digit prefixes (e.g., 99-custom)
2. Make them executable: chmod +x /etc/update-motd.d/99-custom
3. Keep them fast (they run on every login)
To disable any component, either:
sudo chmod -x /etc/update-motd.d/50-motd-news # Remove execute permission
or
sudo mv /etc/update-motd.d/50-motd-news /etc/update-motd.d/50-motd-news.disabled # Rename
Here's a complete example of a custom MOTD script that shows disk usage per mount point:
#!/bin/sh
[ -r /etc/lsb-release ] && . /etc/lsb-release
if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then
DISTRIB_DESCRIPTION=$(lsb_release -s -d)
fi
printf "\nDisk Usage Information:\n"
df -h | awk '
NR==1 {print}
NR>1 && $1 !~ /tmpfs/ && $1 !~ /udev/ {
printf "%-25s %-8s %-8s %-8s %s\n", $1, $2, $3, $4, $6
}'
To test changes without logging in/out:
run-parts /etc/update-motd.d/
Or to see the complete MOTD output:
cat /run/motd.dynamic
When customizing MOTD:
- Avoid revealing sensitive system information
- Keep scripts simple to prevent security issues
- Consider performance impact on frequent logins