Вы находитесь на странице: 1из 7

19/08/2017 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 rsub
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
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\"" >> /etc/profile

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

34 Comments wrgms.com
1 Login

Sort by Newest
Recommend 14 Share

Join the discussion

LOG IN WITH

OR SIGN UP WITH DISQUS ?

Name

Johannes Bergs 5 months ago


Perfect, thank you very much!

I made a tutorial for the Raspberry Pi


https://wrgms.com/editing-files-remotely-via-ssh-on-sublimetext-3/ out of it: 1/7
19/08/2017 Editing files remotely via SSH on SublimeText 3

I made a tutorial for the Raspberry Pi out of it:


http://www.knight-of-pi.org...
Reply Share

Frank Perkins 7 months ago


For Mac users who can't get the rsub package installed locally on their workstation, do CMD-
SHIFT-P. That will bring up a text box in Sublime. Type Install Package, hit enter which then
installs the package manager. Now that package manager is installed, you can type rsub which
should show you the package to install (which will install your workstation version of rmate, I
know, confusing)

Hopefully that works. When you try on the server to do rsub file.txt and it doesn't work, ensure
that Sublime is already running on your workstation. Running rsub will not open sublime locally.
Reply Share

Chris Johannsen 10 months ago


Step 1 produces no result

EDIT: It must have already been installed, works swimmingly


1 Reply Share

CNek a year ago


Thanks buddy, works like a charm ;))
Now we can have best of the both world, Remote CLI power + seamless editing with my favorite
local text editor.
1 Reply Share

Yaeli Cohen a year ago


So I did everything but when I run the rsub command I get: ":no such file or directory". why is
that?
1 Reply Share

Gui Ambros Mod > Yaeli Cohen a year ago


Your /usr/local/bin is not in your path. Just edit your /etc/profile (or /etc/bash.bashrc or
equivalent in your shell) and you're done. See the edit above.
Reply Share

Yaeli Cohen > Gui Ambros a year ago


Thanks @Gui, but I still get the same error. Although when I check vi ~/.bashrc, I
can see the following lines:
export
PATH="/home/ycohen/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/gam
export
PATH=/home/ycohen/bin:/home/ycohen/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/

and if I run the rsub command directly from the directory it was saved, I also get
the same error.
Reply Share

Gui Ambros Mod > Yaeli Cohen a year ago


