HowTo: Set a Warning Message (Banner) in SSH

SSH warning banners and welcome messages are necessary when organization wishes to prosecute an unauthorized user or just give out some information or announcement.

Display SSH Warning Message BEFORE the Login

Pre login SSH warning banner shows before the password prompt, during an interactive session using SSH. It usually uses for legal warnings to establish the terms and conditions by which someone is allowed to use the system.

The SSH warning messages are commonly located in the files ‘/etc/issue’ and ‘/etc/issue.net’, but you can also use your custom file like ‘/etc/ssh/sshd-banner’. The content of the specified file is sent to the remote user before authentication.

Create an SSH login banner file:

$ vi /etc/ssh/sshd-banner

Append some Warning text:

WARNING:  Unauthorized access to this system is forbidden and will be
prosecuted by law. By accessing this system, you agree that your actions
may be monitored if unauthorized usage is suspected.

Open the sshd_config file:

$ vi /etc/ssh/sshd_config

Edit the path to the banner file:

Banner /etc/ssh/sshd-banner

Save the file and reload the sshd:

$ service sshd reload

Display SSH Welcome Message AFTER the Login

The content of the file ‘/etc/motd’ is displayed after successful authentication, but just before the shell. It is used for system announcements and other important information, that you want authenticated users to know about before they start using the system.

Edit the file ‘/etc/motd’:

$ vi /etc/motd

Place the announcement message and save the file.

Now this message will be shown after the successful authentication through SSH.

Writing a Message to Logged in Users through the Terminal

To write a message to logged in users, you can use a write command. The write utility allows you to communicate with other users, by copying lines from your terminal to theirs.

First of all you need to check who is currently logged in, and which terminal he is logged in to.

$ who
root     pts/0        2012-04-25 12:57 (192.168.0.207)
john     pts/1        2012-04-25 13:20 (192.168.0.101)

Now you can write a messages to the user John. For example:

$ write john pts/1
Hello!

When you hit ‘Enter’, your message will be sent to that terminal.

Use Ctrl + D to terminate write

Also you can cat a file and pipe it to the write command too:

$ cat file.txt | write stan pts/1

To broadcast your message to all logged in users you can use a wall command (wall = write to all):

$ wall
Hey you people!

For wall, the message will be sent only after you hit Ctrl + D

Or you can cat a file and pipe it to the wall command:

$ cat announcement.txt | wall