Skip to content

Instantly share code, notes, and snippets.

@Mohammad-Reihani
Created August 12, 2025 23:06
Show Gist options
  • Save Mohammad-Reihani/c0cf0494a830292c34f341e0f0618434 to your computer and use it in GitHub Desktop.
Save Mohammad-Reihani/c0cf0494a830292c34f341e0f0618434 to your computer and use it in GitHub Desktop.
Better Login MOTD with picture

Pictured MOTD

Want your server to greet you with a nice picture (ASCII/ANSI art) when you SSH in? This guide shows how to generate different-width ASCII art pieces and automatically show the best-fitting one on login.


Prerequisites

  • A terminal that supports ANSI escape sequences (most modern terminals do).
  • SSH access to the server.
  • A place on the server to store the ASCII art, e.g. /usr/share/ascii-art.

Overview

  1. Convert your image(s) to ASCII/ANSI text at several widths (90, 120, 200, … up to 500).
  2. Put each width version into a folder named after that width.
  3. Install a small login script that detects the client width and prints the most appropriate file.

1 — Generate ASCII art

Use a generator that can output plain text with ANSI color codes, not PNG. Example: https://www.asciiart.eu/image-to-ascii (or similar). Create multiple versions of the same image at different widths (recommended widths: 90, 120, 160, 200, 300, 400, 500). Save each version as a plain .txt file (ANSI color enabled if you want colored output).

Tips

  • Test output in a terminal window sized to that width before saving.
  • If your generator produces PNG only, look for the ANSI/text output option or try another generator.

2 — Put art on the server (example global path)

Create a shared directory for everyone to use:

sudo mkdir -p /usr/share/ascii-art
sudo chown root:root /usr/share/ascii-art
sudo chmod 755 /usr/share/ascii-art

Create width folders and copy art in:

# from your local machine or server, example:
sudo mkdir -p /usr/share/ascii-art/{90,120,160,200,300,400,500}
sudo cp art-90.txt /usr/share/ascii-art/90/
sudo cp art-120.txt /usr/share/ascii-art/120/
# repeat for other widths

If you want per-user art, put the same folder structure under a user home (e.g. ~/ascii-art), but the global path is cleaner for multi-user servers.


3 — Login script (works for /etc/profile or ~/.bashrc)

This prints a random file from the best matching width folder when a user logs in over SSH. It includes a safe fallback (choose the largest width ≤ client width; if none, choose the smallest available).

Paste this into /etc/profile for all users, or ~/.bashrc for only one user. Adjust ART_DIR if you used a different path.

# Pictured MOTD - put in /etc/profile or in ~/.bashrc
ART_DIR="/usr/share/ascii-art"

# Only show for interactive SSH sessions
if [ -n "$SSH_TTY" ] && [ -d "$ART_DIR" ]; then
    cols=$(tput cols 2>/dev/null || echo 80)

    # Get sorted list of available widths (numbers only)
    widths=( $(ls "$ART_DIR" 2>/dev/null | sort -n) )

    # find best width: largest width <= cols
    best=""
    for w in "${widths[@]}"; do
        # ensure it's a number
        if [[ "$w" =~ ^[0-9]+$ ]]; then
            if [ "$w" -le "$cols" ]; then
                best="$w"
            fi
        fi
    done

    # If nothing is <= cols, pick the smallest available width as fallback
    if [ -z "$best" ] && [ ${#widths[@]} -gt 0 ]; then
        best="${widths[0]}"
    fi

    if [ -n "$best" ] && [ -d "$ART_DIR/$best" ]; then
        art_file=$(find "$ART_DIR/$best" -maxdepth 1 -type f | shuf -n 1)
        if [ -f "$art_file" ]; then
            cat "$art_file"
        fi
    fi
fi

4 — Quick helper commands

Create many width folders quickly:

sudo mkdir -p /usr/share/ascii-art/{90,120,160,200,300,400,500}

Check your current terminal width (locally or via SSH):

tput cols
# or remotely
ssh user@host 'tput cols'

Test printing a specific art file:

cat /usr/share/ascii-art/200/art1.txt

5 — Permissions & security

  • /usr/share/ascii-art should be readable by all users (e.g. chmod -R 755).
  • Avoid putting files with sensitive content there.
  • If you want only certain users to see art, store per-user copies under their home directories instead.

6 — Nice extras (optional)

  • Use ANSI colored art for prettier output (ensure the generator produces ANSI).

  • Animate printing with pv -qL 800 to “type” the image, e.g.:

    pv -qL 800 "$art_file"
  • Use lolcat to rainbow-color text (if installed), but be careful—it may break ANSI color art.


Troubleshooting

  • Art wraps or breaks: The art width is wider than the client columns. Generate a version closer to the client width or resize the client terminal.
  • No art shows: Verify ART_DIR exists and contains numeric-named subfolders. Check /etc/profile permissions and whether your login shell reads /etc/profile for your session.
  • Colors not showing: Your terminal might not support ANSI, or the file is lacking ANSI escape sequences. Test with a known ANSI sample.

Example workflow (summary)

  1. Generate art at widths you care about (90, 120, 160, 200, …). Save as .txt.
  2. Upload them to /usr/share/ascii-art/<width>/.
  3. Add the login script to /etc/profile (or ~/.bashrc).
  4. SSH in and enjoy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment