Edit-text-files-over-SSH using a local text editor

8

4

I am working in various Linux and UNIX environments.

I'd like to elegantly solve the problem of editing remote configuration files over SSH. Instead of using terminal editors (nano), I'd like to open the file in a local text editor on my desktop (Sublime Text 2).

CyberDuck, WinSCP and various other SFTP apps can do this.

Using editors over X11 forwarding has also proven to be problematic. Also using archaic text editors like Vim or Emacs do not serve my needs well. They could do this, but I prefer using other text editing software.

Using ssh mounts (FUSE) are also problematic unless they can happen on the demand and triggered by the remote site.

So what I hope to achieve

  • Have a somekind of easily deployable shell script etc. which I can copy to remote server (let's call it mooedit)

  • I run mooedit command on the remote server of which I have connected over SSH connection

  • mooedit sends some kind of signal (over SSH( to my local desktop

  • On my local desktop this signal is captured and it determines 'a ha! moo wants to edit a file on server X in folder Y'

  • File is SFTP transfered to the local desktop (/tmp)

  • File is opened in a nice GUI text editor on the local desktop

  • When Save is pressed, the local desktop notices changes in the file and SFTP sends the resulting file back to the server

The question is:

  • What signaling mechanisms SSH provides for this?

  • Any other methods to trigger a local text editor for remote SSH file?

Mikko Ohtamaa

Posted 2011-09-27T07:14:57.533

Reputation: 1 790

1This is not a question. – P.T. – 2011-09-27T07:23:15.503

5The word is archaic, and they're not. Both Vim & Emacs can easily edit a remote file using builtin commands. – lornix – 2011-09-27T07:49:06.287

2@MikkoOhtamaa: your workflow is unclear: the server side tells your local editor that the server wants you to edit a file? – akira – 2011-09-27T07:56:13.793

@akira I reworded some sentences... clear now? – Mikko Ohtamaa – 2011-09-27T08:28:22.493

You say "CyberDuck, WinSCP and various other SFTP apps can do this." - so why not use one of them? – RedGrittyBrick – 2011-09-27T09:07:36.530

What's stopping you from using the archaic text editors? If a tool can do its job well, why not use it? – Jin – 2011-09-27T09:30:27.873

This should be something client-server program (server running on your desktop and mooedit as a client), then you'll be able to forward TCP port from remote server to your desktop, allowing client to communicate with server. I haven't seen such program, but, probably, something similar can be achieved with vim's server mode. – gelraen – 2011-09-27T09:36:31.813

1Calling vim and emacs archaic and wanting to use a gui text editor over ssh is a rant, not a question. – Bruno9779 – 2012-08-01T05:16:27.723

Answers

5

You can use rsub and rmate to edit remote files in your local Sublime Text over ssh.

You need to

  • install the rsub package in Sublime Text (with Package Manager)
  • forward port 52698 via ssh, use ssh -R 52698:localhost:52698 ... or set your config

    • create/edit ~/.ssh/config and chmod 600 ~/.ssh/config (to avoid a permissions problem)
    • add (replace SERVERNAME with your server, you can also use *):

Host SERVERNAME
  RemoteForward 52698 127.0.0.1:52698

  • connect to your server with ssh
  • install the rsub script on the remote machine:

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

Then you can do rsub file in the ssh session and it will open file in your local ST editor.

Works with ST2/ST3 and you can also sudo rsub file!

laktak

Posted 2011-09-27T07:14:57.533

Reputation: 2 223

1

This is an old question, but without a clear answer yet. However, you do not mention from which desktop environment you want to edit from? At one point you mention WinSCP; clearly Windows, on the other hand Cyberduck is a Mac program.

Assuming you work from a Mac; the venerable BBEdit, while not as 'sexy' as Sublime and before that TextMate, still has some features up its sleeve that the other editors don't have.

Like opening and writing files directly from and to ssh and ftp servers, from within the program. I've used this functionality since version 5 or so, which is now 13 years ago. Multiple lifetimes ago, and still not available in 'modern' editors.

http://www.barebones.com/products/bbedit/ (not affiliated in any way, just a happy user since 1993

axello

Posted 2011-09-27T07:14:57.533

Reputation: 111

1And on the Windows side I can remember being fond of UltraEdit, which has the same feature: opening a file over ssh/scp. – axello – 2013-03-24T22:03:48.287

0

I'd like to elegantly solve the problem of editing remote configuration files … Any other methods to trigger a local text editor for remote SSH file?

Use something like webmin. Either an existing module or create one for your purposes.


Update:

It is possible to make Apache serve a HTTPS page (via a back-end script) that shows the text file in a textarea and use (It's All Text to launch any local text editor. This obviously requires some care regarding security.

RedGrittyBrick

Posted 2011-09-27T07:14:57.533

Reputation: 70 632

Does webmin somehow solve the problem of launching a local text editor? – Mikko Ohtamaa – 2011-09-27T09:33:43.607

@MIkko: Yes, insofar as you can locally (in your local web-browser) edit the contents of a remote text-file. If you don't consider a local browser's GUI textarea widget (commonly used for editing text) or dedicated set of other widgets, a suitable "text editor", you'll have to look elsewhere. – RedGrittyBrick – 2011-09-27T10:05:46.627

I wish to use real editor, not textarea as it is crap for any serious development. Thus, the question in the first place. – Mikko Ohtamaa – 2012-08-01T05:43:29.813

@Mikko: As I said, Try something like Its All Text or Text Editor Anywhere, It allows you to use your favourite editor to edit textarea data. I use vim to edit text in textareas on web pages.

– RedGrittyBrick – 2012-08-01T09:40:10.897

This sounds like a terrible security nightmare. – nathancahill – 2013-02-14T17:02:00.630