/raspi-ssh-banner

A custom SSH banner script for my Raspberry Pi

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

raspi-ssh-banner

A custom SSH banner script for my Raspberry Pi

I wanted a custom SSH banner for my Raspberry Pi, one that would tell me a bit about its current status, and statistics and service status of the Raspberry Pi, such as OpenVPN, Discord bots, local IPs, and system load. After a bit of research on MotD scripts and ANSI color codes and such, I put together this script one afternoon in my free time.

Setup/Installation

First of all, anyone looking to replicate this script for themselves should note that this script would need to be heavily modified for use for anyone other than...me. You'll just have to dig into the source code to mess with it and adapt it for your own use - it's not exactly a ton of code, but it's not commented and I don't exactly have the best code practices.

Anyway, to get the script working, you'll need a Python 3.6+ installation on your Raspberry Pi. Unfortunately, AFAIK this will have to be compiled from scratch, but anyone who's had a bit of Linux experience will be fine (download/unzip source, ./configure, make, sudo make altinstall).

After installing Python, you'll need to purge the existing MotD, if you'd like. Google a bit and you should find all of the files you need to change, or you can set PrintMotd to no in /etc/ssh/sshd_config. Optionally you can remove the Last Login from there as well but it might be a good idea to keep it as a security measure.

Finally you can move the script to some location you'd like. I was not able to get the script to run in the dynamic MotD feature of sshd, so I simply added python3.7 generate-motd.py to my ~/.bashrc instead.

ANSI Color Code Notes

The script uses 24-bit ANSI color codes in order to get the colors to display. These color codes can be changed in the variables at the top of the script if desired. However, note that some terminals may not support 24-bit color codes, or may simply print the codes, or something else. Some potential issues:

  • screen does not support 24 bit color. It appears to convert it to grayscale instead. Supposedly screen can be compiled from scratch to support 256 color but I'm not sure if 24 bit color can be supported at all in screen.
  • PuTTY by default does not support 24 bit color, but it does 256 color. However, some features like the WiFi dBm scale output 24 bit colors and would take much more work to output in 256 colors instead. This repo has a patched version of PuTTY that supports 24bit color and that's what I use on Windows.
  • The Windows terminal (at least on my version of Windows) does not support any of the colors at all (using ssh from Git for Windows). Just use the patched PuTTY instead (I have it pinned to my taskbar).