📟 Creating fancy ASCII login messages for Linux

Filed under:

Shell afficionados like myself will love when they open a shell that is visually appealing. We know .bash_prompt, Oh My ZSH and other visual tweaking, but did you know you can very easily spice up the boring default SSH login?

With the help from the npm cfonts package we can create colorised ASCII logos and show them on login.

As you may (or may not) know from my previous Linux, Bash, SSH or Raspberry Pi related posts, I always name my server's hostname to a well-known electronic music club somewhere in the world. For once I am setting up a server for someone else and naming it something else. Let's create the same nice login message, also called MOTD (message of the day)

Prerequisites

You will need to install cfonts or call it directly via npx. I prefer installing it globally as a CLI tool so I can reuse it at later times:

$ npm i -g cfonts

# Without installing
$ npx cfonts "HOSTNAME" [...args]

cfonts cli example

For exact CLI options, refer to the usage guidelines on cfont's npm page.

Creating ASCII text

The first argument to cfonts will be the text you want to style, with the rest options being the style properties provided as flags. I try to keep hostnames short since otherwise it will overflow to the next line in smaller terminals and just clutter up your view.

The nice thing is that cfonts automatically wraps named colors and rgb values as ASCII color sequences. We can created a gradient style like this:

$ cfonts "HOSTNAME" -f simple3d --gradient blue,magenta,cyan --transition-gradient

Screenshot 2020-02-15 at 17.39.55

Adding it to our server

To add it to your server we need to overwrite the file at Linux's /etc/motd path. The easiest way to get the file on your server is to redirect stdout from cfonts to a file on your host machine and scp that to your server:

# Write it to a file
$ cfonts "BATI_RPI" -f simple3d --gradient blue,magenta,cyan --transition-gradient > motd

# Copy that file to the server
$ scp motd pi@bati-rpi.local:/home/pi

# Login to the server and move it to the /etc dir
$ ssh pi@bati-rpi.local
$ sudo mv /home/pi/motd /etc/motd

Now, when you log in, you're greeted with your friendly colorised login message! Colors might differ from host to host though I have noticed.

Screenshot 2020-02-15 at 17.41.01