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
?
I think the SSHD option
PrintMotd no
can help you. Add it in /etc/ssh/sshd_config. The doc says :You can create a group and add the relevant users to that group:
Then, you can edit /etc/ssh/sshd_config and add the following:
Then, restart sshd and test it.
The message of the day should not be displayed in non-interactive sessions. For example when you run
ssh 192.19.23.45 ls
, that non-interactively runs commands, and the message of the day ("motd") is should not be displayed.The same applies to any Bash or Perl (or whatever other) scripts that use
ssh
. Scripts will always perform tasks in non-interactive mode, and the message of the day should not be displayed.If you find the contrary in your system, that would be some sort of misconfiguration that we can try to debug, but it's not the default behavior.
So if your main concern is scripts, then there is nothing to worry about. If you don't want the message of the day displayed for users who login remotely with
ssh
, that's a different matter, and the existing answers may help. (But I consider that request a bit strange: I don't see why you wouldn't want to show the message to users (non-scripts), in their interactive remote sessions.)