How does /etc/motd.d directory works?


My system has /etc/motd and /etc/motd.d/ by default. I can use the first one: it’s just a text file and the content of which is printed by motd after logging into the terminal. However, I don’t know how to use /etc/motd.d/ directory. My assumption was that it is the same as the previous one, but there you could split the motd message into pieces, from which a whole message is assembled. For example, /etc/motd.d/10-welcome, /etc/motd.d/20-hostname and /etc/motd.d/30-noticeboard, the output:
Today is maintenance break at 20:00.".
However, it apparently doesn’t do this or nothing else I’ve tested. So how does the /etc/motd.d/ directory work and what are its use cases?


You create files in /etc/motd.d with it ending in .motd, for example:

echo "Test" > /etc/motd.d/test.motd

now when I login I will see that appear. So yours would need to be named /etc/motd.d/10-welcome.motd and so on.

1 Like

In which file is this defined (file extension must be .motd)?

Yes file extension must be .motd for it to work.

You misunderstood my question, in which file or part of the source code is it specified that .motd file extension is reduired? As far as I know the upstream motd does not need this file extension.

Hi @karpse

CentOS 7 has no /etc/motd.d directory by default. CentOS 7 was released in 2014 and uses pam 1.1.8. /etc/motd.d was introduced in pam 1.3.1 in 2018. The pam_motd man page in CentOS 7 does not mention this directory. Creating an /etc/motd.d directory and putting files there has no effect in CentOS 7.

Rocky 8 and Rocky 9 support /etc/motd.d. Files located there are displayed in addition to /etc/motd. By default a message about cockpit is present:

$ ls -l /etc/motd.d
total 0
lrwxrwxrwx. 1 root root 22 May 22 11:50 cockpit -> ../../run/cockpit/motd

Note that this is only valid for a login through ssh. Messages from /etc/issue and /etc/issue.d are displayed when doing a login in the console (in Rocky 8 and 9).

Please keep in mind that each Linux distribution implements the login in different ways. Don’t mix CentOS, Rocky, Arch and so on.

1 Like

Yep, let’s forget CentOS, Ubuntu, Arch Linux, etc. Arch Linux’s man page was linked in the GitHub comment only because it was the first search result on Google and it was similar to the Rocky Linux man page.

So, why name of the symlink is “cockpit” in your example? Didn’t the files in the /etc/motd.d/ directory have to have .motd file extension?

Apparently they don’t need any particular name (nor omit any pattern):

[jlehtone@x motd.d]$ ll
-rw-r--r--. 1 root root  6 Oct 30 13:34 test
-rw-r--r--. 1 root root  6 Oct 30 13:34 test~
[jlehtone@x motd.d]$ cat test
[jlehtone@x motd.d]$ cat *
[jlehtone@x motd.d]$ ssh x
Last login: Sun Oct 30 13:35:56 2022 from

I tested and it doesn’t have to, why do you think so?

Yes it seems you don’t. I tested again today on Rocky 9, and it worked both ways. Not sure why.

Okey, I reinstalled Rocky Linux and all works as it should. The order of values ​​works (first /etc/motd and /etc/motd.d, then /run/motd and /run/motd.d, etc.), when logging into the system pam_motd shows content of the motd file at the top and then content of all motd.d files and not .motd extension ​​needed. So everything works as I originally assumed, that it should work and there is no more confusion with these, thank you. Now I’m just trying to get it working on other distros, or I’ll use Rocky Linux, we’ll see.


$ cat /etc/motd
This is motd file
$ cat /etc/motd.d/10-welcome
Welcome from motd directory
$ cat /etc/motd.d/20-message
Todays message from motd directory
$ cat motd.d/*
Welcome from motd directory
Today's message from motd directory
$ ssh localhost
user@localhost's password: 
This is motd file
Welcome from motd directory
Todays message from motd directory
Welcome from motd directory
Last login: Sun Oct 30 14:53:06 2022 from
1 Like