Introduction
Displaying an SSH login banner is a simple but powerful way to show any user a message before they authenticate. Everything from Cool ASCII based art to legal notices can all be served via the SSH Login Banner.
This tutorial will explain how to edit the following files:
| File | Purpose |
|---|---|
/etc/issue.net |
Shown before login (SSH banner) |
/etc/motd |
Shown after login (MOTD) |
/etc/ssh/sshd_config |
SSH daemon configuration |
Example Legal Banner (Compliant)
Here is an example of a banner I had spotted in real world usage recently.
NOTICE: This system is for authorized users only.
By accessing this system, you consent to monitoring and logging.
Unauthorized access is prohibited and will be prosecuted.Prerequisites
- Any Linux machine with root acccess
- SSH already installed and running
Step 1 - Create the Banner File
Create a new file to hold your banner message:
sudo nano /etc/issue.netAdd your desired message. For example:
*********************************************************
WARNING: Unauthorized access is prohibited!
This system is monitored. All activity is logged.
Disconnect immediately if you are not an authorized user.
*********************************************************To make changes to the file, enter: Ctrl+O to save and Ctrl+X to exit nano.
Step 2 - Configure SSH to Display the Banner
Open the SSH daemon configuration file:
sudo nano /etc/ssh/sshd_configFind this line:
#Banner noneAnd change it to:
Banner /etc/issue.netIf Banner is commented out (has a # in front), remove the #.
Step 3 - Restart SSH
To apply the changes, restart the SSH service by:
sudo systemctl restart sshIf you're connected via SSH, don't close your session until you confirm the config works. Restarting ssh incorrectly could lock you out.
Step 4 - Test the Banner
From another terminal, SSH into your server:
ssh user@serverYou should now see the banner message before being prompted for your password or key.
Step 5 - Setup for a Post-Login Message (MOTD)
If you want to show a message after a successful login, edit the MOTD file:
sudo nano /etc/motdExample content:
Welcome to depths that only a few can approach, your Hetzner server!
Remember to update your packages regularly.This message will be shown after login but before the shell prompt.
Conclusion
You’ve successfully set up an SSH login banner on your server. This adds a cool look or a legal notice on your server when logging in.
References: