bash /etc/motd 在 Gentoo Linux 上打印两次

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/190912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 20:30:47  来源:igfitidea点击:

/etc/motd printing twice on Gentoo Linux

bashsshgentoo

提问by Anthony Giorgio

I've run into a problem where I'm getting two printouts of my /etc/motd file on Gentoo Linux. sshd is doing one of the printouts, and I can toggle that by configuring /etc/ssh/sshd_config, but I can't find out who's printing the second copy. I can't disable sshd from printing out the motd due to an audit requirement. I'm running the bash shell, for what it's worth

我遇到了一个问题,我在 Gentoo Linux 上得到了我的 /etc/motd 文件的两个打印输出。sshd 正在执行其中一个打印输出,我可以通过配置 /etc/ssh/sshd_config 来切换它,但是我无法找出谁在打印第二个副本。由于审计要求,我无法禁用 sshd 打印 motd。我正在运行 bash shell,这是值得的

Any ideas who's printing the second copy? I don't think it's bash, as when I change /etc/passwd to use /bin/ksh for my shell, I still get the motd displayed.

谁有打印第二份的想法?我不认为这是 bash,因为当我将 /etc/passwd 更改为对我的 shell 使用 /bin/ksh 时,我仍然显示 motd。

It's not /etc/issue, as that contains the string "This is \n (\s \m \r) (\l)", which is printed only when you're sitting in front of the machine.

它不是 /etc/issue,因为它包含字符串“This is \n (\s \m \r) (\l)”,只有当您坐在机器前时才会打印该字符串。

回答by Anthony Giorgio

Looks like the answer was in the /etc/pam.d/login and /etc/pam.d/system-login files. I had to comment out the pam_motd.so lines.

看起来答案在 /etc/pam.d/login 和 /etc/pam.d/system-login 文件中。我不得不注释掉 pam_motd.so 行。

回答by Anthony Giorgio

Are you login from SSH connection??.. If so, maybe you must enable and set to no the key "PrintMotd No" on your sshd_config file and restart the service...

你是从 SSH 连接登录的吗??.. 如果是这样,也许你必须在你的 sshd_config 文件中启用并设置为 no 键“PrintMotd No”并重新启动服务......

回答by Anthony Giorgio

I had this problem too, and what was troubling to me was not the double-motd, it was the double "Last login" lines with the second referring back to the login event just above it.

我也有这个问题,让我烦恼的不是双重模式,而是双重“上次登录”行,第二行指的是它上面的登录事件。

I thought it might indicate foul play of some sort, as if my login were being re-directed or piped through some spyware or something.

我认为这可能表明某种不正当行为,就好像我的登录被重定向或通过某些间谍软件或其他东西传送一样。

Here is what the bottom 5 lines of my /etc/pam.d/system-login looks like:

这是我的 /etc/pam.d/system-login 底部 5 行的样子:

session         required        pam_env.so
#session        optional        pam_lastlog.so
session         include         system-auth
#session        optional        pam_motd.so motd=/etc/motd
session         optional        pam_mail.so

Note the commented-out lines. Everything works as expected now. Thanks, Daniel.

注意注释掉的行。现在一切都按预期工作。谢谢,丹尼尔。

回答by oscaroscar

I had the same issue with Ubuntu 15.04 and SSHD configured to use PAM Authentication. My server was sending two MOTD. I managed to make it work nicely by letting SSHD refreshing the MOTD at each login. This is done by editing /etc/pam.d/sshd and removing/commenting the line which says noupdate.

我在 Ubuntu 15.04 和配置为使用 PAM 身份验证的 SSHD 上遇到了同样的问题。我的服务器正在发送两个 MOTD。通过让 SSHD 在每次登录时刷新 MOTD,我设法让它很好地工作。这是通过编辑 /etc/pam.d/sshd 并删除/注释说noupdate.

# Print the message of the day upon successful login.
# This includes a dynamically generated part from /run/motd.dynamic
# and a static (admin-editable) part from /etc/motd.
session    optional     pam_motd.so  motd=/run/motd.dynamic
#session    optional     pam_motd.so  noupdate

The drawback is that if the process of refreshing this message takes a while (or CPU time) logging in could waste some resource, appear to take a while or even timeout.

缺点是如果刷新此消息的过程需要一段时间(或 CPU 时间),则登录可能会浪费一些资源,看起来需要一段时间甚至超时。

However, the basic default MOTD as configured out of the box in Ubuntu 15.04 should not cause trouble.

但是,在 Ubuntu 15.04 中开箱即用配置的基本默认 MOTD 应该不会造成问题。

回答by Martin

I think it would make more sense to make sure that the only component that prints MOTD is PAM. This way you can disable it everywhere else and still comply with your audit requirement.

我认为确保打印 MOTD 的唯一组件是 PAM 会更有意义。这样您就可以在其他任何地方禁用它,并且仍然符合您的审计要求。

Just my $0.02.

只是我的 0.02 美元。

回答by axel_c

Also check out /etc/issue, some systems print both and they might just contain the same text. Note that I don't use gentoo so this might not be the case.

还要查看 /etc/issue,有些系统会同时打印两者,而且它们可能只包含相同的文本。请注意,我不使用 gentoo,所以情况可能并非如此。

回答by Rob Kennedy

When I had this problem, I learned it was a combination of settings active when the system had been issued to me. The first copy of the message was printed before SSH authentication happened, and was due to SSH's Banneroption being set in sshd_config:

当我遇到这个问题时,我了解到这是系统发布给我时激活的设置组合。该消息的第一个副本是在 SSH 身份验证发生之前打印的,这是由于Bannersshd_config中设置了SSH 的选项:

Banner /etc/motd

A misuse of MOTD more than a misuse of Banner.

误用 MOTD 多于误用Banner.

The second copy of the message was printed because in its default configuration, SSH prints the MOTD upon login. I disable that by setting PrintMotd:

打印消息的第二个副本是因为在其默认配置中,SSH 在登录时打印 MOTD。我通过设置禁用它PrintMotd

PrintMotd no

回答by Rob Kennedy

In addition to commenting out the pam_motd.so lines, don't forget to also comment out the following lines in /etc/pam.d/login and /etc/pam.d/system-login:

除了注释掉 pam_motd.so 行之外,不要忘记还要注释掉 /etc/pam.d/login 和 /etc/pam.d/system-login 中的以下几行:

session optional pam_lastlog.so

会话可选 pam_lastlog.so

Like this, the "last login" line gets printed once instead of twice.

像这样,“上次登录”行被打印一次而不是两次。

回答by Nik Reiman

It is probably being done from the shell itself. Check the global profile and bashrc to see if this might be the case.

它可能是从外壳本身完成的。检查全局配置文件和 bashrc 以查看是否可能是这种情况。

回答by nneko

To allow only the pam_motd.so module to print the motd set the MOTD variable in /etc/login.defs to an empty string.

要仅允许 pam_motd.so 模块打印 motd,请将 /etc/login.defs 中的 MOTD 变量设置为空字符串。

MOTD_FILE ""

MOTD_FILE ""