If you are using xterm, this works great: https://github.com/fboender/sshbg
How does it work?
Black unix magic. Well, not really. Well, kinda...
SSH lets you run a local command before the connection to the remote
host is established. Some terminals allow you to set the background
color with an escape sequence. It's possible to detect if the SSH
command has exited from the locally executed command by polling the
parent process PID in the background. Combine the three and presto!
Background colors.
sshbg matches (regex) entries in a configuration file against the
provided hostname. That results in a profile name, which has a
background color associated with it. See the "Config file" section at
the bottom of this page for more info.
Installation and usage
Requirements:
- Python v3.x+
- A supported terminal
Clone this repo:
git clone git@github.com:fboender/sshbg.git
cd sshbg
Copy the sshbg script to some dir in your PATH, for example:
sudo cp sshbg /usr/local/bin/
Copy the sshbg.conf file to ~/.config/sshbg.conf:
cp sshbg.conf ~/.config/
Enable the LocalCommand configuration setting in your SSH config.
You can do this on a host-by-host basis, or with wildcards. To enable
it for all hosts, make your SSH config look like this:
$ cat ~/.ssh/config
PermitLocalCommand yes
Host *
LocalCommand sshbg "%n"