Skip to content

Instantly share code, notes, and snippets.

@vegaasen
Last active August 29, 2015 14:21
Show Gist options
  • Save vegaasen/8e13db3ede302690593a to your computer and use it in GitHub Desktop.
Save vegaasen/8e13db3ede302690593a to your computer and use it in GitHub Desktop.
Adding Linux banner to RHEL and Ubuntu

Adding Linux banner to RHEL and Ubuntu

Introduction

This contains information on how to actually add a banner to RHEL or Ubuntu Linux systems when logging in using ssh.

Linux distributions

Red Hat Enterprise Linux

Do the following:

Locate the ssh and the sshd-config:

[xxxx@whatever ~]$ locate sshd_config
/etc/ssh/sshd_config
/etc/ssh/sshd_config.rpmnew
/usr/share/man/man5/sshd_config.5.gz
[xxxx@whatever ~]$

Edit the first file, and look for the following line:

Banner /etc/ssh/message

If the Banner-configuration is not there, just add it to the end of the configuration for the SSH deamon. You dont have to use the path we're using, obviously! ;)

Anyway, then just add something to the ssh-message, and save it. Then, restart the SSH deamon:

service sshd stop
service sshd start

Then, relog to the server and your message should appear.

Ubuntu Linux

The procedure is similar, however Ubuntu have defined a file you may use (I do actally think this is located in RHEL-distributions as well when I think of it..):

/etc/motd

Which, essentially, means "message of the day". This file you can edit and it will display whatever typed in there to all users that logs in to the ssh port. Remember to restart the SSH deamon services for the change to kick in!

Dynamic MOTD

This applies to all Linux installations, and is quite easy. Do the following:

1. Disable MOTD

First, we will need to disable the MOTD:

locate sshd_config
sudo vi /etc/ssh/sshd_config

In the sshd_config-file, add a comment for the following lines:

#PrintMotd yes
# or, you can add
PrintMotd no
Banner <whatever-file>

2. Create a dynamic file

We need a file that can display some dynamic stuff. Do the following:

sudo echo "Hello there! `alias -a`" >> /etc/ssh/message-dynamic

Make it executable:

sudo chmod a+x /etc/ssh/message-dynamic

3. Add the script to the startup

Now, we have disabled the default MOTD, and created a new script which should do the stuff we want it to do. Add the script to the startup in order to make it display stuff for users when they log in:

sudo vi /etc/profile

In that (----^) file, add the location of the message-dynamic to the last line:

/etc/ssh/message-dynamic

4. Verify :)

Quit and log back in! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment