Disabling Ubuntu SSH login banner

I've been using Ubuntu since sometime in 2009. Every time I login to a Ubuntu machine via SSH I am greeted with a message like this

$ ssh hass
Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0-100-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

  System information as of Wed Aug 14 02:12:12 AM UTC 2024

  System load:  0.0                Processes:             94
  Usage of /:   23.1% of 28.87GB   Users logged in:       1
  Memory usage: 78%                IPv4 address for ens3: 192.168.166.110
  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 not enabled.

0 updates can be applied immediately.

1 additional security update can be applied with ESM Apps.
Learn more about enabling ESM Apps service at https://ubuntu.com/esm


The list of available updates is more than a week old.
To check for new updates run: sudo apt update

Last login: Wed Aug 14 02:04:26 2024 from 192.168.165.6
ericu@hass:~$ 

Over the years it seems Canonical has added more and more to this banner, including lots of things I never needed to see. So I want to turn this off. You can edit /etc/ssh/sshd_config and make sure it contains a line like this

PrintMotd no

However, that alone won't make any difference. You'll need to edit /etc/pam.d/login and find lines like this

# Prints the message of the day upon successful login.
# (Replaces the `MOTD_FILE' option in login.defs)
# 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 last two lines starting with session can be commented out like this

#session    optional   pam_motd.so motd=/run/motd.dynamic
#session    optional   pam_motd.so noupdate

Now open /etc/pam.d/sshd and make the same change in that file. Finally run systemctl restart ssh. Your next ssh login should look something like this

$ ssh hass
Last login: Wed Aug 14 02:16:41 2024 from 192.168.165.6
ericu@hass:~$ 

Copyright Eric Urban 2024, or the respective entity where indicated