HowTo: Raspberry Pi – Set up your own welcome message

There are now all kinds of options to give your RaspberryPi a personal touch. From self-designed and then 3D printed housings to self-soldered expansion boards, there is actually almost nothing that is not possible.

On the software side, too, there are all sorts of options to customize the appearance and functions as you see fit. One option is to set up a personal login screen - i.e. the first message you see after logging in.

Wie Ihr diese „Message of the Day“ (so der eigentliche Name der Ansicht zu beginn des Loginscreens) einrichtet, ist im folgenden Artikel erklärt.


Safety instructions

I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/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 make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂 


Requirements

Helpful articles:
Damit Ihr die „Message of the Day“ eures RaspberryPi’s bearbeiten könnt sollte dieser natürlich soweit vorbereitet sein, dass Ihr per SSH auf diesen zugreifen könnt.

The following three articles describe what needs to be done to prepare the RaspberryPi:
RaspberryPi – setup for nerdiys!
RaspberryPi – The first configuration!
RaspberryPi – Control the RaspberryPi via SSH

Required tool:
-no-

Required material:

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


Log in to the RaspberryPi via SSH

To start, you must first log in to the Rasp Pi with Putty via SSH. How to do this is in the article RaspberryPi - Control the RaspberryPi via SSH described.

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

„Message of the Day“-Datei anlegen

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

sudo mkdir ~/motd

...and then creates the file to be displayed:

sudo nano ~/motd/mymotd

There you now insert the welcome message that you want to display.
You are welcome to 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 "33[1;32m __ __ _ / / | | / / /__| | ___ ___ _ __ ___ ___ / / / _ |/ __/ _ | _ _ / _ \ \ / / __/ | (_| (_) | | | | | | __/ / / \___|_|\___\___/|_| | _| |_|\___| 33[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 +++++++++++++++++++++++++++++++++++ ++++++++++++++++++ "
Speichert diese Datei dann mit „STRG+X“ und „Y“…
…und „Enter“.

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

sudo chmod +x ~/motd/mymotd

Statische „Message of the Day“ deaktivieren

Damit Eure eben festgelegte Begrüßungs-nachricht angezeigt wird, müsst Ihr die alte Nachricht – die bei jedem RaspberrPi „ab Werk“ eingerichtet ist – deaktivieren. Dazu öffnet Ihr die Datei:

sudo nano /etc/ssh/sshd_config

In der geöffneten Datei navigiert Ihr dann bis zu der Zeile die mit „PrintMod …“ beginnt.
Diese Zeile muss dann in „PrintMod no“ geändert werden. Wenn dies bereits so eingestellt war: Umso besser. 🙂

Edit PAM configuration

Now you have to edit your PAM configuration. To do this, open the file:

sudo nano /etc/pam.d/login

Now use the arrow keys to navigate to the two lines:
“session optional pam_motd.so noupdate” “session optional pam_motd.so motd=/run/motd.dynamic”
…und kommentiert diese aus, indem Ihr ein „#“-Zeichen davor setzt.
This should look like this.
Die geänderte Datei speichert Ihr mit „STRG+X“ und „Y“…
…und bestätigt dies mit „Enter“.

edit profile

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

To do this, open the file:

sudo nano /etc/profile

Then navigate using the arrow keys to...
...to the end of the file.
Fügt am Ende der Datei „/home/pi/motd/mymotd“ ein.
/home/pi/motd/mymotd
Die geänderte Datei speichert Ihr mit „STRG+X“ und „Y“…
…und „Enter“.

Perform a restart

In order for this new file to be adopted - and to test the whole thing - you can restart with

sudo reboot

The output doesn't work :/ – What to do?

If you get an error message after booting up instead of the welcome message, then this is most likely due to the formatting of the myotd file being mixed up.

This is what one (or more) error message(s) could look like, for example.

The problem with formatting is that your RaspberryPi may interpret what is written 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 exactly like the photo below.

In order to be able to test your changed file - without having to restart every time, you can also enter the following command (if you are in the motd folder):

./myotd

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

Mit der oben angegebenen Beispiel-„Message of the Day“ werden euch also auch ein paar aktuelle Systemdaten angezeigt. Ihr könnt so gleich nach dem Login erkennen wie die Auslastung der Ressourcen auf eurem RaspberryPi aussieht und ggf. reagieren.


Have fun with the project

I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂

PS 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 think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂

Buy Me a Coffee at ko-fi.com       

Kommentar hinterlassen

Your email address will not be published. Erforderliche Felder sind mit * markiert

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