Edit files on a remote server via SSH with Sublime right in your terminal

Published on October 30th, 2020

Editing files on a remote server via SSH can be tedious and annoying. It does not matter whether you work with vim, nano, or pico. Personally, I am not a fan of these editors, because I just don't feel comfortable with them. But what I feel comfortable with is Sublime. That's why I'll show you today how to open and edit remote files comfortably with Sublime directly from the terminal.

Installation of RemoteSubl on the local computer

We use a plugin called RemoteSubl locally for Sublime, which brings rmate to Sublime. This plugin can be easily installed via PackageControl.

Installation of rmate on the remote server

rmate is installed on the server and connects back to your computer so that it can communicate directly with Sublime. The easiest way to do this is to use a reverse SSH tunnel. I will show you how this works below.

But now rmate must be installed on the remote server. This is also super easy. Download the binary.

curl -o /usr/local/bin/rmate https://raw.githubusercontent.com/aurora/rmate/master/rmate

Make it executable.

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

Alternatively, you can rename it. I usually rename it to subl - just like I have it locally.

mv /usr/local/bin/rmate /usr/local/bin/subl


The next and last thing we need to do is to set up the port forwarding. By default rmate listens on port 52698. We will leave it that way for now. Normally you have to create the appropriate port forwarding for each SSH connection. And this is how you do it:

ssh -R 52698:localhost:52698 forge@

But since that is super annoying, we can automate the whole thing. To do this, open your SSH config and we will specify that for all hosts (alternatively you can specify that for individual hosts as well), this host forwarding should work. It is quite possible that you already have some other options set. Just add the appropriate part.

Host *
    RemoteForward 52698 localhost:52698

Start working with your local Sublime

That's it! From now on you can simply connect to your servers via SSH and open files by executing the command subl file.txt. After that, your local sublime will open and you will feel at home. Of course, you can also save your files. You can also open several files at the same time by writing several file names directly after each other.

Note: If several people want to work this way on the same server, it is necessary that each user uses a different port. This port must then also be specified by an environment variable.

Bobby Bouwmann and I are writing a book called "Laravel Secrets".
You will learn everything about the undocumented secrets of the popular Laravel framework. You can sign up using the form below to get early updates.
      Visit laravelsecrets.com to get more information.