Colorful ssh banner

35,778

Solution 1

You might want to have a look at toilet. The following has been incorporated in the banner of one of the servers at my lab:

enter image description here

You can install it on Debian based systems with

sudo apt-get install toilet

TOIlet prints text using large characters made of smaller characters. It is similar in many ways to FIGlet with additional features such as Unicode handling, colour fonts, filters and various export formats.

toilet works perfectly well with ASCII art:

enter image description here


I have written a little Perl script to highlight specific regexes in text. If you use . as the regex, it will color everything a specific color:

enter image description here

The script (use -h for a tiny help message):

#!/usr/bin/env perl
use Getopt::Std;
use strict;
use Term::ANSIColor; 

my %opts;
getopts('hic:l:',\%opts);
    if ($opts{h}){
    print "Use -l to specify the letter(s) to highlight. To specify more than one patern use commas.\n -i makes the search case sensitive\n -c: comma separated list of colors\n";
    exit;
    }
my $case_sensitive=$opts{i}||undef;
my @color=("bold blue",'bold red', 'bold yellow', 'bold green', 'bold magenta', 'bold cyan', 'yellow on_magenta', 'bright_white on_red', 'bright_yellow on_red', 'white on_black');
if ($opts{c}) {
   @color=split(/,/,$opts{c});
}
my @patterns;
if($opts{l}){
     @patterns=split(/,/,$opts{l});
}
else{
    $patterns[0]='\*';
}
# Setting $| to non-zero forces a flush right away and after 
# every write or print on the currently selected output channel. 
$|=1;

while (my $line=<>) 
{ 
    for (my $c=0; $c<=$#patterns; $c++){
      if($case_sensitive){
        if($line=~/$patterns[$c]/){
        $line=~s/($patterns[$c])/color("$color[$c]").$1.color("reset")/ge; 
        }
      }
      else{
        if($line=~/$patterns[$c]/i){
          $line=~s/($patterns[$c])/color("$color[$c]").$1.color("reset")/ige; 
        }
      }
    }
    print STDOUT $line;
}

Solution 2

Based on my research in this other U&L Q&A titled: Non-ASCII printable characters in sshd banner it is not possible to get SSH's banner facility to print the escape sequences necessary to colorize the output. This is in fact by design for security reasons.

Therefore it's impossible to print an SSH banner in this manner.

Share:
35,778
Patryk
Author by

Patryk

Software Engineer C++/Go/shell/python coder Linux enthusiast Github profiles: https://github.com/pmalek https://github.com/pmalekn

Updated on September 18, 2022

Comments

  • Patryk
    Patryk over 1 year

    I would like to colorize my ssh banner. I know I can perform it like so:

    In /etc/profile I can put:

    echo -e "\e[1;31m Colorful text"
    echo -e "\e[0m Reset"
    

    But I have some ASCII art in the banner with special characters. Is there any way to colorize this without escaping every single special char in the ASCII art?

  • hildred
    hildred almost 9 years
    This is how to generate a banner, not how to display it through an ascii only filter.
  • terdon
    terdon almost 9 years
    @slm I won't have enough access to my machine for the next few days so I can't check. Are you saying that putting the output of toilet in etc/motd won't work?
  • slm
    slm almost 9 years
    @terdon - No it works for motd. hildred brought up that our A'ers won't work with SSH's banner function, given my answer to the this Q: unix.stackexchange.com/questions/109038/…. Escape codes are disallowed in SSH's banner. So I made a Q to cover coloring MOTD's and moved my A'er over there. I figured you'd want to do the same w/ yours.
  • est
    est about 7 years
    /etc/issue.net does not support ANSI color, however, /etc/motd does. Tested on Ubuntu 14.04 LTS and CentOS 6.X