If you are a sysadmin, your desktop must be filled with SSH consoles, allowing you to supervise and administrate a lot of different servers. And there is nothing more similar to a console than another console.
As all these console are the same, there is a real risk of error, typing some commands on the wrong server ...
Nowadays, the standard Gnome Shell terminal is providing a begining of solutions with the support of profiles. So, with the help of these profiles, you can easily change the title bar, background color, background image or text color of your consoles. Your consoles can be customised for every host, but you have to select the profile once the console is opened.
Why not to automatised the process ?
This article explains a solution to select automatically a profile according to the SSH host. The main principle of the proposed solution is to :
- create one SSH configuration for each host
- create one Gnome Terminal profile per host
- use a helper script to detect the host and to launch the terminal with the right profile
To make it simple, when you will type custom-ssh -e "ssh server1" you will launch gnome-terminal SSH console to server1 host using server1 profile.
The strengh of this solution is that it will be integrated with SSH Search Shell Extension, which is a fantastic productivity tool available under Gnome Shell. It allows you to launch your SSH console by just typing the first letters of the host to administrate.
It has been tested under Ubuntu Precise 12.04, but it should work with any Linux distribution using Gnome Shell 3.x.
When every thing will be setup, here is an example of what you can get.
1. SSH Hosts Configuration
If not already done, the first step is to create your different SSH hosts with their specific parameters.
This is done thru the file config in the .ssh folder of your home directory.
If your .ssh folder doesn't exist, it will be created the first time you do any type of ssh connexion.
# gedit $HOME/.ssh/config
You have to make sure that your config file is having 600 rights. Otherwise, SSH will refuse to use it.
# My first server, LAN access
# My second server, internet access
Avoid to use the caracter '-' (minus) in you host names.
It will give trouble with integration within Gnome Shell SSH Search explained later.
2. Create Gnome Terminal Profiles
Second step is to create the Gnome Terminal profiles.
In our example, we need 2 different profiles with these names :
You can easily create the profiles from any Gnome Terminal windows thru the menu Edit / Profiles ...
The only important thing is that your profile names are exactly matching your SSH config host names.
3. Custom SSH Terminal Script
When SSH hosts and Gnome Terminal profiles are created, we will create a pseudo terminal script that will be called as a replacement of gnome terminal.
Its job will be to :
- isolate the ssh host from the command line
- launch gnome terminal with the profile according to the ssh host
The terminal script will be placed under /usr/local/sbin to be accessible by any user.
# sudo wget -O /usr/local/sbin/custom-ssh https://raw.githubusercontent.com/NicolasBernaerts/ubuntu-scripts/master/ubuntugnome/custom-ssh
# sudo chmod +x /usr/local/sbin/custom-ssh
# Script used to create SSH terminal with custom theme per host basis
# This script handle a custom profile for every SSH gnome terminal sessions
# The gnome terminal profile must match the SSH Host name
# Used in http://bernaerts.dyndns.org/linux/76-gnome/223-gnome-shell-customise-ssh-terminal
# Parameters :
# $1 : -e
# $2 : "ssh host"
# 20/05/2012, V1.0 - Creation by N. Bernaerts
# get terminal profile form ssh host
PROFILE=$(echo $2 | cut -d ' ' -f 2)
# call gnome terminal with the needed profile
gnome-terminal --window-with-profile="$PROFILE" "$1" "$2"
For the custom terminal to be recognised as a standard desktop application with an associated icon, we have to create a desktop declaration file under /usr/share/applications.
# sudo wget -O /usr/share/applications/custom-ssh.desktop https://raw.githubusercontent.com/NicolasBernaerts/ubuntu-scripts/master/ubuntugnome/custom-ssh.desktop
Name=Custom SSH Terminal
Comment=Customised SSH terminal using Gnome Terminal
4. Integrate with SSH Search Shell Extension
The solution is ready to be used as a shortcut or a command line :
# custom-ssh -e "ssh my_server1"
You Gnome Terminal should now open a SSH session on the host my_server1 with the profile my_server1.
To be able to start your console in a very simple and effective way, you should install SSH Search Shell Extension.
Once installed, you should be able to see your predefined SSH hosts while doing a Gnome search. But if you select on of them, its a plain an simple Gnome Terminal which is used.
We have to configure SSH Search Shell Extension to use custom-ssh instead of gnome-terminal.
This can be done thru a simple gnome configuration :
# gsettings set org.gnome.desktop.default-applications.terminal exec custom-ssh
Finally, you need to restart Gnome Shell interface with ALT+F2 and 'r'.
Your SSH consoles are now fully customised host by host and you can launch them by typing the first letters of your host in Gnome Search.
Your sysadmin productivity will get a nice boost :-)
Hope it helps.