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:
        RemoteForward 52698
  7. Save (ctrl+w) and SSH into your server (ssh
  8. ‘Install’ the rsub remote script:
    sudo wget -O /usr/local/bin/rsub
  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:

27 Responses leave one →
  1. Dave Kiss permalink
    February 8, 2013

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

  2. Alvin permalink
    April 3, 2013

    Thank you for the tutorial.

  3. RickG permalink
    April 4, 2013

    Works great!

  4. David Kemp permalink
    April 17, 2013

    sshfs has many fewer steps

  5. NelsonMinar permalink
    April 17, 2013

    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

  6. Lex permalink
    June 28, 2013

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

  7. Jesse permalink
    July 26, 2013

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

  8. thumbtackthief permalink
    September 30, 2013

    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 permalink
      December 11, 2013

      You need to have sublime text open with rsub installed.

    • Wes permalink
      January 27, 2015

      I had a similar issue. Rebooted Linux server (Raspberry Pi) and Sublime Text 2 and it worked great after that.

  9. ambar permalink
    October 4, 2013

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

  10. October 14, 2013

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

  11. jacobu9 permalink
    November 3, 2013

    If you want something a bit more robust and editor-agnostic, you can try something I’ve been working on called xeno ( 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.

  12. xrc software permalink
    February 15, 2014

    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 :)

  13. February 20, 2014

    +1 fantastic tool!

  14. Alex M permalink
    June 30, 2014

    For anyone who needs hope, I’ve got this working for Sublime Text 3 on Windows 7 with an Ubuntu server via PuTTy.

    • Dylan permalink
      July 9, 2014

      Looking forward to that! Any downloads?

  15. July 27, 2014

    i am lost in no 5 ! i cant find this option!

  16. Albert Lin permalink
    August 28, 2014


  17. Hari permalink
    November 20, 2014

    You sir have just made my day !

  18. Rafael Cordeiro permalink
    December 1, 2014

    Works PERFECTLY! thanks! I love it

  19. Magnus permalink
    January 11, 2015

    Thank you so much! Saves me a lot of hazzle.

  20. Michael permalink
    March 25, 2015

    Great one :) Thanks!

  21. April 29, 2015

    Works beautifully well with latest Sublime 3. Just make sure you SSH into remote host *after* updating the local “~/.ssh/config”. I had a session open and tried to use it, obviously it didn’t work. After connecting again it worked just fine. Many thanks!

  22. aviraj permalink
    February 23, 2016

    I followed every steps but at last i am getting below error
    connect_to localhost port 52698: failed.
    Any idea why am i getting this error ?

    Thanks in advance!

Trackbacks and Pingbacks

  1. リモートサーバー上のファイルをローカルのSublime Text 2で編集する ¶ blog.masusugu
  2. 使用Sublime Text编辑远程服务器文件 - 浏洋的博客

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS