80

I am connecting to remote server using "mRemoteNG" and want to open remote server files in my local sublime text editor. During my research, I found this relevant blog https://wrgms.com/editing-files-remotely-via-ssh-on-sublimetext-3/ and followed the instructions but it is not working for me. Does, anybody know how can I open remote files in my Sublime?

Raman Balyan
  • 983
  • 2
  • 16
  • 32
  • I found the answer in this http://stackoverflow.com/questions/15958056/how-to-use-sublime-over-ssh I implemented the tenth answer (winscp part) of this question.. – Raman Balyan May 27 '16 at 07:08

4 Answers4

193

On server

Install rsub:

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

On local

  1. Install rsub Sublime3 package:

On Sublime Text 3, open Package Manager (Ctrl-Shift-P on Linux/Win, Cmd-Shift-P on Mac, Install Package), and search for rsub and install it

  1. Open command line and connect to remote server:

ssh -R 52698:localhost:52698 server_user@server_address

  1. after connect to server run this command on server:

rsub path_to_file/file.txt

  1. File opening auto in Sublime 3

As of today (2018/09/05) you should use : https://github.com/randy3k/RemoteSubl because you can find it in packagecontrol.io while "rsub" is not present.

Smart Manoj
  • 5,230
  • 4
  • 34
  • 59
Emamie
  • 2,792
  • 1
  • 19
  • 17
  • 1
    on local,you can use git client to ssh the remote server.the git client ships with ssh client.https://git-scm.com/download/win – sixsixsix Jun 30 '17 at 07:29
  • there is no something more automatic ? – stackdave Jul 25 '17 at 18:04
  • 30
    Managed to get this working, but this is only good for opening individual files? Is there a way to do something like subl * to open up all directories and files for a project in Sublime? – ugotchi Sep 13 '17 at 11:27
  • 1
    My [blog article](https://random.ac/cess/2017/07/03/workflow-magic-or-so-it-seems/) about `rsub/rmate` includes details/links for setting up `rsub/rmate` on both macOS and Windows. – Ville Nov 07 '17 at 07:39
  • 3
    after doing the last step, on ST3, the file does not open automagically. Is there something I am missing here ? – qre0ct Nov 27 '17 at 11:45
  • 8
    What error you get? `connect_to localhost port 52698: failed.`? If so, you should open "Sublime Text" first then execute step 3. – igauravsehrawat Jan 04 '18 at 16:05
  • 1
    @h.emamie I get "No command 'rsub' found" on the server, Am I missing something here? – Angelo Jul 10 '18 at 08:49
  • 1
    If you get the `connect_to localhost port 52698: failed` message even though you did step 3, check to make sure that the port forwarding was successful. If it fails the ssh may still go through but warn that `remote port forwarding failed for listen port 52698`, if that port is not open. – Silenced Temporarily Aug 02 '18 at 19:14
  • 4
    Add `RemoteForward 52698 127.0.0.1:52698` to the .ssh/config file in local machine should solve the connection fail problem caused by port forwarding – Kelvin Sep 15 '18 at 06:43
  • 2
    I cannot install anything on the server, is there another solution? – Herman Toothrot Nov 14 '18 at 16:33
  • RemoteSubl works nicely even on Windows (using Putty). Thank you! – hashchange Apr 25 '20 at 13:56
  • 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` – ericksho Jun 11 '20 at 19:31
  • Does this work for a HPC where you don't have root priviliges? It looks like you permission you are unlikely to have in such a case. – Kvothe Feb 02 '21 at 18:52
  • @Herman, I don't know what not being able to install anything means, but if it just means that you can't install to /usr/local/bin/rsub but you can to some private directory than that is no problem. I just installed it somewhere else and added that directory to the path and it works fine I think. – Kvothe Feb 03 '21 at 10:37
  • So does Sublime text always have to already be open? Is there any work around to make it start when using rsub (or rmate if not renamed) remotely? – Kvothe Feb 03 '21 at 10:39
  • Another thing that might be useful for others, if ST3 is open on server, rsub opens the file on server. Simply, closing ST3 on server fixed the issue, and opened the file on client. – Prefect Jun 16 '21 at 06:44
  • @ugotchi you can try `sublime *.py */.py`. It will open the files but it won't show the directory structure. – irene Feb 15 '23 at 06:16
33

On macOS, one option is to install FUSE for macOS and use sshfs to mount a remote directory:

mkdir local_dir
sshfs remote_user@remote_host:remote_dir/ local_dir

Some caveats apply with mounting network volumes, so YMMV.

tuomassalo
  • 8,717
  • 6
  • 48
  • 50
  • 2
    could you describe the caveats please? – fersarr Jan 19 '18 at 11:24
  • 5
    @fersarr I don't remember which problems I ran into with this setup, but in general with network mounts one might encounter e.g.: lagginess even with a moderate network connection; editor not being able to watch for changes in files; handling network disruptions.. – tuomassalo Jan 19 '18 at 12:29
  • 1
    That's not limited to macOS though – Adrien Leravat May 10 '18 at 11:33
  • 2
    this is the easiest answer ... no need for any subl plugin ... if you are running a linux laptop no need to install FUSE its baked in – Scott Stensland Aug 19 '19 at 00:32
14

You can use these plugins;

Sublime SFTP

sublime FTPSync

baijunyao
  • 682
  • 5
  • 7
1

Base on this.

Step by step:

  • 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
  • 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
  • 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.

Bashid
  • 433
  • 5
  • 15