Linux MOTD

From csn
Revision as of 06:44, 9 June 2020 by David (talk | contribs) (Created page with "I like to make my message of the day as useful as possible. When I login via ssh I want it to be really clear as to which machine I am using and the specifications of that mac...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

I like to make my message of the day as useful as possible. When I login via ssh I want it to be really clear as to which machine I am using and the specifications of that machine. The way that you do this varies between different distributions. Below are some examples of Ubuntu and Rasbian.

There are a couple of packages that I like. You can install them with:

sudo apt install figlet neofetch

Ubuntu

In Ubuntu you can edit the message of the day with:

nano /etc/update-motd.d/00-header

At the bottom of this file I usually insert the following lines:

figlet -f small Welcome to [Insert_server_name_here]
neofetch

I usually then explore the other parts that are added by subsequent files in /etc/update-motd.d/ if I don' find the other information useful then I just delete.

As an example, on my amazon EC2 machine I did:

sudo rm /etc/update-motd.d/10-help-text 
sudo rm /etc/update-motd.d/50-landscape-sysinfo
sudo rm /etc/update-motd.d/50-motd-news  
sudo rm /etc/update-motd.d/51-cloudguest 
sudo rm /etc/update-motd.d/80-esm 
sudo rm /etc/update-motd.d/80-livepatch

Raspbian

Raspbian does not feature a dynamic message of the day. It will simply read and print whatever the contents of /etc/motd. This means that you will need to use cron to periodically insert the data into the motd. Make sure you have installed the packages above.

Then you want to create a script

nano /bin/motd-script
#!/bin/bash

figlet -f small Welcome to Raspbian
neofetch

Provide execute permissions

chmod 755 /bin/motd-script

Then edit crontab

 sudo vim /etc/crontab

I then inserted the following line to use the script to update the motd

24 *    * * *   root    /bin/motd-script > /etc/motd

Other

Sometimes I like running:

/usr/games/cowsay -f /usr/share/cowsay/cows/default.cow Hello, $(w -h | awk '{print $1"@"$3}') I am $HOSTNAME