Skip to content

Sublime Tunnel of Love: How to Edit Remote Files With Sublime Text via an SSH Tunnel

2013 February 4

Eventually you will need to edit a file in-place on a server, for one reason or another (i.e. working on a Javascript front-end that requires templating from a backend); this is partly what Emacs and Vim are for (and they’re both very good at what they do).

There’s nothing wrong with learning either of those tools, but if you really don’t want to, there are options.  If the server is running FTP, you can use something like Transmit to open the file in a local editor and saves will be automatically uploaded to the server.  Unfortunately, FTP is a very old and VERY insecure protocol that should not be used anymore.  What else can we do?

Using Secure Shell (SSH) Tunneling, we can establish an SSH session that routes arbitrary traffic through it to a specified port for any use we want.  Thanks to a nifty set of scripts called rsub, modified originally from TextMate’s rmate, we can run a little utility server on our local machine that interacts with your remote server for you and lets you open up remote files and save them back, all through an encrypted channel.

What Do I Do?

  1. As of writing, these instructions work only for Sublime Text 2.  If I get a chance I’ll look into forking rsub for the newly released ST3 (which runs Python3).
  2. If you don’t already have Sublime Text’s wonderful package manager, install it.
  3. Hit Ctrl+Shift+P, start typing “install” and select “Install Package”
  4. Start typing “rsub” and select it.
  5. Once it’s installed, get on your terminal and do
    nano ~/.ssh/config
  6. Paste the following lines:
    Host your_remote_server.com
        RemoteForward 52698 127.0.0.1:52698
  7. Save (ctrl+w) and SSH into your server (ssh username@your_remote_server.com).
  8. ‘Install’ the rsub remote script:
    sudo wget -O /usr/local/bin/rsub https://raw.github.com/aurora/rmate/master/rmate
  9. Make that script executable:
    sudo chmod +x /usr/local/bin/rsub
  10. Lastly, run rsub on the remote file you want to edit locally:
    rsub ~/my_project/my_file.html

    and it should magically open in Sublime Text!

Let me know if this works for you! Enjoy!

Related Posts:


  • Dave Kiss

    Really rad, would love to see the ST3 fork completed. Thanks for the tutorial.

  • Alvin

    Thank you for the tutorial.

  • RickG

    Works great!

  • David Kemp

    sshfs has many fewer steps

  • NelsonMinar

    Very helpful, thank you. One minor drawback compared to editing local files; ST2 won’t detect asynchronous changes from the file on the remote server. The source for the rsub package for ST2 is https://github.com/henrikpersson/rsub

  • Lex

    I’m having a total nerdboner in reaction to this working out of the box. Thanks!

  • Jesse

    That was THE tip! Huge props man! Thanks a million!

  • thumbtackthief

    I keep getting:

    /usr/local/bin/rsub: connect: Connection refused

    /usr/local/bin/rsub: line 200: /dev/tcp/localhost/52698: Connection refused

    Unable to connect to TextMate on localhost:52698

    • Akhl

      You need to have sublime text open with rsub installed.

  • ambar

    This is simply awesome. Works great with Sublime Text 3 (ST3 build 3047). Thank you!

  • http://www.loudnoises.us/ Paul at LoudNoises

    Works perfectly with Sublime 3. Love this workflow. Thanks!

  • jacobu9

    If you want something a bit more robust and editor-agnostic, you can try something I’ve been working on called xeno (https://xeno.io). It’s free and open source, and I’d love some feedback.

    Basically, it’s a Git/SSH mashup written in Python that allows you to edit files and folders from a remote machine in your local editor (whatever that may be). You don’t have to configure kernel modules or forward ports, you don’t need to have a persistent connection – it’s all automatic and easy.

    What it does is generate an out-of-worktree Git repository of the files you want to edit on the remote machine, and then clones it locally and uses Git over SSH as a transport/synchronization mechanism. Because it’s built on Git, it’s extremely fast and supports automatic merging of files that might be changing on both ends, unlike SSHFS/rmate/rsub which will just clobber any files with older timestamps.

  • xrc software

    Thanks lot for this great tutorial
    Below you will find the screen shot for Putty SSH connection configuration which is replacing the steps 5,6,7.
    1- Establish SSH connection with remote server.
    2- Right click on putty window title.
    3- Choose Change settings / Tunnels.
    4- Modify the settings as shown at the picture below.
    5- Apply.
    6- Enjoy :)

  • http://residr.com/ Jordan Arseno

    +1 fantastic tool!