Linux – is it possible to ignore banner on ssh but not from login

bannerbashlinuxoperating systemredhat

As we all know, we can type banner in /etc/motd or in the file /etc/issue.net,
so every user that login to the Linux machine will get the banner message, for example:

Red Hat Enterprise Linux Server release 6.8 (Santiago)
Kernel \r on an \m
##########################################################################
#                               Welcome to OBAMA house !!!
#                         All connections are monitored and recorded
#                Disconnect IMMEDIATELY if you are not an authorized user!
#
##########################################################################

The problem is that the banner is displayed also when we login remotely via ssh to the Linux machines (as opposed to login locally).

We can simply ignore the banner in the ssh by using the flag -q as the following:

ssh -q  192.19.23.45 ls /hillary_emails 

In fact we have more then ~100 Bash and Perl scripts that use ssh,
so if we add banners to all the machines we need to change also the scripts that use the ssh command, by adding the flag -q (silent mode).

We prefer not to edit the scripts, due to internal reasons.
So my question is,
is it possible to change the Linux client configuration in a way the banner will display only on local logins, and not display when login remotely by ssh?

Best Answer

You can create a group and add the relevant users to that group:

groupadd nobanner
usermod -a -G nobanner username

Then, you can edit /etc/ssh/sshd_config and add the following:

Match Group nobanner
    banner "none"

Then, restart sshd and test it.

Match   Introduces a conditional block.  If all of the criteria on the Match 
        line are satisfied, the keywords on the following lines override those 
        set in the global section of the config file, until either another Match 
        line or the end of the file.

        The arguments to Match are one or more criteria-pattern pairs.  The 
        available criteria are User, Group, Host, and Address.  The match 
        patterns may consist of single entries or comma-separated lists and may 
        use the wildcard and negation operators described in the PATTERNS 
        section of ssh_config(5).