是否可以忽略 ssh 上的横幅,但不能忽略登录时的横幅

是否可以忽略 ssh 上的横幅,但不能忽略登录时的横幅

众所周知,我们可以在/etc/motd或 文件中输入 banner /etc/issue.net,这样每个登录到 Linux 机器的用户都会收到 banner 消息,例如:

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!
#
##########################################################################

ssh问题是,当我们通过Linux 机器远程登录(而不是本地登录)时也会显示横幅。

-q我们可以使用以下标志简单地忽略 ssh 中的横幅:

ssh -q  192.19.23.45 ls /hillary_emails 

事实上,我们有超过 100 个使用的 Bash 和 Perl 脚本ssh,所以如果我们向所有机器添加横幅,我们还需要ssh通过添加标志-q(静默模式)来更改使用该命令的脚本。

由于内部原因,我们不想编辑脚本。所以我的问题是,是否可以更改 Linux 客户端配置,使横幅仅在本地登录时显示,而不在远程登录时显示ssh

答案1

您可以创建一个组并将相关用户添加到该组:

groupadd nobanner
usermod -a -G nobanner username

然后,您可以编辑 /etc/ssh/sshd_config 并添加以下内容:

Match Group nobanner
    banner "none"

然后,重新启动sshd并测试。

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).

答案2

我认为 SSHD 选项PrintMotd no可以帮助您。将其添加到 /etc/ssh/sshd_config 中。文档说:

PrintMotd
             Specifies whether sshd(8) should print /etc/motd when a user logs in interactively.  (On some systems it is also
             printed by the shell, /etc/profile, or equivalent.)  The default is “yes”.

答案3

当天的信息应该不是在非交互式会话中显示。例如,当您运行 时ssh 192.19.23.45 ls,即以非交互式方式运行命令,并且当天的消息(“motd”)不应显示。

这同样适用于使用 的任何 Bash 或 Perl(或任何其他)脚本ssh。脚本将始终以非交互模式执行任务,并且不应显示每日消息。

如果您在系统中发现相反的情况,那可能是某种错误配置,我们可以尝试调试,但这不是默认行为。

因此,如果您主要关注的是脚本,那么就没有什么可担心的。如果您不希望向使用 远程登录的用户显示当天的消息ssh,那就是另一回事了,现有的答案可能会有所帮助。(但我认为这个要求有点奇怪:我不明白为什么你不想在用户(非脚本)的交互式远程会话中向他们显示该消息。)

相关内容