12

I recently did a fresh install of Ubuntu 14.04. When I SSH, there is no MOTD (and yes, I have the appropriate command set in sshd_config).

I read a bunch of tutorials about setting up MOTD, but I realized that while I have /etc/update-motd.d, there is not /etc/motd file nor a /var/run/motd file.

How can I set these up so that I can get a MOTD via SSH?

alxlvt
  • 253
  • 1
  • 2
  • 5
  • 6
    Does sudo run-parts /etc/update-motd.d/ display the expected information? – Seth Oct 18 '14 at 21:43
  • Yes, it does. Though I don't see that after ssh login... – alxlvt Oct 19 '14 at 06:17
  • Check if in /etc/pam.d/login are present two uncommented lines that start with session optional pam_motd.so – Lety Oct 25 '14 at 15:07
  • Yes, there are two uncommented lines: session optional pam_motd.so motd=/run/motd.dynamic noupdate and session optional pam_motd.so – alxlvt Oct 25 '14 at 19:00
  • Could you check if PrintMotd and UsePAM in /etc/ssh/sshd_config are set to yes? – Lety Nov 03 '14 at 22:08
  • PrintMotd yes was in there, but nothing about UsePAM. – alxlvt Nov 04 '14 at 23:28
  • 1
    Sorry, for late. Try adding UsePAM yes and let's see if it fix the problem. Also, please could you add @Letizia in your comment otherwise I will not get notification. – Lety Nov 13 '14 at 22:59

4 Answers4

16

On a base install of Ubuntu 14.04.2 LTS, simply drop the message you want in:

/etc/motd

By default, the MOTD will appear at the end of the other dynamic MOTD content. For example, here's the output from a Vagrant ubuntu/trusty64 (v20150506.0.0) box with a /etc/motd file added:

$ vagrant ssh
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-52-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Thu May 14 20:06:56 UTC 2015

  System load:  0.39              Processes:           78
  Usage of /:   2.8% of 39.34GB   Users logged in:     0
  Memory usage: 24%               IP address for eth0: 10.0.2.15
  Swap usage:   0%

  Graph this data and manage this system at:
    https://landscape.canonical.com/

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

0 packages can be updated.
0 updates are security updates.


#####################################
Howdy! This message is from /etc/motd
#####################################

Last login: Thu May 14 20:06:56 2015 from 10.0.2.2
vagrant@vagrant-ubuntu-trusty-64:~$

That's all there is to it if you're working on a system with the default settings.


Some other troubleshooting notes:

  • Using "/etc/motd" is a change from earlier versions. Recommendations for 12.02 were to use "/etc/motd.tail". That doesn't work in 14.04.2.

  • Other recommendations I've seen include changing some values in "/etc/ssh/sshd_config". In case those have been altered, here's the defaults that work:

    UsePAM yes
    PrintMotd no
    
  • Likewise, here are the defaults for the /etc/pam.d/login I've seen referenced:

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

That's everything I've seen referenced for troubleshooting.

2

Try to add:

 UsePAM yes

in your /etc/ssh/sshd_config as suggested in this bug and in Can't configure MOTD properly in Ubuntu 10.04 Server (update-motd command not found)

With UsePAM enabled, PAM will automatically update the MOTD and print it for you when you log in. You have to disable PrintMOTD or SSH will print it as well, so you'll see it twice, which is annoying.

I'm not sure about this, but in case you get motd twice, you should set PrintMOTD to no.

Lety
  • 6,039
  • 2
  • 29
  • 37
1

Add the following line to /etc/pam.d/sshd :

session    optional   pam_motd.so  motd=/run/motd.dynamic noupdate
hg8
  • 13,462
Edik Mkoyan
  • 349
  • 1
  • 3
  • 11
0

In my case, it was because one of the scripts in /etc/update-motd.d failed to run (giving a non-zero exit code). Fixing it made MOTD start appearing again.

If you're unsure which one it is, just append a line exit 0 to all scripts in that directory.

I noticed this on my machines running Ubuntu Disco and Debian Buster, but I am confident that it's applicable on Ubuntu Trusty (and even Precise).

iBug
  • 1,589