Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Editing Files Remotely via SSH on SublimeText 3

Editing Files Remotely via SSH on SublimeText 3

Sometimes you need to edit a file on a remote server, but using vim/emacs is not very practical, due to lag and speed of screen refresh.

TextMate users have the classic rmate, but it was implemented in Ruby, which may not be available on the remote server.

A better option is to use this version of rmate, implemented in pure Bash. It's a single file, self-contained, and with no external dependencies.

Step by step:

  1. On your local workstation: On Sublime Text 3, open Package Manager (Ctrl-Shift-P on Linux/Win, Cmd-Shift-P on Mac, Install Package), and search for RemoteSubl

  2. On your local workstation: Add RemoteForward 52698 127.0.0.1:52698 to your .ssh/config file, or -R 52698:localhost:52698 if you prefer command line

  3. On your remote server:

    sudo wget -O /usr/local/bin/rsub https://raw.github.com/aurora/rmate/master/rmate
    sudo chmod a+x /usr/local/bin/rsub

Just keep your ST3 editor open, and you can easily edit remote files with $ rsub myfile.txt

EDIT: if you get "no such file or directory", it's because your /usr/local/bin is not in your PATH. Just add the directory to your path:

echo "export PATH=\"$PATH:/usr/local/bin\"" >> $HOME/.bashrc

Now just log off, log back in, and you'll be all set.

Credits: Gui Ambros via https://wrgms.com/editing-files-remotely-via-ssh-on-sublimetext-3/

@scoumbourdis

This comment has been minimized.

Copy link

@scoumbourdis scoumbourdis commented Mar 20, 2019

Thanks @connorjan for sharing this. It works for me :)

@MattRob1nson

This comment has been minimized.

Copy link

@MattRob1nson MattRob1nson commented Jul 3, 2019

This is great - thank you!

@ericksho

This comment has been minimized.

Copy link

@ericksho ericksho commented Jun 11, 2020

Thanks!
hint: to edit with sudo I run which rsub it give me /usr/local/bin/rsub, then just run sudo /usr/local/bin/rsub file-name

@ams001

This comment has been minimized.

Copy link

@ams001 ams001 commented Jul 9, 2020

While this solution works for editing files on a single remote host t a time, how can I simultaneously edit multiple files across multiple hosts?

@jinseokim

This comment has been minimized.

Copy link

@jinseokim jinseokim commented Sep 11, 2020

Thanks!

@cortesimone

This comment has been minimized.

Copy link

@cortesimone cortesimone commented Oct 7, 2020

👍

@biemster

This comment has been minimized.

Copy link

@biemster biemster commented Nov 23, 2020

pure magic!

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