66

I was wondering how /etc/motd is automatically updated (I'm on Ubuntu 10.04, server edition). I found the update-motd manpage via a web search, but that program is not installed on my machine. The /etc/motd file is regularly updated, however. I just don't know how and how often. When doing a locate motd, following files are listed:

/etc/motd
/etc/update-motd.d
/etc/update-motd.d/00-header
/etc/update-motd.d/10-help-text
/etc/update-motd.d/20-cpu-checker
/etc/update-motd.d/50-landscape-sysinfo
/etc/update-motd.d/90-updates-available
/etc/update-motd.d/91-release-upgrade
/etc/update-motd.d/98-reboot-required
/etc/update-motd.d/99-footer
/home/me/.cache/motd.legal-displayed
/lib/security/pam_motd.so
/usr/bin/motd+shell
/usr/lib/update-manager/release-upgrade-motd
/usr/lib/update-notifier/update-motd-cpu-checker
/usr/lib/update-notifier/update-motd-reboot-required
/usr/lib/update-notifier/update-motd-updates-available
/usr/share/base-files/motd.md5sums
/usr/share/man/man1/motd+shell.1.gz
/usr/share/man/man5/motd.5.gz
/usr/share/man/man5/motd.tail.5.gz
/usr/share/man/man5/update-motd.5.gz
/usr/share/man/man8/pam_motd.8.gz
/usr/share/ubuntu-serverguide/html/C/pam_motd.html
1
  • I don't is /etc/motd on Ubuntu 14.04 LTS. The files now are /var/run/motd.dynamic and /run/motd.dynamic which are hard linked. motd is updated if you do not do hushed login. In that case you would see the contents that are created lastly when a user does a login in "non-hushed" mode. Jan 6, 2018 at 7:11

3 Answers 3

67

It's updated by pam_motd on login. The update-motd manual page describes this:

   Ubuntu introduced the update-motd framework, by which  the  motd(5)  is
   dynamically assembled from a collection of scripts at login.

   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.  The order of script execution is determined by the run-
   parts(8) --lsbsysinit option (basically alphabetical order, with a  few
   caveats).

   On   Ubuntu   systems,  /etc/motd  is  typically  a  symbolic  link  to
   /var/run/motd.
5
  • 33
    you can force with sudo run-parts /etc/update-motd.d/
    – Pete
    Nov 22, 2013 at 19:09
  • @Pete, I tried that command, and although it printed out the relevant information, it did not actually change the text in /etc/motd. Is this expected? Dec 20, 2013 at 15:16
  • 5
    @snapfractalpop, Sorry, I was wrong. You can use run-parts for debugging, it will spit out what the resulting motd will be if you are making additions to /etc/update-motd.d. As far as I can tell, the only way to update the file is by triggering pam_motd. On my system it appears to be the services login and sshd (grep pam_motd /etc/pam.d/*)
    – Pete
    Dec 20, 2013 at 20:40
  • 7
    @snapfractalpop Yes, that's expected. If you want to update /etc/motd redirect the output there: run-parts /etc/update-motd.d/ | sudo tee /etc/motd
    – n.st
    Jan 4, 2014 at 3:23
  • 3
    To speed up logins on my machine, I switched from libpam-motd to update-motd. Update-motd uses a cronjob instead of triggering the update on login. sudo apt-get remove libpam-motd; sudo apt-get install update-motd
    – xer0x
    Oct 9, 2014 at 3:38
14

The accepted answer above is correct, however incomplete. I'm hoping this provides a bit more info for the OP.

Basically, on a fresh install, the motd is generated from three places:

  1. The scripts in /etc/update-motd.d/
  2. The compiled binaries controlled by /etc/pam.d/login
  3. The /etc/legal file

Number 3 there refers to the block of text at the end of your motd that includes "Ubuntu comes with ABSOLUTELY NO WARRANTY ...", that's the /etc/legal file. However you will not find anything under /etc/update-motd.d/ that mentions it, nor does the word "legal" appear anywhere in the /etc/pam.d/login file. It's inclusion has been made obscure and I really don't know how it gets in there. I mean I know there's a {$HOME}/.cache/motd.legal-displayed but I don't know where that comes from either (yet).

The /etc/pam.d/login file is responsible for the notification of pending email, however that is not obscure. There's a nice comment describing:

Prints the status of the user's mailbox upon successful login

...right there in the file. I suppose technically that is not really a part of the motd, but it shows up at login and if you're new that fine distinction may not be appreciated.

On a fresh install of 14.04 there is no /etc/motd file. If you create one (or create a motd.static and symlink it to motd) the contents of that file will be appended to text generated by the update-motd.d scripts but the contents of /etc/legal will stop showing up. Go figure. The email notice still appears so this does not interrupt the /etc/pam.d/login script so I doubt /etc/legal is being pulled in from there. Its sourcing remains a mystery for the reader. I have noticed that when I remove the /etc/motd link (or file) the legal disclaimer does not immediately come back. It takes a few minutes. I did not want to constantly see the disclaimer so I deleted the text from that file.

Cheers.

1
  • 1
    Oh, I forgot one part. If you're accessing your machine via ssh there is also a setting in the /etc/ssh/sshd_config file of "PrintLastLog". That's what controls the "Last login: ..." line, which is the last thing to print after a successful login. Setting it to "no" will not make the line go away, just hide the IP address of the last successful ssh connection. Again, not technically part of the motd but then neither is the darn legal disclaimer and it keeps showing up.
    – David Kuhl
    Aug 20, 2014 at 16:58
10

To expand a little on David Kuhl's answer:

A fresh install of Ubuntu Server 14.04.1 LTS apparently does not install landscape-common nor update-notifier-common packages. Thus the following scripts are not installed:

/etc/update-motd.d/50-landscape-sysinfo
/etc/update-motd.d/90-updates-available

Thus, to get all of the ssh login information available from servers migrated from 12.04 LTS one must install the above packages manually:

sudo apt-get install landscape-common update-notifier-common

You must log in to answer this question.

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