When I ssh into a remote production server I would like the colour scheme of my terminal window to change to something brigh and scary, preferably red, to warn me that I am touching a live scary server.
How can I make it automatically detect that I have ssh'ed somewhere, and if that somewhere is on a specific list, change the colour scheme?
I want to update the Scheme of Terminal.app, not know how I would do this in a pure linux/unix env
To do so, navigate to the Terminal's Preferences screen. From here, select the Profiles tab. This section will let you adjust the appearance of the Terminal window. You're able to change the background and text color, text-rendering options, font sizes and typefaces, the cursor type, selection color, and ANSI colors.
Under Background: Click on the image box that reads - Color and Effects, You will see a Colors window open, where there are multiple bars, adjust Opacity, as you make this value less then 100% you will see that the background of the Terminal window gets transparent. Close the Colors window, Close the Preferences window.
Put following script in ~/bin/ssh
(ensure ~/bin/
is checked before /usr/bin/
in your PATH):
#!/bin/sh HOSTNAME=`echo $@ | sed s/.*@//` set_bg () { osascript -e "tell application \"Terminal\" to set background color of window 1 to $1" } on_exit () { set_bg "{0, 0, 0, 50000}" } trap on_exit EXIT case $HOSTNAME in production1|production2|production3) set_bg "{45000, 0, 0, 50000}" ;; *) set_bg "{0, 45000, 0, 50000}" ;; esac /usr/bin/ssh "$@"
Remember to make the script executable by running chmod +x ~/bin/ssh
The script above extracts host name from line "username@host" (it assumes you login to remote hosts with "ssh user@host").
Then depending on host name it either sets red background (for production servers) or green background (for all other). As a result all your ssh windows will be with colored background.
I assume here your default background is black, so script reverts the background color back to black when you logout from remote server (see "trap on_exit").
Please, note however this script does not track chain of ssh logins from one host to another. As a result the background will be green in case you login to testing server first, then login to production from it.
A lesser-known feature of Terminal is that you can set the name of a settings profile to a command name and it will select that profile when you create a new terminal via either Shell > New Command… or Shell > New Remote Connection….
For example, duplicate your default profile, name it “ssh” and set its background color to red. Then use New Command… to run ssh host.example.com
.
It also matches on arguments, so you can have it choose different settings for different remote hosts, for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With