How to customize ubuntu’s message of the day

I like to have a banner display at login to my servers when I use Secure Shell (SSH) to access them. Once upon a time, this was done by putting a static message in a static file called /etc/motd .

Since 2008, in Ubuntu, this system has changed allowing administrators to easily call dynamic content and have it added to the motd.

There’s a directory called /etc/update-motd.d/ that holds shell scripts that are executed pretty much in alphabetical order with the resulting output displayed to the logging in user.

/etc/update-motd.d Contents

The leading two digit number (00 to 99) will determine where the file is alphabetically, and thereby where it will be in the order of items displayed. Lower numbers like 00 or 10 will be displayed first but will scroll up as subsequent files are processed and their output is displayed.

Processing these files results in seeing something similar to the following upon a successful SSH login:

There’s a lot of useful information there, but no banner saying only authorized connections are permitted.

Each section of the output comes from an individual file in /etc/update-motd.d

To add my warning to logging in users, I’ve added a file called 96-access-warning . I want the login warning displayed near the end of the motd script output so it is visible, but I want a few things like Last login date and time displayed after.

There was a file 95-hwe-eol , and a file 97-overlayroot , so I made one in between called 96-access-warning .

sudo vim 96-access-warning while in the /etc/update-motd.d/ directory.

The file had the following content:

Next, you have to set the file to be executable.

sudo chmod +x 96-access-warning

Now, users logging in will see output similar to the following:

There you have it! Want something else displayed at login? Add an appropriate shell script to /etc/update-motd.d with a number that will place it in the order you’d like it displayed.

If you like the text based artwork for Authorized Access Only!, you can generate your own quickly for free. It’s called ascii art, and there are many sites that will do this for you. I used patorjk.com’s text to ascii art generator.

I’ve created a super-small github repo for this.

Ted LeRoy

Full time: Enterprise Security Architect Part time: Udemy Instructor, Ubuntu Linux Fundamentals – Learn Linux Server with Ubuntu

Treat Yourself To More Linux Server Knowledge

$9.99 coupon for my Udemy Ubuntu Linux Fundamentals course.

How to customize ubuntu’s message of the day

Have A Ubiquiti UniFi Device? Make Sure To Change Your Default Credentials!

I was checking the security logs on one of my servers as I often do and noticed attempts to log into SSH using a curious username. My servers are all set up to

The personal site of Mark H. Nichols.

How to customize ubuntu’s message of the day

  • About
  • Archive
  • Colophon
  • My Other Sites
  • Geek
  • Books
  • Health
  • Music

  • How to customize ubuntu’s message of the day

I’ve always liked the message of the day the Freenode displays when you connect to IRC. With both a laptop and a desktop running Ubuntu 17 these days, I wanted to have a custom message of the day (MOTD) that followed a similar pattern as Freenode uses.

Ubuntu stores the components of the MOTD in /etc/update-motd.d .

Each of these parts is executed in numerical order, and each is a small bash shell script. You can see the current MOTD by running

In order to customize my message of the day I added a new part, 05-fermata . The 05 puts it just after the initial header, and fermata happens to be the name of the machine. The file itself contains this:

Now when I run run-parts /etc/update-motd.d/ or when I ssh into the machine or create a new terminal session, the MOTD includes the name of the machine and a brief description of that name.

Mark H. Nichols

I am a husband, cellist, code prole, nerd, technologist, and all around good guy living and working in fly-over country. You should follow me on Twitter.

Share this post

Suppress message of the day for specific user or multiple user respectively.

Default message of the day looks like this.

Remote OpenSSH session

Per user option

To suppress message of the day for specific user create

/.hushlogin file on remote server.

Global option for every user

To suppress message of the day for every user on remote server perform three simple steps.

Ensure that PrintLastLog option and PrintMotd respectively are disabled in OpenSSH server configuration /etc/ssh/sshd_config .

Reload service after configuration update.

Ensure that PAM configuration /etc/pam.d/sshd for OpenSSH server does not use pam_motd module.

This behavior is defined in OpenSSH session.c file.

Local session

Per user option

Inspect default /etc/login.defs configuration to check HUSHLOGIN_FILE option.

/.hushlogin file to suppress message of the day for particular user.

This behavior is defined in Shadow shadow/libmisc/hushed.c file.

Global option for multiple users

Alter /etc/login.defs configuration to define system-wide /etc/hushlogins file as HUSHLOGIN_FILE .

