How to set custom login banner message in linux

SSH banner messages are necessary when you want to display a warning for users when they access a server over SSH.

Let’s see how to set a custom SSH warning banner.

Configure SSH Warning Banner

Specify the banner message file in /etc/ssh/sshd_config SSH configuration:

1
2
3
4
$ sudo vim /etc/ssh/sshd_config
# no default banner path
#Banner none
Banner /etc/banner

Create the SSH Banner message file

Create a new banner message file as specified in /etc/ssh/sshd_config:

1
2
3
4
$ sudo vim /etc/banner
-------------------------
Authorized access only
-------------------------

Verify the banner message

To apply the changes, restart the SSH service:

1
$ sudo systemctl restart sshd

To test out the banner, login to the system over ssh:

1
2
3
4
5
ssh root@test-vm1
-------------------------
Authorized access only
-------------------------
root@test-vm1's password:

Setting a MOTD Banner

If you wish to set a MOTD (Message Of The Day) banner right after login, edit the /etc/motd file.

1
2
3
4
5
6
7
8
9
10
11
12
13
$ sudo vim /etc/motd
#####
#######
@ ##O#O##
###### @@# #VVVVV#
## # ## VVV ##
## @@@ ### #### ### ### ##### ###### # ##
## @ @# ### ## ## ## ### ## # ##
## @ @# ## ## ## ## ### # ###
## @@# ## ## ## ## ### QQ# ##Q
## # @@# ## ## ## ## ## ## QQQQQQ# #QQQQQQ
## ## @@# # ## ## ### ### ## ## QQQQQQQ# #QQQQQQQ
############ ### #### #### #### ### ##### ###### QQQQQ#######QQQQQ

The MOTD will be displayed next time you log in to the system.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
ssh root@test-vm1
-------------------------
Authorized access only
-------------------------
root@test-vm1's password:
#####
#######
@ ##O#O##
###### @@# #VVVVV#
## # ## VVV ##
## @@@ ### #### ### ### ##### ###### # ##
## @ @# ### ## ## ## ### ## # ##
## @ @# ## ## ## ## ### # ###
## @@# ## ## ## ## ### QQ# ##Q
## # @@# ## ## ## ## ## ## QQQQQQ# #QQQQQQ
## ## @@# # ## ## ### ### ## ## QQQQQQQ# #QQQQQQQ
############ ### #### #### #### ### ##### ###### QQQQQ#######QQQQQ