Ideas X Close

{{ }} {{ article.publishedDate | date:'MM.dd.yy' }} {{ }} {{ }} {{ article.minutesToRead }} min read {{ article.alternateText }}

{{ article.title }}


Editing Files on Raspberry Pi with Local Sublime

March 23, 2015 / By Chris Wigley


Editing Remote Files on a Raspberry Pi with Sublime Text 2/3

Lately, I've been doing a lot of work with a Raspberry Pi. Until recently, I would ssh into the Raspberry Pi, and use Vim on the pi to edit files on the pi. I really hate doing this, not because I don't like Vim, but because I love Sublime Text. I can't reasonably install Sublime Text on the Raspberry Pi, so I sought the next best thing: use my local instance of Sublime Text to edit the remote files on the Raspberry Pi. To do this, I had to setup a few things, but now that I'm done, it's hard to imagine doing it any other way.

This article assumes you have Sublime Text 2 or 3 installed on your local computer, either MacOS or WIndows, and that you have a running Raspberry Pi that you can ssh into.

Steps We'll Perform

  • Install rsub for Sublime Text on your local computer
  • Edit ~/.ssh/config on your local computer
  • Install rmate shell script on the Raspberry Pi

Package Control for Sublime Text

The first you thing you'll need to do is to add the rsub package to Sublime Text. The best way to install the package for Sublime Text is to use the excellent Package Control Sublime Package Manager tool.

Installing the RSUB Package

Once you've installed Package Control, open Sublime Text and press command+shift+p (ctrl+shift-p on Windows) to bring up the package manager dialog in Sublime Text. The dialog will show a number of options and a textbox in which you can type. Type install, and the visible list of options will be automatically filtered down to a subset of options, and you should see an option Package Control: Install Package. Select this option, and the dialog content will refresh with a list of packages that you can install into Sublime Text. You will see a textbox in which you can type. Type rsub in the textbox, which will filter the list, and automatically highlight the rsub package name. Press Enter (or click the rsub option with you mouse) to install the package.

Installing rsub in Sublime Text

When you install a package for Sublime Text using Package Control, you'll have to look at the left portion of the bottom status bar of Sublime Text to see the installation progress.


The next step is to modify the ~/.ssh/config file on your local machine. You need to do this so that the remote port on the Raspberry Pi will be forwarded to a local port on your local computer.

The port, 52698, is used by rsub for the secure communication (via ssh) between your local computer (Sublime Text) and the remote Raspberry Pi.

Go ahead and open the `~/.ssh/config file (there's no file extension) in your favorite text editor (Sublime, of course). I like to use the terminal to open the file:

subl ~/.ssh/config

The previous example assumes you have a bash alias for Sublime Text in your terminal profile (e.g., in your ~/.bashrc, ~/.profile, ~/.zshrc, etc.).

If you don't have an alias configured for Sublime Text, it's no big deal. Simply navigate your file system from your user directory to locate the .ssh folder, and open the config file located in the .ssh folder.

Once you have the config file open, add the following lines to the bottom of the file:

    RemoteForward 52698

In the above example, replace with the IP Address or hostname of your Raspberry Pi. Save and close the config file.

Setting up the Raspberry Pi

We're almost done. You've made it this far. Don't give up.

Install RMATE
Now you need to ssh into the Raspberry Pi (ssh your_username@your_raspberry_pi_address). Once you've ssh-ed into the pi, run the following in the terminal:

sudo wget -O /usr/local/bin/rsub

This command downloads the rmate repository from github into a newly created rsub folder in the /usr/local/bin/ folder on the Raspberry Pi.

Make the Script Executable
You can't do anything with the rmate script you just downloaded until you make it executable. To do that, run the following command from your terminal while still ssh-ed into the Raspberry Pi:

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

This command will make the rmate file an executable file.

We're done!

Ok, whew! Take a breath. Now that you've done all of the above, let's see it in action. While still ssh-ed into the Raspberry Pi, use the terminal to navigate to a directory that contains a text file on the Raspberry Pi. Once you're at the directory, type the following at the terminal command prompt:

rsub my_file.html

Presto! The file should open in Sublime Text on your local computer. You can edit the file and save your changes, and the file will be updated on the Raspberry Pi! You no longer need to ssh into the Raspberry Pi to edit files on the pi. Shazam!

Here's me opening a file called index.html on the Raspberry Pi, with Sublime Text on my local Macbook Air:

using rsub to open file in Sublime

Cool, yeah?

I hope this improves your workflow, and inspires you to look for other creative ways to make everyday tasks easier for you and others.

Curious to read another one of my posts? Check out this post on things to consider for designing modal windows.

Interested in learning more or joining the team? Let's talk.

Chris Wigley
Solutions Architect

At the time of publishing, Chris was a Solutions Architect at One North.

Subscribe to our Blog


Brand Planning and Digital: A Framework