我想更改通过 TTY 登录计算机时显示的 MOTD,这似乎可行,但不知何故,它不仅显示和中的 MOTD /etc/motd
,/etc/update-motd.d/
还显示另一条消息。
当我登录到我的服务器时显示如下内容:
sam@laptop:~$ ssh <user>@<server>
Welcome to Ubuntu 12.04.2 LTS (GNU/Linux 2.6.32-042stab068.8 i686)
* Documentation: https://help.ubuntu.com/
No mail.
Last login: Thu Feb 21 19:20:55 2013 from <ip>
Welcome to Ubuntu 12.04.2 LTS (GNU/Linux 2.6.32-042stab068.8 i686)
* Documentation: https://help.ubuntu.com/
<user>@<server>:~$
我的update-motd.d
包含两个文件,00-header
和10-help-text
。
00-header
包含以下内容:
[ -r /etc/lsb-release ] && . /etc/lsb-release
if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then
# Fall back to using the very slow lsb_release utility
DISTRIB_DESCRIPTION=$(lsb_release -s -d)
fi
printf "Welcome to %s (%s %s %s)\n" "$DISTRIB_DESCRIPTION" "$(uname -o)" "$(uname -r)" "$(uname -m)"
并10-help-text
包含以下内容:
[ -r /etc/lsb-release ] && . /etc/lsb-release
if [ -z "$DISTRIB_RELEASE" ] && [ -x /usr/bin/lsb_release ]; then
# Fall back to using the very slow lsb_release utility
DISTRIB_RELEASE=$(lsb_release -sr)
fi
URL="https://help.ubuntu.com/"
if uname -r | grep -qs "\-server"; then
URL="https://help.ubuntu.com/$DISTRIB_RELEASE/serverguide/C"
fi
printf "\n * Documentation: %s\n" "$URL"
这将弥补截至 的 MOTD 部分No mail.
。但其余部分来自哪里?
答案1
MOTD 可由sshd
或 PAM 打印。两者都可能这样做。
检查/etc/ssh/sshd_config
以下项:
PrintMotd yes
如果该行不存在,则可能默认为yes
(尽管 Debian/Ubuntu 将默认值更改为no
)。
检查您的 PAM 配置是否存在/etc/pam.d/
以下情况:
session optional pam_motd.so
尝试一次禁用一个功能,看看有什么变化。
答案2
在 Ubuntu 22.04 服务器上,我安装 update-motd 包时遇到了这种情况。卸载它没有帮助。
似乎 pam at-login-time 动态功能创建了/run/motd.dynamic
,并且 update-motd 也创建了/run/motd
,然后两者都在 ssh 登录时打印出来。
对我来说,解决方案是卸载 update-motd 并删除/run/motd
:
sudo apt remove --purge update-motd
sudo rm -f /run/motd
答案3
如果您使用的是 Ubuntu,您可以尝试:
sudo nano /etc/ssh/sshd_config
并检查PrintMotd
和UsePam
是否都设置为真,对我来说就是这种情况。
笔记:按照上述操作,您可以执行此操作sudo service ssh restart
,并且在登录时您应该只会看到一个 Motd。
答案4
在 Debian 8 上测试后:
/etc/pam.d/login 中的这个选项会打印另一个 motd
session optional pam_exec.so type=open_session stdout /bin/uname -snrvm