Lately I'm working a lot with a few open ssh connections to multiple VPS servers. The hostnames of the servers all follow an ID approach and it's becoming very difficult to know on what machine I'm working with.
I was wondering if there is a way to put a name I define somewhere as the title of the terminal. So I would, for example, associate IP 123.123.123.123 with webserver-stg. When opening the connection to the IP, webserver-stg would automaticaly be displayed as the name of the session. Of course I'm not able to change code on the VPS servers, so the solution should be client-side.
Edit: I'm working with terminal.app on OSX 10.6
xterm has a -T flag that lets you set the window title. putty lets you set it in the Behavior sub-menu of the Window options.
Assuming the remotes hosts are *nix, you can also set your login prompt to be the hostname.
In bash or ksh, doing
export PS1="[\u@\h]$ "
results in something like:[mazianni@europe]$
First of all you should try to automate your process so you aren't running a lot of ssh sessions by hand.
To follow up on the xterm -T
option, you can also set the xterm title via shell escapes. I think most terminal programs support a similar function. See the Xterm Title Howto for details. Then use a wrapper for your ssh command, something like this:I verified that works in xterms and in the mac terminal.app, like I said it probably works in most terminal programs which emulate exterm.
Why not just setup meaningful CNAME records that point at the ID type hostname. You can then connect via the CNAME instead. If you don't have access to DNS for these hosts, you could do it with a HOSTS file too - which will work for any computer it is installed on.
Putty will display whatever you used to connect in its title bar. Can't say for XTERM.
Alternatively, if you are using PuTTY, you could just configure a Session with the name you want in the title bar (Window > Behaviour option in menu), the ugly hostname/ip address in the destination field, and your preferred name as the Session name. Then you can click on the memorable Session name to open the connection and have the title as you want.
You might also want to do something to the .bash_profile for users sshing in so that the preferred name is used in the prompt on the box, but you said you couldn't change anything on the box (seems likely you can change your own profile though).
The other answers are correct, but I find that it is more useful to have a good script and shortcuts to it.
I personally use Ion3 on Debian and have F4 bound to the following script. Ion3 prompts me for the hostname:
If you want a panel shortcut that asks you for a hostname, then create a panel shortcut that links to the following script:
Finally, you can also just create a script and then have links to that script, each for a different host.
Then, create links such as: ln -s ssh-script.sh yourhost.example.com
You would then, for each such link, create a separate desktop/panel shortcut.
Will change the title of your Mac OS X Terminal window to the given string. Then you can easily choose which terminal window you want from the Window menu in Terminal.
If $HOSTNAME isn't defined as well as you'd like, you can insert any arbitrary string with a subshell command, like this: