SSH登录后如何禁用欢迎消息?


32

我已经更改了/etc/issue.net,因此在SSH终端中输入用户名后,我已经设置了“个人”消息。现在,我尝试成功登录后更改欢迎文本。

我已经找到了很多有关该/etc/motd文件的文章,但是“欢迎使用Ubuntu blabla版本号等等” +“ *文档URL”这一部分不存在吗?

我只是不想在SSH终端中显示操作系统信息,我已经知道我已经安装了什么。:)我只想查看我的上一次登录。而且也不是错误;错误属于日志文件。

我必须编辑哪个文件?

Answers:


46

欢迎消息是由中的文件生成的/etc/update-motd.d/

来自man update-motd

/etc/update-motd.d/*中的可执行脚本由pam_motd(8)作为root用户在每次登录时执行,并且此信息串联在/ var / run / motd中。

因此,如果您不希望通过登录ssh删除这些脚本的输出,只需删除它们上的execute标志:

sudo chmod -x /etc/update-motd.d/*

现在,如果您想在登录时显示想要的内容,则有两个选择:

  • 创建一个脚本,将其放入中/etc/update-motd.d/,使其可执行,还确保其在STDOUT上输出。

  • ssh有一个Banner选择。您可以将文本放在文件中,然后在Banner选项中进行设置,以便在通过登录时显示文件的内容ssh。请注意,这仅适用于ssh

    Banner /etc/foobar
    

    来自man 5 sshd_config

     Banner  The contents of the specified file are sent to the remote user
             before authentication is allowed.  If the argument is “none” then
             no banner is displayed.  This option is only available for
             protocol version 2.  By default, no banner is displayed.
    

8
);我最喜欢的答案,所有启动“从某某人”
AB

谢谢!现在我知道了这些文件之间的关系。我没有修改它们,只是在我不想显示的某些行之前添加了#。
Terradon

@Terradon是的,那也可以。.我只是笼统地提出了解决方案,因为许多人不愿过多地研究文件
。– heemayl 2015年

2
很棒的解决方案,因为chmoding文件意味着我不必编辑它们。真好!
culix

...为什么他们在motd中放了这么多废话,却浪费了人们禁用它的时间:chmod -x的不错解决方案!
Motsel

4

您也可以pam_motd完全核对:

sed -i '/^[^#]*\<pam_motd.so\>/s/^/#/' /etc/pam.d/sshd

PAM呼叫pam_motd取决于中的设置/etc/pam.d,通常,这些条目是:

$ grep pam_motd /etc/pam.d -R
/etc/pam.d/login:session    optional   pam_motd.so  motd=/run/motd.dynamic noupdate
/etc/pam.d/login:session    optional   pam_motd.so
/etc/pam.d/sshd:session    optional     pam_motd.so  motd=/run/motd.dynamic noupdate
/etc/pam.d/sshd:session    optional     pam_motd.so # [1]

仅注释掉pam_motd这些文件中的行会禁用它。


感谢您的宝贵时间,但是对于“全力以赴”,我不知道自己在做什么。(我是linux / ubuntu的新手)。
Terradon

1
@Terradon您正在告诉PAM不要打电话pam_motd.so,仅此而已。
muru

谢谢,我将仔细看看PAM.does到底是什么。
Terradon

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.