https://wrgms.com/editing-files-remotely-via-ssh-on-sublimetext-3/ 2/7
19/08/2017 Editing files remotely via SSH on SublimeText 3
Gui Ambros Mod > Yaeli Cohen a year ago
Run "ls -ls /usr/local/bin/rsub". Either rsub doesn't have the execute bit on
(that's the `chmod a+x above`), or you haven't downloaded the file to the
proper location under /usr/local/bin
Reply Share

Yaeli Cohen > Gui Ambros a year ago


ls -ls /usr/local/bin/rsub brings me -
root 9256 Jun 14 17:07 /usr/local/bin/rsub

means, the file is there. Again, if I run directly from /usr/local/bin/ the
command : rsub test - I get the same error message!
even when I just run: /usr/local/bin/rsub-- I get:
: No such file or directory
Reply Share

Gui Ambros Mod > Yaeli Cohen a year ago

What comes *before* "root 9256"? You didn't copy the most important part,
with the file permissions...

That's likely what's missing. It should be -rwxr-xr-x. To fix, use "chmod a+x
/usr/local/bin/rsub"
Reply Share

Yaeli Cohen > Gui Ambros a year ago


I did it...
12 -rwxrwxrwx 1 ycohen root 9544 Jun 14 19:20 /usr/local/bin/rsub
Reply Share

Yaeli Cohen > Yaeli Cohen a year ago


the command: "file rsub" brings:
"rsub: a /usr/bin/env bash\015 script, ASCII text executable, with CRLF
line terminators"
Reply Share

Gui Ambros Mod > Yaeli Cohen a year ago

Hmm. Do you /usr/bin/env and bash installed? Is this a linux or mac?

It seems your rsub is in the right path, and has right permissions (777 - a
bit too permissive, as anyone can write, but ok, wouldn't cause problems).
So the problem must be when executing rsub.
Reply Share

Yaeli Cohen > Gui Ambros a year ago


what do you mean by "/usr/bin/env " and bash installed? I run cygwin in
windows. thanks for all of your help! the sad thing that is was working in
the past.. I don't know why it is not working now
Reply Share

Gui Ambros Mod > Yaeli Cohen a year ago


https://wrgms.com/editing-files-remotely-via-ssh-on-sublimetext-3/ 3/7
19/08/2017 Editing files remotely
Gui Ambros via SSH on SublimeText 3
Yaeli Cohen

ah, that explains everything. In this case, you have quite a bit of homework
to do, to change the script to run with Cygwin under Windows.

You may try replacing the first line by /bin/bash and giving it a shot. It might
work.
Reply Share

Sinu Poonia a year ago


when I run: /usr/local//bin/rsub myfile.txt
giving me error:
connect_to localhost port 52698: failed.
Reply Share

Gui Ambros Mod > Sinu Poonia a year ago

You likely did not add the RemoteForward to your ".ssh/config" (step 2). Optionally, you
can append "-R 52698:localhost:52698" to your ssh command when connecting to the
remote machine, so establish the forward on port 52698.
Reply Share

Zega a year ago


Absolutely awesome, thanks for sharing!
1 Reply Share

Kevin Suttle 2 years ago


OR, if you're like me and used to typing `subl`, you can replace `rsub`.

```
sudo wget -O /usr/local/bin/subl https://raw.github.com/auro...
chmod a+x /usr/local/bin/subl
```
1 Reply Share

2 years ago
Hey guys,

It didn't really work for me either, but you have to follow the following instructions to make it
work:

If you have multiple servers you want this to work for, do the following as exactly shown here:

Host *
RemoteForward 52698 localhost:52698

You also have to connect to the remote server using:

ssh -R 52968:localhost:52968 yourservername.com

Also, make sure your sublime text console says the following:

[rsub] Server running on localhost:52698...

This did the trick for me, I hope it helps some hapless stranger as well!
https://wrgms.com/editing-files-remotely-via-ssh-on-sublimetext-3/ 4/7
19/08/2017 Editing files remotely via SSH on SublimeText 3
This did the trick for me, I hope it helps some hapless stranger as well!
Reply Share

Gui Ambros Mod > 2 years ago


You're repeating the same command twice. The "-R 52968:localhost:52968" is equivalent
to adding "RemoteForward" to your .ssh/config file.

It doesn't hurt, but you certainly don't need both.


Reply Share

Jay Killeen 2 years ago


Would love to get this to work.

Currently getting the error as follows after I ssh to the remote server. I ssh using `ssh -R
52968:localhost:52968 yourservername.com` as per your comments @Gui Ambros.

```bash
root@Dev:~# rsub test.txt
/usr/local/bin/rsub: connect: Connection refused
/usr/local/bin/rsub: line 322: /dev/tcp/localhost/52698: Connection refused
Unable to connect to TextMate on localhost:52698

```

Any ideas?

EDIT

My issue is I had already had a block in my SSH config for connecting to this remote server. I
adjusted my block to look like:

see more

1 Reply Share

Gui Ambros Mod > Jay Killeen 2 years ago


Glad it worked!
Reply Share

Agustin 2 years ago


Absolutely awesomee!!! Thank you, very much!!
1 Reply Share

Vasiliy Demchenko 2 years ago


I'm having a bit of issues getting this to work. I don't have superuser previleges so I just did
~/rsub instead of /usr/local/bin, but this isn't working... When I type rsub after I ssh into my
server, I'm told -bash: rsub: command not found. My .ssh/config has the remote forwarding lines.
Any idea what I've done wrong?
Reply Share

Wes Peters > Vasiliy Demchenko a year ago


Make your rsub executable: chmod 755 ~/rsub
https://wrgms.com/editing-files-remotely-via-ssh-on-sublimetext-3/ 5/7
19/08/2017 Editing files remotely via SSH on SublimeText 3

1 Reply Share

rwxpro 2 years ago


absolutely incredible.
1 Reply Share

Jason Howard 2 years ago


very cool Gui. thx!
1 Reply Share

ApplesAreNotOrange 2 years ago


OK. After Googling around I've managed to install the relevant items. However now it still
doesn't work.

The 'rsub' command just edits a file on my local machine. I don't understand how other people in
the comments had success with this. It just doesn't work.
Reply Share

Gui Ambros Mod > ApplesAreNotOrange 2 years ago


@ApplesAreNotOrange: what exactly is the problem you're facing?

If you installed rsub extension, and added the RemoteForward to your .ssh_config, the
expected behavior is to type 'rsub myfile.txt' on the remote server, and it'll open in
Sublime on your local machine.

If it doesn't work, confirm that you really added RemoteForward, and check the ssh log
by using 'ssh -vv ...'
Reply Share

ApplesAreNotOrange 2 years ago


I can't seem to get this working.

Some issues I'm having:

1) The key combination ctrl-shift-P doesn't do anything.

2) When I do run the Command Palette (which is what those keys are supposed to be mapped
to) there is no rsub.

What is the fix for this?

I'm really excited to get this working :-)

Thanks
Mike
Reply Share

Jacob Henke 2 years ago


You Sir just made my life a little bit better today. Thank you.
1 Reply Share

https://wrgms.com/editing-files-remotely-via-ssh-on-sublimetext-3/ 6/7
19/08/2017 Editing files remotely via SSH on SublimeText 3

Gui Ambros Mod 2 years ago


@Plandevida: yes, you need to be connected on the remote server. Just connect using ssh -R
52968:localhost:52968 yourservername.com and then run rsub file.txt. The remote file will
appear on your local Sublime Text. Very handy.
Reply Share

Plandevida 2 years ago


Hello,

Is not it necessary to make a ssh connection to the server?.


Reply Share

ALSO ON WRGMS.COM

The next chapter Synology's "secret" telnet password


2 comments 2 years ago 2 comments 5 years ago

AvatarGisele Pereira Funny. I left Wunderman in AvatarGui Ambros (Sorry for the delay; I guess you
July and started at Nokia in August... and so did must have solved it by now).Yes, on 2012/12/27
you! Almost.So we've got work anniversaries the password would be really c12-1b03. I

Reverse Engineering Synology's OpenSSH Voice Recognition on Embedded Devices -


1 comment 3 years ago Part 1
AvatarMike Petonic Good writeup. Thank you for 5 comments 3 years ago
this. I hate it when people gratuitously over AvatarLupita Citra Astari Any chance you know
engineer perfectly good unix utils. IBM did a why the accuracy in pocketsphinx, especially in
android ?

Written by

Gui Ambros

Maker, developer, ad:tech executive. Incurable optimist. Head of Operations & Technology @
WPP/Wunderman. I was there when the web was born. @GuiAmbros

Published 25 Nov 2014

https://wrgms.com/editing-files-remotely-via-ssh-on-sublimetext-3/ 7/7

Вам также может понравиться