0

I am looking to disable MOTD on my Debian 12 systems. I updated my sshd_config file to not display MOTD but it is still showing up. Is it possible it is coming from another module and how can I disable it?

I deploy servers in Vultr with a shell script. I would need to be able to call a command in my shell script to disable MOTD so I do not have to go into the server to make this change for each new server.

2
  • 1
    What changes did you make to the sshd_config? How are you connecting to the servers when you see the MOTD? Please provide more details in the question itself. Use the EDIT button to fix and improve your question, adding the information I have requested, and any other information that may help us understand relevant environment details and what you have tried and done so far. Commented Apr 24 at 16:17
  • This might help: SSH client option to suppress server banners?
    – Cyrus
    Commented Apr 24 at 21:02

1 Answer 1

1

In order to disable (or otherwise manage) output of MOTD there are typically three places to consider.

  1. SSH server configuration, /etc/ssh/sshd_config. The documentation writes,

    PrintMotd Specifies whether sshd(8) should print /etc/motd when a user logs in interactively. (On some systems it is also printed by the shell, /etc/profile, or equivalent.) The default is yes.

    So

    PrintMotd no
    

    On my installation (Debian 12) this is already set as no, so it's clearly not the source of the message output.

  2. PAM. Looking in /etc/pam.d/sshd we can see

    # 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
    

    Open a root shell (sudo -s or other). Do not rely on using sudo as a prefix to edit and change the files. Open a root shell. Really. Save a copy of the file and then comment out these two session lines to disable MOTD. Restart sshd (systemctl restart sshd) and test that you can still log in. If there is an issue, use the still-open root shell to revert your changes and retest.

  3. Shell. Check in /etc/profile, /etc/bash.basrc, and other shell initialisation scripts to ensure that none is displaying MOTD. (It's unlikely, but we'll check.)

    grep -ril motd /etc/zsh /etc/bash.bashrc /etc/profile /etc/profile.d
    

    You can safely ignore any "No such file or directory" errors. On my system this found no matching files.

2
  • How would I add a comment in front of the two lines in /etc/pam.d/sshd using SED? Commented Apr 24 at 16:51
  • @themegamenuguy99 same as for any other file. Match on something unique to those lines (eg pam_motd) and insert a leading #. Perhaps sed '/pam_motd/s/^/#/' /etc/pam.d/sshd. Use sed -i to edit in-place once you've verified its output is correct - but not before! Commented Apr 24 at 21:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .