If you manage a corporate Linux server, it is a legal and security best practice to display a warning message to anyone attempting to connect via SSH. This message, often called a “login banner,” explicitly warns unauthorized users that they are accessing a private system and that their actions are being monitored. In Ubuntu, setting up this pre-login banner is a simple two-step process.
Step 1: Create the Warning Message
The SSH daemon looks for a specific file called issue.net to generate its pre-login banner. We need to edit this file to contain your custom warning.
- Open your terminal and SSH into your server.
- Open the issue file using a text editor with root privileges:
sudo nano /etc/issue.net - Delete any generic text that might already be in the file.
- Type your legal warning. For example:
WARNING: This system is for authorized users only. All activities are monitored and recorded. Unauthorized access will be fully prosecuted. Disconnect immediately if you do not have explicit permission.
- Press Ctrl + O then Enter to save the file, and Ctrl + X to exit the editor.
Step 2: Enable the Banner in the SSH Configuration
Now that the message exists, we must instruct the SSH service to actually display it to incoming connections.
- Open the main SSH configuration file:
sudo nano /etc/ssh/sshd_config - Use your arrow keys to scroll down and look for a line that says
#Banner noneor#Banner /etc/issue.net. (The hashtag means the line is currently disabled/commented out). - Remove the hashtag (
#) and ensure the line points to your file exactly like this:
Banner /etc/issue.net - Save and exit the file (Ctrl + O, Enter, Ctrl + X).
- Finally, restart the SSH service to apply the changes:
sudo systemctl restart ssh
You can test this immediately by opening a new terminal window and attempting to SSH into your server. Before you are even prompted for a password, your custom legal warning will be proudly displayed on the screen.