71

I have changed /etc/issue.net, so I have set a "personal" message after typing a username in an SSH terminal. Now I am trying to change the welcome text after successful login.

I have found a lot of posts about the /etc/motd file, but the part "Welcome to Ubuntu blabla versionnumber and so on" + "* Documentation URL " is not there?

I just do not want to show OS info in my SSH terminal, I already know what I have installed. :) I only want to see my last login. And also not errors; errors belong in a logfile.

Which file do I have to edit?

4 Answers 4

95

The welcome messages are generated by the files residing in /etc/update-motd.d/.

From man update-motd:

Executable scripts in /etc/update-motd.d/* are executed by pam_motd(8) as the root user at each login, and this information is concatenated in /var/run/motd.

So if you don't want the outputs of those scripts upon login via ssh just remove the execute flag on them:

sudo chmod -x /etc/update-motd.d/*

Now if you want to show something you want upon login, you have two options:

  • Make a script, put it in /etc/update-motd.d/, make it executable, also make sure it outputs on STDOUT.

  • ssh has a Banner option. You can put the text in a file and set it in the Banner option so that the content of the file is shown upon login via ssh. Note that this is applicable to only ssh.

    Banner /etc/foobar
    

    From man 5 sshd_config:

     Banner  The contents of the specified file are sent to the remote user
             before authentication is allowed.  If the argument is “none” then
             no banner is displayed.  This option is only available for
             protocol version 2.  By default, no banner is displayed.
    
10
  • 16
    My favorite answers all start with "From man xyz" ;)
    – A.B.
    Sep 20, 2015 at 18:07
  • Thank you! Now i know the relationship between those files. I did not chmod them, just added # before some lines i do not want to show.
    – Terradon
    Sep 20, 2015 at 18:47
  • @Terradon Yeah, that would do too..i just generalized the solution because many people won't like to look into the file much..
    – heemayl
    Sep 20, 2015 at 18:49
  • 2
    Great clean solution because chmoding the files means I don't have to edit them. Nice!
    – culix
    Aug 8, 2016 at 4:27
  • 3
    ...why do they put so much crap in the motd and waste people's time disabling it :s Nice solution with the chmod -x !
    – Motsel
    Feb 1, 2019 at 9:04
66

Another way that does not require administrative rights is to place an empty file called

.hushlogin

into your $HOME directory (using for example touch ~/.hushlogin).

The downside to this solution is that you might miss a message saying something like

Last login: Wed Aug 22 16:00:10 2007 from l33t.hax0r.some.ips

that indicates your account has been compromised.

Source.

5
  • 5
    Elegant, simple, doesn't mess with other users, no sudo. Thanks. Sep 24, 2019 at 0:37
  • 5
    this is not "another way" but the best way !
    – Yunus
    Mar 16, 2020 at 23:31
  • 2
    this should be the most upvoted answer
    – mao95
    Feb 12, 2022 at 11:47
  • This should be the right answer. Jun 17, 2023 at 16:30
  • @PhilippeRemy The user explicitly said that he wants to see the last login information. This answer hides the last login information.
    – Toxiro
    Feb 13 at 11:15
6

You can also nuke pam_motd altogether:

sed -i '/^[^#]*\<pam_motd.so\>/s/^/#/' /etc/pam.d/sshd

PAM calls pam_motd depending on the settings in /etc/pam.d, and typically the entries are:

$ grep pam_motd /etc/pam.d -R
/etc/pam.d/login:session    optional   pam_motd.so  motd=/run/motd.dynamic noupdate
/etc/pam.d/login:session    optional   pam_motd.so
/etc/pam.d/sshd:session    optional     pam_motd.so  motd=/run/motd.dynamic noupdate
/etc/pam.d/sshd:session    optional     pam_motd.so # [1]

Just commenting out the pam_motd lines from these files will disable it.

3
  • Thanks for your time, but with "Nuke them all" i dont know what i am doing. (I am new to linux/ubuntu).
    – Terradon
    Sep 20, 2015 at 18:54
  • 1
    @Terradon you're telling PAM not to call pam_motd.so, that's all.
    – muru
    Sep 20, 2015 at 18:55
  • Thanks, i will take a closer look at what PAM.does exactly.
    – Terradon
    Sep 20, 2015 at 19:01
6

There might also be file under /etc/motd containing a welcome message which can easily be removed (the content).

1
  • Thanks this was the case on Debian 10, and a nice quick easy fix!
    – kjones
    Mar 9, 2021 at 23:19

You must log in to answer this question.

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