Add user login to /etc/hushlogins to suppress message of the day for specific user.

Add login shell to /etc/hushlogins to suppress message of the day for every user using specific shell.

This behavior is defined in Shadow shadow/libmisc/hushed.c file.

Bálint’s blog about some of the important things in the Universe

How to customize ubuntu’s message of the day

People logging in to Ubuntu systems via SSH or on the virtual terminals are familiar with the Message Of The Day greeter which contains useful URLs and important system information including the number of updates that need to be installed manually.

However, when starting a Ubuntu container or a Ubuntu terminal on WSL, you are entering a shell directly which is way less welcoming and also hides if there are software updates waiting to be installed:

To make containers and the WSL shell friendlier to new users and more informative to experts it would be nice to show MOTD there, too, and this is exactly what the show-motd package does. The message is printed only once every day in the first started interactive shell to provide up-to-date information without becoming annoying. The package is now present in Ubuntu 19.10 and WSL users already get it installed when running apt upgrade .
Please give it a try and tell us what you think!

Bug reports, feature requests are welcome and if the package proves to be useful it will be backported to current LTS releases!

Related

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

How to customize ubuntu’s message of the day

Geoffrey_Carr

How to customize ubuntu’s message of the day

Az Ubuntu egy olyan tájékoztató üzenetet jelenít meg, amelyet a napi üzenetként ismerünk el, amikor egy felhasználó bejelentkezik a terminálon. A MOTD teljes mértékben testreszabható – hozzáadhatja saját szövegét és egyéb dinamikus adatait.

Amikor egy felhasználó bejelentkezik, a pam_motd folyamat végrehajtja a scripteket a /etc/update-motd.d könyvtárban, és dinamikusan létrehozza a napi üzenetet. A MOTD testreszabása a szkriptek módosításával, eltávolításával vagy saját szkriptek írásával lehetséges.

A nap alapértelmezett üzenete

A napi üzenet csak akkor jelenik meg, ha az Ubuntuban szöveges módban, nem pedig grafikus módban jelentkezik be. A grafikus asztal használata esetén a Ctrl-Alt-F1 billentyűparanccsal elérheti a virtuális terminált – használja a Ctrl-Alt-F7 parancsikont, hogy visszatérjen a grafikus asztalhoz, amely X szerverként is ismert. A Ctrl-Alt-F2-től a Ctrl-Alt-F6-ig a többi virtuális terminálhoz vezet.

How to customize ubuntu’s message of the day

Itt van az Ubuntu szabványos MOTD. Megmutatja a tipikus rendszer verziószámokat, amelyekről ismeri, ha régóta Linux-felhasználó vagy. Dinamikusan generált információkat jelenít meg az Ubuntu licencéről rendelkezésre álló frissítésekről és statikus üzenetekről.

How to customize ubuntu’s message of the day

Egyéni üzenet hozzáadása

Tegyük fel, hogy hozzá szeretne adni egy olyan egyéni üzenetet, amelyet a felhasználók az Ubuntu rendszerbe történő bejelentkezéskor láthatnak. Az Ubuntu MOTD-jét szkriptek generálják, amikor bejelentkezel, tehát nem teheted az / etc / motd fájlba. A saját statikus üzenetek elhelyezésének helye az /etc/motd.tail – a fájl tartalma a MOTD végére kerül, amikor létrehozzák.

Használjuk a Nano szövegszerkesztőt az /etc/motd.tail fájl megnyitásához a következő paranccsal: (A Linux terminálvarázslók Vi-ot vagy Emacsot használhatják, de a Nano könnyebb az újszülöttek számára)

sudo nano /etc/motd.tail

How to customize ubuntu’s message of the day

Ez a fájl alapértelmezés szerint teljesen üres. Adjon meg minden tetszőleges üzenetet – szabadon őrülsz a fekete-fehér ASCII művészetben. Ha elkészült, mentse a fájlt a Ctrl + O és az Enter billentyűkombinációval, majd a Ctrl + X billentyűvel lépjen ki a Nano-ból.

How to customize ubuntu’s message of the day

Amikor a felhasználó legközelebb bejelentkezik, megjelenik az egyéni üzenet. Ha azonnal szeretné ellenőrizni, jelentkezzen ki a terminálból a kijárat parancsot és jelentkezzen be újra.

How to customize ubuntu’s message of the day

