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 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

  • Are you using command line ssh to connect to the remote hosts or something like putty ? – user9517 Jan 14 '11 at 16:07
  • I am mainly using terminal.app on OSX – kimausloos Jan 14 '11 at 23:55

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:

if [ x$1 != x ]
  read -p "host? " remote
echo -ne "\033]0;$remote\007"
exec ssh $remote

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.

  • It would be better to do: if [ -n $x ]; then read -p "host? " remote; else remote=$1; fi; echo -ne "\033]0;$remote\007" ; exec ssh $remote – ewindisch Jan 14 '11 at 19:14
  • Oh yeah I just banged out some ugly bash that works, you can definitely make it a lot more elegant. – Phil Hollenback Jan 14 '11 at 19:15

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:



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:

x-terminal-emulator -t $HOST -e ssh -l root $HOST

If you want a panel shortcut that asks you for a hostname, then create a panel shortcut that links to the following script:

HOST=$(zenity --entry --text="Connect to SSH Host")
x-terminal-emulator -t $HOST -e ssh -l root $HOST

Finally, you can also just create a script and then have links to that script, each for a different host.

x-terminal-emulator -t $HOST -e ssh -l root $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.

PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'

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:

PROMPT_COMMAND='echo -ne "\033]0;$(cat /etc/my.host.name)\007"'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.