Configure Access to MOTD Files

Description

The files that make up the message of the day, /etc/motd, /run/motd, /usr/lib/motd, the files in /etc/motd.d, /run/motd.d and /usr/lib/motd.d, and the scripts in /etc/update-motd.d, must be owned by root, group-owned by root, and have mode 0644 or more restrictive. For a symbolic link, the owner, group and mode of its target count. To set them on a file, run:

$ sudo chown root:root /etc/update-motd.d/00-header
$ sudo chmod u-x,go-wx /etc/update-motd.d/00-header

Since run-parts runs only executable files, a script in /etc/update-motd.d with mode 0644 stops contributing to the message of the day.

Rationale

Restrictive ownership and permissions prevent unauthorized users from changing the text displayed to users after login.

Remediation

Shell script

The following script can be run on the host to remediate the issue.

#!/bin/bash

for motd_file in /etc/motd /run/motd /usr/lib/motd /etc/motd.d/* /run/motd.d/* /usr/lib/motd.d/* /etc/update-motd.d/*; do
    [[ -f "$motd_file" ]] || continue
    chown root:root "$motd_file"
    chmod u-xs,g-wxs,o-wxt "$motd_file"
done