Keep logged in users informed with motd

Jack Wallen
Apr 6, 2009
Updated • Nov 28, 2012

If you have users that log into a server, or a desktop (for whatever reason) you might want to take advantage of the Linux Message Of The Day file. This file resides in the /etc directory and, when a user logs in, the contents of that file are displayed every time a user logs into that machine. Of course there is a bit of a trick involved. If you write your own nice /etc/motd file every time you reboot that machine part of the /etc/motd file contents will be replaced by new information. Easily we can make the portion of the file that is not rewritten suite our needs. And with a little trickery we can fine tune the entire motd to our satisfaction.

In reality the message you see upon login is a combination of two files: /etc/motd and /etc/motd.tail. The former file is the file that is regenerated upon boot. The latter file contains static information. The first thing we will do is change the /etc/motd file so that, upon loggin in, the users can get system (or company) specific information. Once that is done we'll trick /etc/motd.tail into getting content different than that from /etc/init.d/


The first thing you should is open up your /etc/motd.tail file in your favorite text editor. When I open up that file in Ubuntu Server 8.10 the contents look like:

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To access official Ubuntu documentation, please visit:

I want to change that content so I know exactly which server I am on when I log in. So let's say I want to change that to say:

welcome to the Ubuntu Server. have a good time and do not break anything.

Now when I log into my Ubuntu Server I will see the following motd:

welcome to the Ubuntu Server. have a good time and do not break anything.

System information as of Mon Apr 6 15:00:01 EDT 2009

System load: 0.0 Swap usage: 0% Users logged in: 1
Usage of /: 18.5% of 13.46GBTemperature: 52 C
Memory usage: 43% Processes: 104

Graph this data and manage this system at
Last login: Mon Apr 6 15:06:41 2009 from

As you can see there is some useful information to be had with this. But you may not want all of your users to see this information. Say you want to first let the users know which server they are on. We've already covered that with /etc/motd.tail. But let's say you also want to send out a message to all users who log onto the server. You can change /etc/motd to reflect that message but when you reboot the machine that message will be replaced. So to get around that we can create a shell script that will over write the information written at bootup. A possible (and overly simple) shell script could look like this:

rm /etc/motd
touch /etc/motd
echo "this is my message" > /etc/motd

Save that file in, say /opt (for example sake we'll call it /opt/motd_append) and make it executable with the command chmod u+x /opt/motd_append. Now to make sure this command runs we can create an entry at the end of /etc/rc.local like this:


Now when /etc/rc.local runs the script will run and over write the information in /etc/motd. Now when your users log in they will see your special message every time.


Previous Post: «
Next Post: «


There are no comments on this post yet, be the first one to share your thoughts!

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.