Skip to content


screen_ssh

I use GNU Screen a lot – as in basically all the time, and when I SSH somewhere I like to set the title of the screen I’m in, so I can easily keep track of loads of them.

To do this I’ve pulled together ideas and suggestions from a bunch of people to come up with a script which can be executed by SSH when it connects to a remote server.
You’ll need to edit

~/.ssh/config

and set something like this:

Host *
  LocalCommand /path/to/screen_ssh.sh $PPID %n
  PermitLocalCommand yes

This will set the screen title to the name of the machine you SSH’d to and do its best to chop off extraneous Top-Level-Domain information (i.e. if you ssh to foo.company.com the title will be “foo”).

You can download the script here: screen_ssh.sh

This is an example, if such a thing were needed:

If you want the blue line to appear at the bottom of your Screen sessions, add this to ~/.screenrc (all on one line):

hardstatus alwayslastline
"%{= bw} %{= bc}[%{-}%0c%{= bc}]%{-} [%-Lw%{= bW}%{+b}%50>%n%f* %t%{-b}%{= bw}%+Lw]%<"

9 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. PIONNIER says

    Do you know how to use it on mac?

  2. cmsj says

    Pionnier: Unfortunately not, I don’t know how OSX’s ssh stuff works.

  3. Luke says

    I needed to add “PermitLocalCommand yes” to /etc/ssh/ssh_config instead of /etc/ssh/sshd_config on Ubuntu. Works great now! :)

  4. kinji says

    How did you do your ascii art on the screenshot ? Did you use some framework or just by hand ? ‘Cause it is really cool :)

  5. cmsj says

    kinji: that’s the output of:

    toilet –gay mairukipa.tenshu.net

    (a really horrible name for an app and its colourful option, but there it is)

  6. Thomas Morgan says

    Do you have a method that also works on web ssh clients ?

  7. Chris Jones says

    Thomas: don’t use web ssh clients :)

  8. Jonas Jacobsson says

    Nice. But when exiting the ssh session I would like the title to change back to the old (bash), or even better, the local host. Now it just keep the hostname until I ssh to a new machine. Any ideas?

Continuing the Discussion

  1. ./alexandru » GNU Screen, Window Manager. linked to this post on June 26, 2010

    [...] Install screen_ssh.sh so your window title automatically renames to your ssh destination.  To have the title revert [...]



Some HTML is OK

or, reply to this post via trackback.