Információk eltávolítása

Most mondjuk el szeretnénk távolítani néhány alapértelmezett információt. Nem csak egy fájl szerkesztésére van szükség – minden szakasz automatikusan létrejön egy /etc/update-motd.d könyvtárban található szkriptből.

Ehhez a könyvtárban található fájlok teljes listáját kapja beírással /etc/update-motd.d a terminálon és nyomjuk meg a Tab billentyűt.

How to customize ubuntu’s message of the day

A szkriptek numerikus sorrendben futnak, ezért vannak számokkal ellátva. A szkriptfájlokat átnevezheti, és megváltoztathatja a számokat, ha tetszetét veszi a MOTD különböző részei sorrendjének átrendezésére.

A parancsfájl információinak eltávolítása a MOTD-ről csak meg kell akadályoznia a futást. Ezt úgy tehetjük meg, ha eltávolítjuk a végrehajtási jogosultságait a chmod -x parancs.

Ha a dokumentáció szövegét a MOTD-ben szeretnénk eltávolítani, a következő parancsot futtattuk:

sudo chmod -x /etc/update-motd.d/10-help-text

How to customize ubuntu’s message of the day

Amikor a felhasználó legközelebb bejelentkezik, a dokumentáció nem jelenik meg.

How to customize ubuntu’s message of the day

Dinamikus információk hozzáadása

Saját szkriptjeinket megírhatjuk bármilyen dinamikus információ hozzáadásához, amit szeretünk a MOTD-nek. Példaként próbáljuk meg használni az időjárás-kihasználó csomagot, hogy hozzon létre egy forgatókönyvet, amely hozzáadja a jelenlegi helyi időjárást a MOTD-hez.

Alapértelmezés szerint nincs telepítve, ezért telepítsük a következő parancsra:

sudo apt-get install weather-util

How to customize ubuntu’s message of the day

Szüksége lesz a helyi Nemzetközi Polgári Repülési Szervezet kódjára, amelyet ebből a weboldalról szerezhet. Az alábbiak szerint kell az időjárást használni a kóddal:

How to customize ubuntu’s message of the day

Most használja a következő parancsot egy parancsfájl létrehozásához a megfelelő helyen, és nyissa meg a Nano-val:

sudo nano /etc/update-motd.d/98-weather

Miután megnyílik a Nano, írja be a következő kódot, és helyettesíti a CODE-t a helyi időjárási kóddal:

echo weather -i CODE echo

Nyomja meg a Ctrl-O és az Enter billentyűt a mentéshez, majd nyomja meg a Ctrl-X billentyűt a kilépéshez.

How to customize ubuntu’s message of the day

Végezze el a parancsfájl futtatását chmod + x vagy nem fog futni:

sudo chmod +x /etc/update-motd.d/98-weather

Mostantól a felhasználók megtekintik a helyi időjárás-előrejelzést, amikor bejelentkeznek. Nincs semmi különös az időjárási felhasználással kapcsolatban – bármilyen parancsot használhat, amely szöveget nyomtat a terminálhoz.

How to customize ubuntu’s message of the day

A MOTD nem csak akkor jelenik meg, ha a felhasználók helyileg jelentkeznek be. Minden olyan felhasználó, aki távolian csatlakozik az SSH vagy a Telnet szolgáltatáshoz, szintén látni fogja a személyre szabott MOTD-t.

I would like to have a dynamic motd, but I can’t figure out how to do it.

I tried what I found, adding /etc/update-motd.d/00-header , 10-sysinfo , 90-footer , and symlinking to /etc/motd /var/run/motd.dynamic , /run/motd.dynamic , /run/motd or /var/run/motd .

I’ve got these lines in /etc/pam.d/sshd :

I’m also confused with systemd.

Is there a way to do this? Could someone provide a example with a simple fortune?

How to customize ubuntu’s message of the day

3 Answers 3

I am able to test simple dynamic-motd with fortune example on my Debian Jessie 8.2 host as below and found the issue to be related to a buggy behavior.

Created two test files as below and made them executable

However at this time, there was no change in motd. So i strace’d sshd process.From that trace (interesting parts shown below), you can see that newly created motd.new file is renamed to /var/run/motd. However it’s later trying to read from /run/motd.dynamic – which was never created

The issue seem to be related to inconsistencies with pam_motd module. See bug report https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=743286;msg=2

Simply changing motd file location from /run/motd.dynamic to /run/motd in /etc/pam.d/sshd – makes it work for me

Here is the sample MOTD seen during ssh login .

This has changed over the years:

First there was /etc/motd (static).

Then Ubuntu came up with their own package update-motd based on a script called from cron.

Highly customizable Message of the Day script for Raspberry Pi

How to customize ubuntu’s message of the day

Written in Bash. No other dependancies. So far tested with Raspbian Jessie only, but should work with most other Linux distributions.

The following steps may vary depending on the OS.

Download and save the motd.sh bash script onto your machine. Remember to add execute permissions and change the owner:

Simply execute the script to test if it works

You can remove default MOTD, but it’s not necessary since the script will clean the screen anyway.

For the same reason as above, not necessary, but you may want to remove the “last login” message. Disable the PrintLastLog option from the sshd service.

Restart the sshd service:

At the top of the file are variables allowing customization of the messages:

settings array contains all possible messages to be displayed. Comment lines with a # for messages you don’t want to see. Change order of items in array to change order of displayed messages.

weatherCode set region code for the weather message. Full list of available Accuweather location codes

degrees change value to “C” to show all temperatures in Celsius or “F” for Fahrenheit

colour array, lets you set your own colours. List of colour codes:

Comments

sffred commented May 21, 2020

/usr/lib/ubuntu-release-upgrader/release-upgrade-motd: 31: cannot create /var/lib/ubuntu-release-upgrader/release-upgrade-available: Permission denied

This is what the message shows on wsl once a day. Although it seems to be no harm, I still wonder how can I avoid this.

I have tried the chmod command to open the permission of release-upgrade-available, but it doesn’t work. Since the release-upgrade-motd belongs to root, there shouldn’t be any permission denied problem.

The text was updated successfully, but these errors were encountered:

therealkenc commented May 21, 2020

sffred commented May 25, 2020 •

Thanks. However I ran into trouble when trying some seemingly incomplete fix in the link.
Someone on that page posted a ‘harmful’ fix of an official package because he posted this fix in an inappropriate way – offering a non-official ppa containing a special version designed by himself. This package destroyed my apt and I have no idea about how to deal with this situation. Since my working environment in wsl is easy to rebuild, I reinstalled the wsl on my pc.
Surprisingly, this issue – the error message – didn’t pop up since then. So in a nut shell, Reinstalling wsl may fix this problem, although it’s not a good idea.

spaulaus commented Jun 17, 2020

I ran into the same issue. I resolved it by removing /var/lib/ubuntu-release-upgrader/release-upgrade-available . This causes /usr/lib/ubuntu-release-upgrader/release-upgrade-motd to skip to the second condition, but since I don’t login as root it never tries to write the file.

sffred commented Jun 18, 2020 •

@spaulaus maybe this is a solution, but I don’t like it. You say, it never tries to write the file unless you login as root? However, whenever I login, no matter if I am root, it always tries to write the file.
I have to admit that I made the conclusion too soon in the last comment. I said that reinstalling wsl will help, but it didn’t. The message pop up later again. Luckily, I managed to ‘fix’ it by opening the access of /usr/lib/ubuntu-release-upgrader (not the file, but the folder) using the command

and the message haven’t shown since then. It’s strange for that release-upgrade-motd should have the root authority but it cannot write the file.

spaulaus commented Jun 18, 2020 •

@sffred : I agree that this isn’t an optimal solution since it prevents the file from being generated.

Here’s the contents of /usr/lib/ubuntu-release-upgrader/release-upgrade-motd on my WSL install.

As you can see, the first if checks if the file exists. If the file does not exist, the elif checks if the executing user is root . My solution prevents the upgrade check from happening at all, by ensuring that both of these conditions are false. The file doesn’t exist and I don’t login as root.

Discussion based on a previous version of the above comment.
By default /usr/lib/ubuntu-release-upgrader has the following permissions:

Setting 664 on this directory will give drw-rw-r– , which will prevent any script from actually navigating into the folder at all. This gives the same effect as my solution since the script cannot confirm that the file exists, and the script is not being run as root. See the image below:

sffred commented Jun 18, 2020

@spaulaus : I made a mistake because I am not familiar enough with chmod. Actually I set it to 664 first and then found it was wrong and set it to 775 instead. Sorry for that and I have updated the comment.
I looked at my /usr/lib/ubuntu-release-upgrader/release-upgrade-motd and it’s just the same. Yeah, I agree with you that deleting the file will prevent it from being generated again, but when I deleted the file the message is still there. (Actually this is the first thing that I tried.) It’s really odd, but I’d ignore this issue and go on my work. Anyway, I have solved it now, at least to some extent.

spaulaus commented Jun 18, 2020 •

@sffred : No worries! I’ve confirmed that the script is running as the user logging in.

One more question: Did you get this message after upgrading to a new version of Ubuntu (e.g. from 19.10 -> 20.04) using do-release-upgrade ?

spaulaus commented Jun 18, 2020

After a little more research, I found the following solution, which prevents the release check all together. This is probably the safest solution.

sffred commented Jun 18, 2020

@sffred : No worries! I’ve confirmed that the script is running as the user logging in.

One more question: Did you get this message after upgrading to a new version of Ubuntu (e.g. from 19.10 -> 20.04) using do-release-upgrade ?

hhh that’s a sad story. I run do-release-upgrade several month ago and it totally broke my disto. I really experienced a hard time because I tried to fix it manually and it took me several hours. And I chose to reinstall wsl at last. After that I still get the message so I came here for help.

sffred commented Jun 18, 2020

After a little more research, I found the following solution, which prevents the release check all together. This is probably the safest solution.

Configuring login messages on Linux servers is more complex and dynamic. Let’s look at the message of the day setup on an Ubuntu server to decipher how the process works.

It seems only decades ago that I was commonly sending out notices to my users by editing the /etc/motd file on the servers I managed. I would tell them about planned outages, system upgrades, new tools and who would be covering for me during my very rare vacations.

Somewhere along the stretch of time since, message of the day files seem to have faded from common usage — maybe overwhelmed by an excess of system messages, emailed alerts, texts, and other notices that have taken over, the /etc/motd file has. Or maybe not.

+ Also on Network World: Half a dozen clever Linux command line tricks +

The truth is the /etc/motd file on quite a number of Linux systems has simply become part of a larger configuration of messages that are fed to users when they log in. And even if your /etc/motd file is empty or doesn’t exist at all, login messages are being delivered when someone logs into a server via a terminal window — and you have more control over what those messages are telling your users than you might realize.

Here’s an example of the messages that might be displayed on an Ubuntu server when someone logs in:

As you can see, there’s quite a lot of information there — details about the OS, some pointers showing where you can go to get more information on the OS, an appeal for your opinion on useful desktop alls, and some notices about package and security updates. Some of these messages are aimed at sysadmins. Others are useful for all users.

Even though no /etc/motd file existed on this server when these login messages were captured, the system has a lot to tell us and any user who logs in.

Instead, the configuration of login messages is much more complicated and dynamic than it was when the /etc/motd file came into being and was then used for many years as a primary way to communicate with users. Now, let’s take a look at where all of this information is coming from today — at least on one very popular Linux platform. For Ubuntu, one place to start looking is a directory named /etc/update-motd.d.

Each of these files has a role to play in building the sequence of login messages that is displayed. Looking first at a file called /etc/default/motd-news, the command shown below picks out the operative lines (non-blank and not comments), we see this:

Change the ENABLED setting to 0 and the motd.ubuntu.com message will no longer be included in the login messages. You can examine what the motd-news is right now by putting the URL into a browser, but expect that it will change from time to time.

The 00-header file composes the line describing the OS release by sourcing the /etc/lsb-release file and using what it finds to construct a message like this:

The 10-help-text file add these lines:

The 50-motd-news file adds the content of this URL

The 90-updates-available file contributes the lines about package and security updates using the /var/lib/update-notifier/updates-available file.

You can insert text that you want included in the login messages by creating or editing the /etc/motd file. Of course, if your users simply gloss over the login messages because they become more or less routine, you might want to highlight messages that you really want them to notice. I sometimes set mine up to look something like this:

Message of the day files can turn out to be message of the month files or message of the moment files, depending on how you want to use them. The content can be routine or very important. Getting users to notice included content will depend on getting their attention and educating them about what to expect.

Sandra Henry-Stocker has been administering Unix systems for more than 30 years. She describes herself as “USL” (Unix as a second language) but remembers enough English to write books and buy groceries. She lives in the mountains in Virginia where, when not working with or writing about Unix, she’s chasing the bears away from her bird feeders.