我有两台运行 Ubuntu 22.04.4 LTS 的服务器。其中一台(我们称之为host1 )通过 SSH 登录时将看到 motd,如下所示。但是,在第二台( host2)上,这不会在 SSH 登录时显示,我只会获得“上次登录”信息。
Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0-112-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
System information as of So 16. Jun 15:00:05 CEST 2024
System load: 0.62 Processes: 115
Usage of /: 39.5% of 19.51GB Users logged in: 1
Memory usage: 58% IPv4 address for ens3: XXX.XXX.XX.XX
Swap usage: 0%
* Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
just raised the bar for easy, resilient and secure K8s cluster deployment.
https://ubuntu.com/engage/secure-kubernetes-at-the-edge
Expanded Security Maintenance for Applications is enabled.
0 updates can be applied immediately.
Last login: Sat Jun 15 14:07:55 2024 from XXX.XXX.XXX.XXX
当我run-parts /etc/update-motd.d/
在其中任何一台机器上执行时,两种情况下都会显示预期的信息。
运行ls -l /etc/update-motd.d/
显示文件在两台机器上都存在且可执行。
host1(登录时mod工作正常)
user@host1:~$ ls -l /etc/update-motd.d/
total 56
-rwxr-xr-x 1 root root 1220 Okt 15 2021 00-header
-rwxr-xr-x 1 root root 1151 Jan 2 15:57 10-help-text
lrwxrwxrwx 1 root root 46 Mai 6 22:11 50-landscape-sysinfo -> /usr/share/landscape/landscape-sysinfo.wrapper
-rwxr-xr-x 1 root root 5023 Okt 15 2021 50-motd-news
-rwxr-xr-x 1 root root 84 Mai 17 2023 85-fwupd
-rwxr-xr-x 1 root root 218 Feb 28 2023 90-updates-available
-rwxr-xr-x 1 root root 296 Nov 30 2023 91-contract-ua-esm-status
-rwxr-xr-x 1 root root 558 Jan 9 2023 91-release-upgrade
-rwxr-xr-x 1 root root 165 Feb 19 2021 92-unattended-upgrades
-rwxr-xr-x 1 root root 379 Feb 28 2023 95-hwe-eol
-rwxr-xr-x 1 root root 111 Aug 17 2020 97-overlayroot
-rwxr-xr-x 1 root root 142 Feb 28 2023 98-fsck-at-reboot
-rwxr-xr-x 1 root root 144 Feb 28 2023 98-reboot-required
-rwxr-xr-x 1 root root 275 Jun 15 03:05 99-livepatch-kernel-upgrade-required
host2(登录时未显示mod )
user@host2:~$ ls -l /etc/update-motd.d/
total 56
-rwxr-xr-x 1 root root 1220 Oct 15 2021 00-header
-rwxr-xr-x 1 root root 1151 Jan 2 14:57 10-help-text
lrwxrwxrwx 1 root root 46 May 6 20:40 50-landscape-sysinfo -> /usr/share/landscape/landscape-sysinfo.wrapper
-rwxr-xr-x 1 root root 5023 Oct 15 2021 50-motd-news
-rwxr-xr-x 1 root root 84 May 17 2023 85-fwupd
-rwxr-xr-x 1 root root 218 Feb 28 2023 90-updates-available
-rwxr-xr-x 1 root root 296 Nov 30 2023 91-contract-ua-esm-status
-rwxr-xr-x 1 root root 558 Jan 9 2023 91-release-upgrade
-rwxr-xr-x 1 root root 165 Feb 19 2021 92-unattended-upgrades
-rwxr-xr-x 1 root root 379 Feb 28 2023 95-hwe-eol
-rwxr-xr-x 1 root root 111 Aug 17 2020 97-overlayroot
-rwxr-xr-x 1 root root 142 Feb 28 2023 98-fsck-at-reboot
-rwxr-xr-x 1 root root 144 Feb 28 2023 98-reboot-required
-rwxr-xr-x 1 root root 275 Jun 12 02:08 99-livepatch-kernel-upgrade-required
我不清楚为什么这两个系统上的行为不同。我怀疑我可能忽略了一些琐碎的事情。
如何让motd在 SSH 登录时显示?是否必须在某处明确启用它?
顺便说一句,我注意到这两个系统上的PrintMotd都设置为“否” /etc/ssh/sshd_config
。不确定这是否相关,因为尽管设置为“否”,但host1
仍在显示它。
我在这两个系统上都没有任何自定义 motd 脚本。
有一点背景可以解释配置的差异:host1是通过云提供商提供的 Ubuntu 22.04 映像设置的。host2是使用来自 Ubuntu.com 的标准 22.04 安装 ISO 设置的。
这是基于steeldriver提供的评论。
在 的 sshd 配置文件中
/etc/ssh/sshd_config
,需要将参数UsePAM
设置为,yes
以便在通过 SSH 登录时显示motd 。有了这些信息,我能够找到针对 Ubuntu 21.10 的类似问题,其中接受的答案有助于阐明 PAM 和 MOTD 之间的联系: