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:

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

    • john permalink
      June 9, 2015

      where is the picture?

  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. Hugo Gómez Mac Gregor permalink
    June 17, 2015

    This is great!!!
    Before I had mounted the remote folder and it was very slow. This is really fast!

    Thanks a lot!!!

    You just made an Argentinian developer happier :)

  23. September 7, 2015

    For me, it didn’t work until I added “RemoteForward 52698 localhost:52698” to my server block in ~/.ssh/config. See

  24. Kickflip Jawny permalink
    September 18, 2015

    Thank you!

  25. Manuel permalink
    September 23, 2015

    Worked! Thanks!

  26. Patrick permalink
    January 6, 2016

    Awesome script, worked right out of the box and is incredibly useful.

  27. Sae permalink
    January 11, 2016

    Works great. Thanks!

  28. 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!

    • May 17, 2016

      Comments around your should help.

    • September 7, 2016

      Make sure you have sublime program open on your local machine. I had the same problem. This fixed it.

  29. Sabyasachi permalink
    May 6, 2016

    Excellent one ! Thanks a lot !!!

  30. May 17, 2016

    Thanks a lot.
    But I needed to close and re-open my terminal after modifying ~/.ssh/config or connecting to my ssh server with arguments -R 52698:localhost:52698.

  31. Avishek De permalink
    June 13, 2016

    Thank you. Nice tutorial indeed!

  32. August 4, 2016

    Worked only with adding a slightly different entry to my ~/.ssh/config file:

    Host *
    RemoteForward 52698

  33. Zeïok permalink
    August 8, 2016

    Works like a charm, even with Sublime Text 3 !
    Thanks a lot !

  34. September 7, 2016

    Great instructions! Thanks a million for writing this up!

  35. vinit payal permalink
    October 3, 2016

    Able to open file but the file loaded is empty it does not contain information available on server. It’s just opening blank file even though this file does have some content on remote server

  36. olu permalink
    October 19, 2016

    Thank you so much! Works like a charm.

  37. November 8, 2016

    Works Perfect!
    Thank u!!!

  38. December 21, 2016

    Great post!

    I’m a newbie to SSH (and coding) but I was able to get it working with some tweaking. I’m tunneling into a shared server which does not give me permission access rights to /usr/local/bin nor ability to run sudo commands.

    Fortunately the following worked without sudo:

    #8) install using wget into simply “rsub” instead of “usr/local/bin/rsub” (where my current working directory {pwd}= /home/myname):
    wget -O /rsub
    #9) chmod +x rsub

    From here the rsub command returns a bash error that the command is not recognized

    I followed suggestion from Karthik T on this forum to update my ~/.bashrc file on the remote server (while still SSH’d into my server):

    9a) nano ~/.bashrc
    9b) Add line to the bottom of your .bashrc file:
    alias rsub=/home/myname/rsub
    9c) save file
    9d) source ~/.bashrc (in terminal)

    I’m now able to run rsub on the remote file I want to edit locally (#10)!

    Hopefully this helps someone else facing the same issue!

Trackbacks and Pingbacks

  1. リモートサーバー上のファイルをローカルのSublime Text 2で編集する ¶ blog.masusugu
  2. 使用Sublime Text编辑远程服务器文件 - 浏洋的博客
  3. Live Editing Raspberry Pi Files Remotely on a Windows PC - Using Sublime Text, RSUB and PuTTY - Martin's Explorations
  4. LinkedModernismProject/web_code | GITROOM
  5. #Devember log 4 5 6 | Minarth

Comments are closed.