Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm frequently logging into different servers from my os x terminal window.

I'd like to assign a color scheme for different hosts so that my terminal windows are easier to tell apart. Can this be done automatically?

share|improve this question

Here's a complete solution. Keep a list of your servers ip addresses and/or domains and the colors you want for them in in ~/.server_colors:,Red Sands,Ocean,Grass,Grass

Then add this line to ~/.profile to hijack the ssh command:

alias ssh="~/bin/safe_ssh $1"

Then compare whatever's after the @ in your ssh target to your list. If there's a match, run an AppleScript to change the screen to the corresponding color. Here's ~/bin/safe_ssh:

ip=`echo $1 | cut -d"@" -f2`
match=`cat ~/.server_colors | grep $ip | wc -l`
if [ $match -gt 0 ]
    color=`cat ~/.server_colors | grep $ip | cut -f2 -d","`
    osascript ~/bin/change_terminal_color.scpt "$color" 2>/dev/null
/usr/bin/ssh $1

And last, here's ~/bin/change_terminal_color.scpt

on run argv
    tell application "Terminal" to set current settings of selected tab of window 1 to (first settings set whose name is (item 1 of argv))
end run

I took most of this code from this blog post.

share|improve this answer
Very nice. In the safe_ssh script, the $1 should be $@ to allow extra parameters to SSH to be passed through. Perhaps also a call after ssh to return the terminal back to the default. One last edit would make this pretty much perfect: support for SSH commands not containing '@'. – nOw2 Aug 31 '13 at 13:02


Either you use e.g. "screen" and customize it:

Or you manage to do it on your SSH Client, if possible.

You could also try this:

share|improve this answer

The solution of @muirbot works really well for me. I made some little improvements to that. I'll add it below his post once I have enough reputation.

Replace the line

ip=echo $1 | cut -d"@" -f2
ip=echo $@ | grep -Eio [[:alnum:]_.-]+@[[:alnum:]_.-]+ | cut -d@ -f2

This change allows for giving additional arguments to your ssh command like "ssh -p 1111 userName@host"

The regular expression allows for simple ipv4 addresses and domain names.

To further support multiple arguments change the last line into

/usr/bin/ssh $@

share|improve this answer

I was just looking for the same thing and found this article:

It uses a php script to change the terminal colors by applescript. You can set up mappings of different colors for each server. Works great for me, though feel the urge to rewrite the php stuff into ruby :)


share|improve this answer

I use a script that launches SSH in xterm windows with different bg/fg colors. It selects the colors based on the hostname's hash from a color span so that no configuration is needed.

The script is written in Ruby:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.