snork.ca: Welcome to the brown age of computing! Partly Cloudy, 7.6°C - No precip

Colourizing And Menuizing My Xfce SSH Sessions 2017-07-22


I usually have a bunch of SSH sessions open. They're often busy tail'ing log files, scrolling Asterisk output, or forwarding ports for me to access other services. On Windows you can easily set the colours of your SSH sessions in a client like PuTTY or KiTTY, but in Linux the expectation is that you'll use your usual terminal application, which probably doesn't allow you to specify custom colours for your SSH hosts. The desktop environment I am using (minimal Xfce on Jessie) also doesn't provide an easy way to make a menu that can access all my SSH sessions quickly. So, here's what I did.

Part 1: Get SSH Working

To start with, I got my SSH sessions working with keys so I wouldn't be typing in passwords all the time. There are plenty of tutorials and forums posts on how to make this work, but the general idea is to (1) generate a keypair (2) setup your ~/.ssh/config with an entry like below and (3) copy the public key to ~/.ssh/authorized_keys on the computer you wish to connect to.

example ~/.ssh/config file Host myserver
HostName server.domain.tld
Port 666
User mycoolname
IdentityFile ~/topsecret/sshkeys/myprivatekey

There are obviously plenty of config options I have not included here, but you can decide which ones you want to use on your own. If you can type ssh myserver and get in to your remote server, then you're ready to move on to the next step.

Part 2: Colourize Your Sessions

If you only have one server that you remotely SSH in to, then you may not care to colourize your terminal on a per-server basis. However, if you do have multiple SSH sessions open sometimes, you might want to make it easy to tell which one is which with a quick glance. To do this, start by creating a script on the server you'll be SSH'ing in to, we'll call it setcolour.sh:

~/scripts/setcolour.sh #!/bin/bash
echo -e "Setting text colour to \e[92mlight green..."

The \e[92m just happens to be light green. I like light green on a black background for my log scrolling server because it really stands out and is easy to read in chunks. You can choose whatever colour you like, this list has a few to choose from. Once you have your colour picked out, add the ~/scripts/setcolour.sh to your ~/.bash_profile and don't forget to "chmod +x" your script. Now when you log in to your SSH session again you should get your fancy new colour.

Part 3: Make An Xfce Menu For Your Sessions

Another thing that bothered me about Xfce is the complete lack of any reasonable menu editing tool. I made one manually but am not sure it is really worth the pain the arse. Here's what I did in case anyone cares... start by making a directory (we'll call it ~/sshmenu) to keep your menu in, and create an ssh.menu file to lay out your menu.

~/sshmenu/ssh.menu <!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN"
"http://www.freedesktop.org/standards/menu-spec/1.0/menu.dtd">
<Menu>
   <Name>sshmenu</Name>
   <AppDir>/home/user/sshmenu/</AppDir>
   <Include>
      <All />
   </Include>
   <Layout>
      <Filename>ssh_myserver.desktop</Filename>
   </Layout>
</Menu>

Then make a ssh_myserver.desktop file that defines your menuitem:

~/sshmenu/ssh_myserver.desktop [Desktop Entry]
Name=SSH To My Server
Comment=Connect to my really awesome server
GenericName=SSH To My Server
Exec=xfce4-terminal --geometry=190x51 --title="SSH: My Server" -e "ssh myserver"
Icon=xfce4-terminal
Terminal=false
StartupNotify=true
Type=Application
Categories=CoolGuyApp;

You'll of course want to add a .desktop file for each SSH session you want to make a menuitem for, and you'll have to add each .desktop file to your .menu file too. Finally just go in to the preferences of one of your Xfce panels, hit the Items tab, and add a new Application Menu. You need to browse to your new .menu file and you might want to uncheck "Show button title" so your menu is just an icon on your panel. Now you have a quick way to open your SSH sessions and can easily tell them apart when you have a bunch of them running.

tee2 Adding the menu to a panel.


Made with Notepad++ & FastStone, without javascript, cookies, or the help of Clippy or ai. Hosted on Devuan with nginx & powered by NK shrooms.