HowTo: Raspberry Pi – Set up your own welcome message

There are meanwhile many possibilities to give your RaspberryPi a personal touch. About self-designed and then 3D-printed housing to self-soldered expansion boards, there is almost nothing that is not possible.

Also on the software side, there are a lot of possibilities to set up the look and the functions according to your own discretion. One possibility is to set up a personal login screen – the first message you will see after logging in.

How to set up this “Message of the Day” (the actual name of the view at the beginning of the login screen) is explained in the following article.

Hints for our lovely english readers: Basically, many of the articles on Nerdiy.de are translations from the original german articles. Therefore, it may happen here and there that some illustrations are not available in english and that some translations are weird/strange/full of mistakes or generally totaly wrong. So if you find some obvious (or also not obvious) mistakes don't hesitate to leave us a hint about that in the comment section. 
Also please don't get confused, that instead of a "dot" often a "comma" is used as decimal separator. 🙂


Safety instructions

I know the following hints are always a bit annoying and seem unnecessary. But unfortunately, many people who knew it "better" from carelessness lost their eyes, fingers or other things or hurt themselves. In comparison, a loss of data is almost not worth mentioning, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Even the coolest project is worth no injury or other annoyance. https://www.nerdiy.de/en/sicherheitshinweise/

Affiliate links / advertising links

The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and shop via this link, Nerdiy.de receives a commission from the online shop or provider concerned. The price doesn't change for you. If you do your purchases via these links, you will support Nerdiy.de in being able to offer further useful projects in the future. 🙂


Requirements

Helpful Articles:
Of course you should be prepared for the “Message of the Day” of your RaspberryPi so that you can access it via SSH.

The following three articles describe what to do to prepare the RaspberryPi so far:
RaspberryPi – Setting up for Nerdiys!
RaspberryPi – The first configuration
RaspberryPi – Controlling the RaspberryPi via SSH

Required Tools:
-none-

Required material:

In the following list you will find all the parts you need to implement this article.


Log in via SSH on the RaspberryPi

To get started, you first need to log in to RasPi with SSH on Putty. How to do it is described in the article

After entering your username and password you can start to enter the first commands.

Create “Message of the Day” file

First you have to create the message you want to display. To do this create a directory – in which later the file is created – with the following command:

sudo mkdir ~/motd

… and then create the file to be displayed:

sudo nano ~/motd/mymotd

In this file you can insert the welcome message you want to display.
Of course you can also use the example below.

#!/bin/bash

PROCCOUNT=`ps -l | wc -l` 
PROCCOUNT=`expr $PROCCOUNT - 4` 

if [[ $(groups) == *irc* ]]; then 
ENDPROC=`cat /etc/security/limits.conf | grep "@irc" | grep nproc | awk {'print $4'}` ENDSESSION=`cat /etc/security/limits.conf | grep "@irc" | grep maxlogins | awk {'print $4'}` PRIVLAGED="IRC Account" 
else
ENDPROC=`cat /etc/security/limits.conf | grep "*" | grep nproc | awk {'print $4'}` ENDSESSION="Unlimited" PRIVLAGED="Regular User"
fi 

echo -e "\033[1;32m 
 __          __  _                          
 \ \        / / | |                         
  \ \  /\  / /__| | ___ ___  _ __ ___   ___ 
   \ \/  \/ / _ \ |/ __/ _ \|  _   _ \ / _ \\
    \\\  /\  /  __/ | (_| (_) | | | | | |  __/
     \/  \/ \___|_|\___\___/|_| |_| |_|\___|
     
\033[0;37m +++++++++++++++++: System Data :+++++++++++++++++++ 
+ Hostname: `hostname` 
+ IP-Address: `hostname -I` 
+ Kernel: `uname -r` 
+ Free Space: `df -h / | awk -v col=4 'NR > 1 {sub( "%", "", $col); print $col }'` 
+ Memory: `cat /proc/meminfo | grep MemTotal | awk {'print $2'}` kB 
+ Uptime:`uptime | sed 's/.*up ([^,]*), .*/1/'` 
++++++++++++++++++: User Data :++++++++++++++++++++ 
+ Username: `whoami` + Privlages = $PRIVLAGED 
+ Last login: `lastlog | grep pi | awk {'print $4,$5$6,$7,$8,$9'}`
+ Sessions: `who | grep $USER | wc -l` of $ENDSESSION MAX 
+ Processes: $PROCCOUNT of $ENDPROC MAX 
+++++++++++++++++++++++++++++++++++++++++++++++++++
"
Save this file with “CTRL + X” and “Y” …
… and “Enter”.

Now you have to make the file executable. This is done with the following command:

sudo chmod +x ~/motd/mymotd

Disable static “Message of the Day”

In order for your newly defined welcome message to be displayed, you must disable the old message – which is set as “factory-standard” for each RaspberrPi. To do this, open the file:

sudo nano /etc/ssh/sshd_config

In the opened file, you then navigate to the line that begins with “PrintMod …”.
This line must then be changed to “PrintMod no”. If this was already set: So much the better. 🙂

Edit PAM configuration

Now you have to edit your PAM configuration. Open the file:

sudo nano /etc/pam.d/login

Now you navigate with the arrow keys to the two lines:
"session    optional   pam_motd.so noupdate” 
“session    optional   pam_motd.so  motd=/run/motd.dynamic“
… and comment them out by putting a “#” sign in front of it.
This should look like this.
Save the changed file with “CTRL + X” and “Y” …
… and confirm this with “Enter”.

Edit profile

In the last step you have to specify that your new welcome message should be displayed at the start.

Open the file:

sudo nano /etc/profile

Navigate with the arrow keys until …
… to the end of the file.
Inserts “/home/pi/motd/mymotd” at the end of the file.
/home/pi/motd/mymotd
Save the changed file with “CTRL + X” and “Y” …
… and “Enter”.

Restart

So that this new file is now taken over – and to test the whole thing – you can perform a reboot with

sudo reboot

The output does not work: / – What to do?

If you receive an error message after startup instead of the welcome message, it is most likely due to a jumbled formatting of the myotd file.

For example, one (or more) error message (s) might look like this.

The problem with formatting of the file is that your RaspberryPi may interpret the written text differently than it is presented to you.

To fix this you have to open the file again:

sudo nano ~/motd/mymotd

Now you have to edit the file so that it looks the same as in the photo below.

To be able to test your modified file then – without having to restart each time, you can also enter the following command (if you are in the folder motd):

./myotd

If you have edited the file correctly, it should now look like this.

With the above example-“Message of the Day” you will also be shown a few current system data. Immediately after logging in, you will be able to see how the resource usage on your RaspberryPi looks and react if necessary.


I hope everything worked as described. If not or you have any other questions or suggestions, please let me know in the comments. Also, ideas for new projects are always welcome. 🙂

Fab

P.S. Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you appreciate it that I share these information with you, I would be happy about a small donation to the coffee box. 🙂

Buy Me a Coffee at ko-fi.com

Leave a Reply

Your email address will not be published. Required fields are marked *