How to use MOTD in Ubuntu 22.04 | 20.04 Linux or any version

Learn how to show a custom message upon login Ubuntu 22.04 / 20.04 server or desktop to users on the command terminal using the MOTD file.

MOTD is a simple text file in a Linux system that is used to display some custom text message on login using the command line locally or SSH. MOTD’s full form is “Message of the Day”.  The necessity of this simple MOTD is to display some alert, important information such as system maintenance, security updates, or any other relevant message to Linux users by the Admin.

Suppose you have a couple of Linux systems in your office and want to display important info to all users upon their login in such a case MOTD can be a quite useful tool.

The file used by the MOTD is generally located under the /etc directory of the Linux which can be edited manually to display custom messages. If you have scripting knowledge then can display dynamically generate messages.

Well, one thing that needs to be noted only users with system admin rights such as sudo, root, or any other authorized users can only update the contents of the MOTD file.

In this article, we learn how to edit and use the MOTD file on Ubuntu Linux to show custom messages.

Use MOTD in Ubuntu to show a custom message

The commands given here to use the MOTD are not just limited to Ubuntu 22.04 or 20.04 only, you can use them on Debian, Linux Mint, and other similar Linux operating systems.

Edit MOTD file on Ubuntu 22.04 | 20.04

Open your command terminal and use the given command. It will open the “Message of the Day” file available inside the /etc directory using the nano text editor. If you don’t have Nano then can install it using sudo apt install nano- y

On Ubuntu MOTD is located under: /etc/motd, so to edit it, use:

sudo nano /etc/motd

Add Custom Message to Display

The custom MOTD file on your Linux system by default will be blank. You can add any message that you want to show to users upon their login to the system.

Let’s say, we want to display:

####################################################
You are welcome to H2S Media, don't share your password with anyone...
####################################################

After typing the message we will save the file using the shortcut Ctrl+X, then confirm the same by typing Y, and exit press the Enter key.

Create a Cutstom message to display upon loign linux

Login Ubuntu system to show MOTD

As here we are using the GUI desktop system of Ubuntu, hence to see the MOTD custom message we just created, we need to log in using the command line.

So there are two ways to do that either switch to the command line interface on your current GUI Ubuntu or login using SSH using any other system. Here we will show you both the ways.

Show MOTD by switching to CLI mode:

We can switch to the Command interface from Ubuntu GNOME GUI by pressing Ctrl+ALT+F5.

After that, enter your login details and you will see the created Custom MOTD message.

MOTD Message on Ubuntu 22.04 or 20.04

Once you are confirmed your message is showing correctly get back to the graphical desktop of Ubuntu by pressing – Ctrl+Alt+F2

Get MOTD Display via SSH login

Now, if you have created the MOTD text file on some remote server then you can check the created message by login the system remotely using SSH.

For that, first, note down the remote server IP address using the given command on it:

ip a

After that open the command terminal on your local system which can be Windows, macOS, or Linux to log in to the remote server via SSH.

ssh username@ip-address 

For example, if our remote server address is 192.168.53.101 and the username is h2s then the command to access SSH will be:

ssh [email protected]
Display MOTD message using SSH Login

Disable System MOTD message on Ubuntu login

You have seen that when we log in to our Ubuntu server or desktop using the command terminal, it will also show other default text messages along with the MOTD messages.

But, if we only want the Ubuntu system to show our custom MOTD custom, not all the other text then we have to disable the system’s default MOTD files, here is the command to do that.

Note: It will simply remove the permission of the all system’s default MODT files from executing.

Disable System default MOTD files on Ubuntu:

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

After that, when you log in to your Ubuntu 22.04/20.04 system you will only get your custom message.

Disable default MOTD files in Ubuntu Linux

To enable again system default MOTD files:

In the future, if you want to display all the default system messages upon logging in again, then you can enable the MOTD using the given command.

sudo chmod o+rx /etc/update-motd.d/*

In this way, we can easily create and display the custom MOTD messages on Ubuntu 22.04 or 20.04 using our command terminal.

FAQ

What is the motd command in linux?

MOTD is a simple text file in a Linux system that is used to display some custom text message on login using the command line, locally or via SSH.

Where is Motd located in Linux?

The default location of MOTD file in Linux such as Ubuntu is: /etc/motd however, in other Linux, you could find it at- /run/motd, /usr/lib/motd, /etc/motd. d/ or /run/motd.

How to disable default MOTD in Ubuntu Linux?

If you don’t want to show any message upon Ubuntu login then disable all MOTD files using – sudo chmod -x /etc/update-motd.d/*

Other Articles:

1 thought on “How to use MOTD in Ubuntu 22.04 | 20.04 Linux or any version”

Leave a Comment

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