Differences between revisions 18 and 19
Revision 18 as of 2017-01-21 23:38:01
Size: 6148
Editor: AlbanVidal
Comment: Add pam_motd manpage link. Links to Gentoo wiki is brocken.
Revision 19 as of 2017-04-23 01:04:35
Size: 6117
Editor: PaulWise
Comment: use Debian manpages
Deletions are marked like this. Additions are marked like this.
Line 11: Line 11:
The actual motd is generated and printed by pam_motd, see its [[https://linux.die.net/man/8/pam_motd|manpage]]. The actual motd is generated and printed by pam_motd, see its [[DebianMan:8/pam_motd|manpage]].
Line 142: Line 142:
 * [[http://linux.die.net/man/5/motd|Simplest motd manpage I could find]]  * [[DebianMan:5/motd|Simplest motd manpage I could find]]

Translation(s): English - Français - Italiano


Wheezy and above

Currently /etc/motd is user editable and static in Wheezy - The file will not be overwritten by reboot.

The actual motd is generated and printed by pam_motd, see its manpage.

/etc/motd in Debian before and in squeeze

Debian has a peculiar way of handling /etc/motd. The motd is updated at every reboot, in a boot script (/etc/init.d/bootmisc.sh in lenny and below, /etc/init.d/bootlogs in squeeze and above), which basically runs the following:

uname -snrvm > /var/run/motd
[ -f /etc/motd.tail ] && cat /etc/motd.tail >> /var/run/motd

Since /etc/motd is a symlink to /var/run/motd in Debian, this works.

How to update your /etc/motd

Since /etc/motd basically gets overwritten at every reboot, you need to instead update /etc/motd.tail and either reboot (!!) or also edit /etc/motd.tail or run the above commands. There is a bug report (437176) to provide an easier command to allow you to update only /etc/motd.tail.

How to script updates to your /etc/motd

A little less known thing about /etc/motd in Debian and Ubuntu is that pam will actually update your /etc/motd based simply on the scripts in /etc/update-motd.d. So to replicate the above scripts, you could do:

mkdir /etc/update-motd.d
cat > /etc/update-motd.d/10uname <<EOF
#! /bin/sh
uname -snrvm
EOF
cat > /etc/update-motd.d/20tail <<EOF
#! /bin/sh
[ ! -f /etc/motd.tail ] && exit 0
cat /etc/motd.tail
EOF
chmod a+x /etc/update-motd.d/*

Then you could add other scripts to your /etc/update-motd.d directory to add stuff to your /etc/motd. See the manpage for more information.

Note that this technique is using a patch that is shipped only with Debian and Ubuntu and not factored into upstream PAM. Furthermore, this code has had security issues in the past (CVE-2010-0832, this bug).

How to keep your /etc/motd from being overwritten

rm /etc/motd
cat > /etc/motd <<EOF
This is my message of the day!
EOF

This way, /etc/motd is not a symlink to the updated one anymore and will therefore always stay the same. The downside to this is that you will not see the latest kernel version in the motd.

Old school "don't touch my motd" approach

Similar to the above, this approach also makes sure dynamic information can be displayed...

cat > /etc/profile.d/uname <<EOF
#!/bin/sh
uname -snrvm
EOF
rm /etc/motd
cat > /etc/motd <<EOF
Known issues
============

 * the kerkuffle is known to not restart properly on reboot, to restart use the command
   service kerkuffle restart

Who's responsible for /etc/motd?

Here's a list of packages which do that work:

base-files: /usr/share/base-files/motd
base-files: /usr/share/base-files/motd.md5sums
manpages: /usr/share/man/man5/motd.5.gz
manpages: /usr/share/man/man5/motd.tail.5.gz
libpam-modules: /lib/x86_64-linux-gnu/security/pam_motd.so
initscripts: /etc/init.d/bootlogs
  • base-files basically takes care of installing the motd on boot but will not replace it on upgrade (see /usr/share/doc/base-files/README)

  • manpages explains how motd and motd.tail work

  • libpam-modules has a pam_motd module which displays the motd file. It also has a patch (in squeeze and above, from Ubuntu) to run the scripts from /etc/update-motd.d to update the motd on login.

What others do

Ubuntu

Since Ubuntu Intrepid Ibex (2008.10), Ubuntu has had a /etc/update-motd.d/ directory, from which scripts are ran to update the /etc/motd file. This is now factored into the pam_motd module, which updates the /var/run/motd file, using this C code:

    if (do_update && (stat("/etc/update-motd.d", &st) == 0)
        && S_ISDIR(st.st_mode))
    {
       mode_t old_mask = umask(0022);
       if (!system("/usr/bin/env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ru
n-parts --lsbsysinit /etc/update-motd.d > /var/run/motd.new"))
           rename("/var/run/motd.new", "/var/run/motd");
       umask(old_mask);
     }

For a short while, this was instead done by the update-motd pacakge every 10 minutes.

By default Ubuntu ships with a set of scripts that add the number of packages to be update (for example).

Gentoo

Gentoo doesn't display the motd file by default, but this can be enabled in login.defs, see this wiki page.

Arch, CentOS, and others

According to this this wiki page, Arch doesn't seem to do anything special to /etc/motd other than display it on boot.

FreeBSD

In FreeBSD, the motd file is also generated through a boot script, which will preserve modifications by changing only the line that matches (loosely) the uname that gets updated on reboots. The magic lines:

T=`mktemp -t motd`
uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}

References


CategoryCommandLineInterface