Live Editing Raspberry Pi Files Remotely on a Windows PC – Using Sublime Text, RSUB and PuTTY

Pi_PuTTY_Sublime_CFile

Having started to do some programming on my Pi I soon came to become frustrated with the basic editors on offer. I wanted an editor which was more suited to programming, language aware colour coding, helping with syntax and having ideally having some auto-complete functionality.

I figured I couldn’t be the only one wanting to do this, and sure enough with a bit of time searching I found a couple of guides:

These provided a great guide on using the rsub etension for Sublime Text, but had one small stumbling block. They both stated I needed to modify ~/.ssh/config on my Windows machine. Well I suspect this was assuming I had some other Open SSH client installed. I use and am happy with PuTTY and derivative fork KiTTY. So the next step was determine how to configure PuTTY to provide an SSH tunnel. Again a quick search and the answer was found here: http://www.akadia.com/services/ssh_putty.html

So I found all I needed to know. So here’s the steps I followed to get it all setup. Much of this duplicates the information in the earlier referenced links, but this is my step by step guide.

Initial Downloads

  • PuTYY or KiTTY – A terminal emulator and SSH client
  • Sublime Text (version 2) (version 3 beta (this is the version I used)) – A text editor for code and markup with colourful syntax highlighting with lots of other helpful capabilities.

At time of writing, details on rsub state that it supports Sublime Text 2, but not 3, however I didn’t have any issues with the latest 3 beta.

Download and install both on your Windows PC. For me, something odd happens anytime I try and install Sublime Text 2 or 3 on my PC. Launching the setup program, it takes several minutes before the installer actually appears. It looks like a possible interaction with Microsoft Defender, but I can’t be sure.

Sublime Text Setup and Configuration

The rsub component we need is an addon. This is easiest to install once we add package control support to Sublime. To do this we have to follow these steps:

Install Package Control into Sublime Text

  • Open Sublime Text
  • Navigate to https://packagecontrol.io/installation and select the tab for either Sublime Text 2 or Sublime Text 3. Copy the contents
  • In Sublime Text select: “View -> Show Console” from the menu (shortcut: CTRL + ‘)
  • Paste in the text from the package control site into the console that appears at the bottom of the screen. Press enter
  • Restart Sublime Text

Install rsub into Sublime Text

  • Open Sublime Text
  • From the menu select: “Preferences -> Package Control” (shortcut: CTRL + SHIFT + P)
  • In the dialog that appears enter: “Install” then select “Package Control: Install Package”
  • In the subsequent text box that appears enter: “rsub”, select the rsub package returned in the search results
  • rsub is now installed.

Putty SSH Tunnel Setup

You may already have PuTTY setup for connecting via SSH to your Pi. If so you can modify your existing connection and so skip the first stage below.

Create Initial SSH connection

  • Determine the IP address of your Raspberry Pi.
    • The IP address is sometimes shown before the logon prompt is shown on your Pi. I’ve seen this report an incorrect address when using WiFi and the connection isn’t fully setup before the IP address is displayed.
    • Logon to your Pi and run the command: hostname -I
    • Logon to your Pi and run the command: ifconfig
      • The IP address is shown in the output as inet.
  • Open PuTTY
    • Enter the hostname or IP address of your Raspberry Pi
    • Select the connection type as: SSH
    • Under the “Saved Sessions” label there is a text box, enter a friendly name for your Pi, and press Save.
    • Confirm you can connect to your Pi by selecting “Open”

Adding SSH Tunnel for RSUB

Now that you have an initial connection in place and can SSH into your Pi. We now want to add an SSH tunnel between the Pi and your PC so that rsub can open the files in Sublime Text

  • Within Putty Load your connection to your Pi
  • From the menu on the left select: SSH -> Tunnels
  • Add the tunnel for the Pi on port 52698
    • Source Port: 52698
    • Destination: 127.0.0.1:52698 (aka Localhost)
    • Select: Remote (from the collection of radio buttons)
  • Select back on the top node in the left hand menu: Session
  • Save the updated connection
  • Quit PuTTY.
  • When you restart and make a connection Window Firewall will probably prompt you to allow application through the firewall. You need to allow this.

Putty SSH Tunnel Setup for rsub

Pi Setup

Logon to your Raspberry Pi and run the command the wget command to download rmate and name the binary rsub, then give it execute permissions:

sudo wget -O /usr/local/bin/rsub https://raw.github.com/aurora/rmate/master/rmate

Update 18 Jan 2016: Whilst setting up an old RPi 1, the command above didn’t work. Giving a TLS error (GnuTLS: A TLS fatal alert has been received.). However this command to download the file did work:

sudo curl -L --output /usr/local/bin/rsub https://raw.github.com/aurora/rmate/master/rmate

sudo chmod +x /usr/local/bin/rsub

Remote File Editing

Now we’ve got it all setup. Time to test it works.

Important Note: rsub will only work with Sublime Text open on the Windows PC. It won’t start it if it’s not already running.

Simply logon to your Pi via PuTTY with the SSH tunnel all setup. Navigate to where you have a file you want to open. Edit it by simply using rsub <filename>. The file specified will open in Sublime Text, you can make your changes to the file. When you save it back, you are saving it back to the Pi. Great, right?

PuTTY to Sublime Text via rsub Demo

One thought on “Live Editing Raspberry Pi Files Remotely on a Windows PC – Using Sublime Text, RSUB and PuTTY

Leave a Reply