Customize your SSH connection with motd message

Today an article of customization at your SSH connection. Un peu d’esthétique ne fera pas de mal 🙂

motd-2

When you connect to the Raspberry in SSH either by opening a terminal under X you have the ability to display a particular message whose content lies in the file /etc/motd.

We will modify this message to get the message of the image above.

  1. Create a script (Home /root/update_motd.sh) with the content of This file (the file has a .doc extension but it is .txt because wordpress.com hosting).

    The script will write to the/etc/motd file. However you may have to add spaces at the beginning of line to align everything.
    Personnaliser votre message de connexion SSH avec motd

    Customize your SSH connection with motd message - Screenshot because that do not pass on this blog …

  2. Set up a regular updating of the file/etc/motd via a job in crontab. Start the command crontab-e and copy the following line at the end of file :
    */10 * * * * /root/update_motd.sh

    The script will run all the 10 minutes

Et voilà 🙂

Sources :

You may also like...

  • waraxe

    For my part, I already knew and mine is very similar with the same raspberry in ASCII art.

    Before I did not know where to put my welcome message. Initially I put it in the /etc/init.d/motd file but it is running the Raspberry boot or manually, displayed data were never updated.

    Now I put it in the/etc/profile so at each opening of shell Bash it generates me the information. I have personally not too calculations to do but depending on the complexity of the script, my method can lose a few tenths of seconds at the start of the shell especially for a low-power as the RPi machine.

    With yours, the data are generated in advance and therefore are just to be displayed. But they are generated even when no one is using the machine.

    Even if the “prejudice” is very minimal, It is a matter of choice.

    • s akifrajput

      Hello waraxe, It line have you added to etc / profile for the execution of the script ?

      Thank you

  • starcleff

    Chez moi ça marche pas 🙁

    It not like the personnnalisation of the colours of the shot makes me it:

    ————————-

    Linux raspberrypi 3.6.11+ #371 PREEMPT Tue Feb 7 16:31:35 GMT 2013 armv6l

    33[0;32m

    .~~. .~~. 33[0;37mMonday, 29 April 2013, 18:0533[0;32m

    ‘. ‘ ‘ / .’ 33[0;37mLinux 3.6.11+ armv6l GNU/Linux33[0;31m

    .~ .~~~..~. 33[0;37M33[0;31m

    : .~.’~’.~. : 33[0;37mUptime………….: [0;31m

    ~ ( ) ( ) ~ 33[0;37Memory………….: 124MB (Free) / 438MB (Total)33[0;31m

    ( : ‘~’.~.’~’ : ) 33[0;37Processes mRunning..: 11633[0;31m

    ~ .~ ( ) ~. ~ 33[0;37M33[0;31m

    ( : ‘~’ : ) 33[0;37PSA Addresses…….: 192.168.1.39 / 79.159.70.6533[0;31m

    ‘~ .~~~. ~’ 33[0;37mTemperature……..: 46.5' C33[0;31m

    ‘~’ 33[0;37m

    33[0;32m

    .~~. .~~. 33[0;37mMonday, 29 April 2013, 18:0533[0;32m

    ‘. ‘ ‘ / .’ 33[0;37mLinux 3.6.11+ armv6l GNU/Linux33[0;31m

    .~ .~~~..~. 33[0;37M33[0;31m

    : .~.’~’.~. : 33[0;37mUptime………….: [0;31m

    ~ ( ) ( ) ~ 33[0;37Memory………….: 124MB (Free) / 438MB (Total)33[0;31m

    ( : ‘~’.~.’~’ : ) 33[0;37Processes mRunning..: 11633[0;31m

    ~ .~ ( ) ~. ~ 33[0;37M33[0;31m

    ( : ‘~’ : ) 33[0;37PSA Addresses…….: 192.168.1.39 / 79.159.70.6533[0;31m

    ‘~ .~~~. ~’ 33[0;37mTemperature……..: 46.5' C33[0;31m

    ‘~’ 33[0;37m

    —————————

    (and not I not put it 2 times)

    If qqun has an idea :p

  • waraxe

    It looks like missing characters “” before each color code.

    For example instead of “33[0;37m” It should be “33[0;37m”.

    So the code is a little more readable small, It is better to establish the colors in variables at the start and then call the variables by name.

    For the Green it would :

    GREEN =.”33[0;32m”

    And we call the Green variable with “$GREEN”.

    In the passage, a small link to understand the color codes : http://wiki.mandriva.com/fr/Utilisateur:Yves_Bourguet/ANSI

  • waraxe

    Ah thin. Chris looks that your blog does not like the backslash characters. Each time the character following a backslash is escaped (it disappears).

    So in my previous comment I said that missing characters “[backslash][zero]” (a backslash followed by a zero) at the beginning of each color code.

  • starcleff

    Okey, thanks I'll try that.

  • I updated the article following remarks on colours and characters. Everything is in a file as an attachment.

  • starcleff

    I have reessaye with the attached file it still doesnt it puts:

    ———————-

    Linux raspberrypi 3.6.11+ #371 PREEMPT Tue Feb 7 16:31:35 GMT 2013 armv6l

    33[0;32m

    .~~. .~~. 33[0;37mTuesday, 30 April 2013, 18:3333[0;32m

    ‘. ‘ ‘ / .’ 33[0;37mLinux 3.6.11+ armv6l GNU/Linux33[0;31m

    .~ .~~~..~. 33[0;37M33[0;31m

    : .~.’~’.~. : 33[0;37mUptime………….: 0 days, 00h 12 m 11 s 33[0;31m

    ~ ( ) ( ) ~ 33[0;37Memory………….: 161MB (Free) / 438MB (Total)33[0;31m

    ( : ‘~’.~.’~’ : ) 33[0;37Processes mRunning..: 9833[0;31m

    ~ .~ ( ) ~. ~ 33[0;37M33[0;31m

    ( : ‘~’ : ) 33[0;37PSA Addresses…….: 192.168.1.39 / 79.159.70.6533[0;31m

    ‘~ .~~~. ~’ 33[0;37mTemperature……..: 45.5' C33[0;31m

    ‘~’ 33[0;37m

    33[0;32m

    .~~. .~~. 33[0;37mTuesday, 30 April 2013, 18:3333[0;32m

    ‘. ‘ ‘ / .’ 33[0;37mLinux 3.6.11+ armv6l GNU/Linux33[0;31m

    .~ .~~~..~. 33[0;37M33[0;31m

    : .~.’~’.~. : 33[0;37mUptime………….: 0 days, 00h 12 m 11 s 33[0;31m

    ~ ( ) ( ) ~ 33[0;37Memory………….: 161MB (Free) / 438MB (Total)33[0;31m

    ( : ‘~’.~.’~’ : ) 33[0;37Processes mRunning..: 9833[0;31m

    ~ .~ ( ) ~. ~ 33[0;37M33[0;31m

    ( : ‘~’ : ) 33[0;37PSA Addresses…….: 192.168.1.39 / 79.159.70.6533[0;31m

    ‘~ .~~~. ~’ 33[0;37mTemperature……..: 45.5' C33[0;31m

    ‘~’ 33[0;37m

    ————————-

    (before each 33 I well put [backslash][zero]

    • There is only one line in the crontab ?

      • starcleff

        I have not yet launched the crontab I test to see if it works and after I program Autorun.

        • The duplicate content is the script that generates it ? What is launched alone without redirection in/etc/motd it works ?

  • Raph

    Or otherwise we create a file/etc/ssh/sshrc (If it does not already exist) or ~/.ssh/rc and put in for example: sh /home/pi/.update_motd.sh (or directly the script)

    man sshd:

    […]

    LOGIN PROCESS

    8. If ~/.ssh/rc exists, runs it; ElseIf/etc/ssh/sshrc exists,

    runs it; otherwise runs xauth. The “RC” files are given the

    X 11 authentication protocol and cookie in standard input. See

    SSHRC, below.

    […]

    Allowing to update before the client connects rather than every 10 min.

    • Actually, seems much more effective ! 🙂
      Thanks for sharing these details

    • Bencici

      I have the right to it me :S :

      “Last login: Wed May 1 19:57:04 2013 from 192.168.0.11

      Use: grep [OPTION]… PATTERN [FILE]…

      Try ' grep -help’ For more information.

      /etc/ssh/sshrc: 2: /etc/ssh/sshrc: MemFree: not found

      /etc/ssh/sshrc: 4: /etc/ssh/sshrc: arithmetic expression: expecting primary: “/1024” “

      • Hello,
        What distribution used you ? What happens if you do a cat/etc/motd ?
        For each command it is possible need to put the full path (/usr/bin/grep instead of grep for example)

        • Last Raspbian dated.

          I have the right to the MOTD.

          I just turned, I'll try the original method.

        • I finally used this method http://www.raspberrypi.org/phpBB3/viewtopic.php?t=23440 with the MOTD + small mods home http://pastebin.com/yJwQL6WK

          For the weather, just change the city at the end of the address.

  • waraxe

    Yes it's a bit what I said in my first comment.

    But I'd rather put it in/etc/profile, because in the sshrc this concerns only ssh connections (in any case if it is someone who uses the Pi directly without going through ssh).

    • Raph

      HA yeah right I was not watching the coms.

  • Polo0000

    Good and well I have a problem, I tried everything that is important or I set the commands to execute : ~/.ssh/RC ; /etc/ssh/sshrc ; /etc / profile ; ~/.bash_profile

    The message is updated well but after that I am connected, so when I connect I have the message of my previous connection. If I connect only once a day I get the message of the day before each time, not terrible…

    An idea?

    • I wonder if MOTD is not executed before these files (profile and .bash_profile) It is certain. So it's normal the message then that then it puts the updated.
      You don't want to tried by the crontab ?

      • Polo0000

        Yes I runs like that waiting to find another alternative. I like when it works as I want!

        • Viewing This link you have the complete sequence of execution during the boot. You see that motd is displayed before the file's profile

  • Polo0000

    ER… your link does not work!

  • torriep

    Hello,

    Thank you for the tutorial !

    But I have no color : whether it's on the side of putty or SSH on Android client :/

    An idea, Please ? Thank you. See you again. Good continuation.

  • torriep

    Hello,

    Always one to help me ? 🙁

Handpicked links

disk Page Caching using disk: enhanced Database Caching 347/648 queries in 0.215 seconds using disk Served from: pihomeserver.fr @ 2017-08-18 08:22:02 by W3 Total Cache -->