Skip to content

Instantly share code, notes, and snippets.

@Ninjex
Last active August 26, 2022 10:57
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ninjex/9582357 to your computer and use it in GitHub Desktop.
Save Ninjex/9582357 to your computer and use it in GitHub Desktop.
How to: Setting up Sublime Text to work through an SSH tunnel.

First, you need to install the Sublime Text package manager.

To do this, open up Sublime Text, and hit hit the cntrl+p key binding (or navigate to: Preferences -> Package Control)

When prompted for the search query, type the following: 'Package Control: Install Package'

Press enter, and shortly it should generate a list of plugins that can be installed to Sublime.

Search for the following plugin: 'RemoteOpen' and press enter. This will begin the installation.

Next, we need to configure some settings in our ~/.ssh/config file, so go ahead and open up your favorite editor (Hopefully Sublime) and add the following code:

Host <hostname / host ip here>
  RemoteForward 52698 127.0.0.1:52698

When we create a tunnel via ssh to our desired Host, it will start a session on port 52698, which is what Sublime Text will be waiting on.

This port can be configured from: Preferences -> Package Settings -> rsub -> Settings -- Default, however it is suggested not to do this.

Once you have all the above set up, tunnel into the remote machine you configured previously inside your ~/.ssh/config file.

We now want to install the remote rsub script, and configure it to be executable. The following code snippet will do this for you: sudo wget -O /usr/local/bin/rsub https://raw.github.com/aurora/rmate/master/rmate && chmod +x /usr/local/bin/rsub

Note that if you changed the port in the plugin settings, you need to change the port in the remote script.

Look for line number 56, which will look like port=52698 simply change it to your desired port.

Now, it's as simple as calling the rsub command on a file while on the machine.

Let's test it out with the following code that will generate a file with the text 'Hello, rsub!' and open it inside Sublime on your local machine.

echo 'Hello, rsub!' > tmp.txt && rsub tmp.txt

@bmetea
Copy link

bmetea commented Apr 6, 2018

Hi, is it possible to do this for UDP connections?
I'm using mosh to connect to my ec2 instance so I can roam between ips and different connections without getting a broken pipe. However, rsub gives me this:
usr/local/bin/rsub: connect: Connection refused /usr/local/bin/rsub: line 390: /dev/tcp/localhost/52698: Connection refused Unable to connect to TextMate on localhost:52698

@Dours-d
Copy link

Dours-d commented Aug 17, 2020

Hi, is it possible to do this for UDP connections?
I'm using mosh to connect to my ec2 instance so I can roam between ips and different connections without getting a broken pipe. However, rsub gives me this:
usr/local/bin/rsub: connect: Connection refused /usr/local/bin/rsub: line 390: /dev/tcp/localhost/52698: Connection refused Unable to connect to TextMate on localhost:52698

Same issue for me then meteabogdan ;

We now want to install the remote rsub script, and configure it to be executable. The following code snippet will do this for you: sudo wget -O /usr/local/bin/rsub https://raw.github.com/aurora/rmate/master/rmate && chmod +x /usr/local/bin/rsub

It seems the given code requires a sudo after the && operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment