Present Perfect


Picture Gallery
Present Perfect

one-click terminal window to remote hosts

Filed under: Fluendo,Hacking,sysadmin — Thomas @ 15:54


By now we have three platforms we're managing - one internally for development, and two external ones. It gets a little tedious always typing the right commands to log in to them, and it gets a little dangerous because the hostnames are named relatively consistently across the platforms, and a terminal prompt only shows the first part. So, "myimportantserver" would exist in all three platforms, and it's just no fun at all to discover that you typed "reboot" in the wrong window.

Here's how I set up a gnome-terminal launch icon on my desktop for each platform:

  • Create a new profile in gnome-terminal (Edit>Profiles, New)
  • Give it the name of your platform/group of hosts, for example my.platform
  • Edit the profile, go to the "Title and Command" tab, and select "Run a custom command instead of my shell"
  • As the custom command,enter "ssh firsthost.my.platform"
  • In the Colors tab, deactivate "Use colors from system theme"
  • Pick a background color that will remind you of this platform
  • Right-click on a panel, add a custom launcher
  • Give it a name like "Terminal my.platform"
  • As the command, use "gnome-terminal --window-with-profile=my.platform"
  • Pick an icon (Would it not be nice to have nautilus's emblems for this ?)

Now, clicking the icon should give you:

  • a terminal window
  • with a login on that machine
  • in a different color than your normal terminals, so you really know what platform you are on

Make sure you make log-ins very easy by using ssh keys, and using a desktop running under ssh-agent, so you can ssh-add your key once and then log in to these machines with a single click.  You should make it easy to jump from this entry point host to the other hosts on your platform, by using authentication forwarding for this first host.  This makes going to the next one as easy as typing "ssh nexthost"

Now, for the dessert: open a new tab in this terminal and see what happens!


  1. And thanks to Alacarte, these days you can create a menu for them too :-) Nice if you can’t quite remember what machine each icon stands for.

    Comment by Juri Pakaste — 2007-04-01 @ 17:03

  2. Cool, I did not know this one. It seems that the –tab-with-profile switch does not work though, it only opens a new window. Anyone knows a solution?

    Comment by knipknap — 2007-04-01 @ 17:11

  3. Thanks ! This is an extremely handy trick to whoever uses ssh daily.

    (BTW WordPress transformed the two -‘s into a – on the “gnome-terminal …” command line)

    Comment by Sunny — 2007-04-01 @ 17:12

  4. This made me try something: right-clicking on a remote ssh mount, and then choosing “open terminal here”. Surprisingly enough, it works !

    Comment by S.F. — 2007-04-01 @ 17:20

  5. Nice!

    I’ve always used different colours in my PS1 to distinguish local terminals from remote ones (change colour if SSH_CONNECTION is set) and also to distinguish root shells from regular user shells.

    Another useful thing you can do with gnome-terminal: open ssh sessions to multiple hosts in different terminal tabs. Useful when Ubuntu releases a security update that you want to install in several machines. The command line is pretty tedious, though:

    gnome-terminal –tab -e “sh -x -c ‘ssh host1 sudo apt-get upgrade'” –tab -e “sh -x -c ‘ssh host2 sudo apt-get upgrade'” …

    I wrote a short script to construct it from a list of hostnames (configurable at the top of the script) and the command (passed on the command line).

    Comment by Marius Gedminas — 2007-04-01 @ 17:52

  6. Nice. Very nice. For quite some time I’ve viewed gnome-terminal’s profiles as needless bloat. I just entirely flipped that view.

    Comment by Graham Forest — 2007-04-01 @ 19:30

  7. Really useful. Great trick man!!!

    Comment by Jose — 2007-04-01 @ 20:54

  8. You might also find libpam-ssh useful; properly configured, it removes the need to ssh-add.

    Comment by Anonymous — 2007-04-02 @ 18:41

  9. I finally made a concerted effort to switch away from mrxvt to gnome-terminal. This was difficult since gnome-terminal, when creating a new tab in an existing window, doesn’t execute the current window’s command-line custom command (that being an ssh to the desired host). So, I created a wrapper script that takes input from zenity (the target hostname) and searches for a profile by that hostname. It then either loads that profile if it finds one or just creates a new gnome-terminal profile on the fly using gconftool-2. :)

    It’s a hack but it works nicely. :)

    Comment by Frank — 2007-04-03 @ 20:54

  10. –window-with-profile-internal-id is the right option for me
    Best Regards

    Comment by Sebastian — 2007-04-04 @ 01:04

  11. Thanks for this!
    –window-with-profile=my.platform should be -–window-with-profile=my.platform
    for me, anyway

    Comment by Eoghan — 2007-09-26 @ 21:52

  12. Thank you, been searching for this, now i won’t have to hack my .bashrc

    Comment by Vimm — 2010-02-19 @ 03:13

  13. Thanks, that was a simple and clear tip. What I’m after now, is a way to simultaneously set the character encoding. My machine uses UTF8, but some remote hosts are in ISO-8859-1. I have not found a way to change the character encoding through a command-line switch to gnome-terminal, or some shell command or property. I have to do it manually through the menu, every time I start the terminal.
    Anybody have an idea?

    Comment by rduke15 — 2010-09-18 @ 10:57

  14. Replying to myself… Found the solution for setting the character set. This works for me:

    env LANG=en_GB.iso88591 gnome-terminal –window-with-profile=my-latin1-host –disable-factory

    Comment by rduke15 — 2011-01-14 @ 11:37

RSS feed for comments on this post. TrackBack URL

Leave a comment