How to Customize or Disable SSH Login Banner Messages in Ubuntu/Debian Systems


29 views

The welcome message you're seeing during SSH login typically comes from multiple system files in Linux. While .bashrc and .profile are user-specific configuration files, system-wide messages are usually controlled by different mechanisms.

Here are the key files that might be generating your login messages:


1. /etc/motd (Message of the Day)
2. /etc/issue and /etc/issue.net
3. PAM modules configured in /etc/pam.d/sshd
4. /etc/update-motd.d/ directory (on modern Ubuntu systems)

Recent Ubuntu versions use a dynamic MOTD system:


# To disable all dynamic MOTD content:
sudo chmod -x /etc/update-motd.d/*

This prevents execution of the MOTD scripts while preserving them for future use.

For the copyright and warranty messages specifically:


# Edit sshd configuration
sudo nano /etc/ssh/sshd_config

# Add or modify these lines:
PrintMotd no
PrintLastLog no
Banner none

# Then restart SSH
sudo systemctl restart sshd

The "Received message too long" error in SFTP occurs because SSH banners are sent before the SFTP protocol handshake. To fix this while keeping some messages:


# Create a custom minimal banner
sudo nano /etc/ssh/my_banner
(Add your short welcome message here)

# Then in sshd_config:
Banner /etc/ssh/my_banner

After making changes, test with:


ssh -T user@yourserver.com
sftp user@yourserver.com

This helps verify both SSH and SFTP connections work properly.

If you want to keep some information but make it more concise:


# Example custom MOTD script
sudo nano /etc/update-motd.d/01-custom

#!/bin/sh
echo "=== Server: $(hostname) ==="
echo "Last login: $(lastlog -u $USER | tail -1)"

When you SSH into an Ubuntu server, the welcome message you see typically comes from multiple system files. The issue you're experiencing with SFTP (error code 761422195) is indeed often caused by excessive MOTD (Message of the Day) content. Let's examine the key files involved:

# Common files that generate login messages:
/etc/motd          # Message of the Day
/etc/update-motd.d # Dynamic MOTD scripts
/etc/issue         # Pre-login banner
/etc/issue.net     # Network login banner
~/.bashrc          # User-specific shell config
~/.profile         # User-specific profile

To eliminate the lengthy legal notices from Debian/Ubuntu, you can disable the MOTD system:

# Disable MOTD updates
sudo chmod -x /etc/update-motd.d/*

For a more surgical approach, you might want to keep some useful system information while removing the legal text:

# Edit the MOTD scripts
sudo nano /etc/update-motd.d/10-help-text
# Comment out or remove the warranty sections

The /etc/issue and /etc/issue.net files control banners displayed before authentication. To clear them:

# Clear the banner files
echo "" | sudo tee /etc/issue /etc/issue.net

For SFTP clients that choke on large banners, you can configure SSHd to suppress banners:

# Edit SSH daemon configuration
sudo nano /etc/ssh/sshd_config

# Add or modify these lines:
DebianBanner no
PrintMotd no
PrintLastLog no
Banner none

# Then restart SSH
sudo systemctl restart sshd

After making these changes, test with a new SSH session and SFTP connection. For quick verification:

ssh -T user@yourserver.com "echo 'SSH banner test'"
sftp -b /dev/null user@yourserver.com

Remember that some changes might require logging out and back in to take effect, as shell initialization files are only processed during login.