Skip to content

Creating a custom motd on Debian Jessie

Chris edited this page Dec 27, 2017 · 10 revisions

A couple of hours in the evening, a couple of hours in the after, and a few questions on IRC later, I have a custom motd (message of the day). I'm taking the time to write this article just for the sheer fact that this process took way longer than expected, and for the fact that I want to have something to reference if I ever have to do this again.

cheers 🍻
Chris

So if I remember correctly Debian 8 (Jessie) was the first major version of Debian to introduce systemd (let's not go down the systemd love / hate rabbit πŸ‡ hole) shall we.

So, doing a quick google search for debian motd will more than likely put this article in the top of the results. Now as informative at that article is, I find lacking some information to complete the custom motd on a Debian 8 (Jessie) box. I'll try and fill the gaps where that article leaves off.

For starters, my Debian 8 box is a digital ocean droplet, and not a Raspberry Pi.

So the first I noticed, is that motd is now a service provided by systemd. If one try's to run the below command,

systemctl start motd

your more than likely not going to get that far, just for the fact that the motd service is in a masked state. So before you can even enable the motd service, you're going to want to "unmask" the service. So if your thinking well let me just run the below command,

systemd unmask motd

however, that won't get you that far either. 😏 So after going back to the googler and refining my searches I came across this nice answer. So if you don't want to go down the link rabbit πŸ‡ hole (can't say that I don't blame you) then I will try and transpose what that answer states. If the systemd service is linked to /dev/null then run the below commands.

file /lib/systemd/system/motd.service

which should return

/lib/systemd/system/motd.service: symbolic link to /dev/null

so your going to want to delete,

sudo rm /lib/systemd/system/motd.service

Since you changed a unit file, you need to run this:

sudo systemctl daemon-reload

now check the status:

systemctl status motd

Now it's green and running :) The service has no systemd unit file, but systemd happily uses the script for it in /etc/init.d instead. For my particular use case I ssh into this box 99% of the time, so I want to have the motd displayed when I log in with my standard user account on the box. So if I remember correctly, you're going to want to edit the file,

sudo nvim /etc/pam.d/sshd

and make sure you have the below line in there

session optional pam_motd.so motd=/etc/motd Next, I made the /etc/motd file a symlink to /var/run/motd with below command,

sudo ln -sf /var/run/motd /etc/motd

With that set up, I was able to place custom shell script files within /etc/update-motd.d with a filename of 02-header and 50-footer. Next make sure all the scripts are executable within the above mentioned directory by running the below command,

sudo chmod +x /etc/update-motd.d/*

Note: if you don't want a particular script to run from within this directory simply remove the executable bit from the file with the below command.

sudo chmod -x /etc/update-motd.d/51-test

Now you should be all set up to see your custom motd displayed when you login to this particular box again. So for my particular use case I have two caveats.

  1. I use 🐟🐚 (fish-shell)
  2. I want to display "motd" that is greater than 64KB in size.

Well the peeps on IRC frowned upon the idea of making a motd greater than 64KB, and suggested I run a custom script from within /etc/profile.d which would lead to the script running every time I login to the box. However I since I'm running fish shell as my default shell these scripts will not run.

So I ended up creating an /etc/environment and putting the below line within it,

SHELL=/usr/bin/fish

And then from reading the fish documentation, one can edit the global fish shell configuration file located within > /etc/fish/ by running the below command,

sudo nvim /etc/fish/config.fish

and placing the single line within it,

/home/$USER/.cargo/bin/termpix --true-color /etc/environment.d/cable.jpg

Pheww, take a deep breath, pat yourself on the back, and everything goes well, you should see something like the below, obviously your mileage 🏎 will vary depending on what you put in your scripts, but for my particular use case I see something like the following in my terminal now.


custom-motd

Clone this wiki locally