Strovent SystemsSign in
Reference

Turn off the SSH login message: motd, "Last login" and the pre-login banner

The text after an SSH login comes from the motd, PAM and Last login; the text before the password is the Banner. Hide yours with ~/.hushlogin or change sshd.

Logging in over SSH can print a page of text before your prompt: a welcome note, system information, update counts and a Last login: line. On a small screen that pushes everything else away. Where the text comes from decides how to turn it off.

Which text is which

| What you see | When | Where it comes from | |---|---|---| | A notice before you are asked for a password or key | before login | sshd's Banner setting | | Last login: ... from ... | after login | sshd, when PrintLastLog is on (the default) | | The message of the day | after login | /etc/motd printed by sshd when PrintMotd is on, or a PAM module such as pam_motd | | Text printed by your shell | after login | your ~/.bashrc, ~/.profile or the system's /etc/profile files |

On Debian and Ubuntu, the packaged sshd_config sets PrintMotd no, and the message of the day comes from pam_motd instead, through two lines in /etc/pam.d/sshd. On Ubuntu, pam_motd runs the scripts in /etc/update-motd.d at each login to build it.

Hide it for your own account: ~/.hushlogin

touch ~/.hushlogin

When this file exists in your home folder, sshd does not show the last login time or the message of the day, and the PAM text it would show after login is skipped as well. It does not hide the Banner, which is shown before login, when sshd does not yet know who you are.

To get the messages back, delete the file: rm ~/.hushlogin.

Turn it off for everyone (administrator)

In /etc/ssh/sshd_config, or a file in /etc/ssh/sshd_config.d/:

PrintMotd no
PrintLastLog no

Then check the file with sudo sshd -t and reload the SSH service. A value set in an earlier file wins, so if a setting seems to be ignored see sshd_config.d drop-in ignored: the first value wins (KexAlgorithms and others).

For text from pam_motd:

  • Silence one message by putting a link to /dev/null in /etc/motd.d with the same file name as the message, for example ln -s /dev/null /etc/motd.d/my_motd.
  • On Ubuntu, a script in /etc/update-motd.d that is not executable is not run.
  • To stop pam_motd for SSH logins entirely, comment out its session lines in /etc/pam.d/sshd.

The pre-login Banner is off unless sshd_config names a file with Banner. Banner none turns it off.

Text that keeps coming back

If the text is still there after all of the above, it is printed by a shell startup file. Look for echo, cat, neofetch or similar lines in ~/.bashrc, ~/.profile and the files in /etc/profile.d/. Text printed there can also break SFTP: see SFTP "Received message too long".

Sources

Spotted a mistake? Email [email protected].