242
votes

I'm trying to use Sublime Text 2 as an editor when I SSH in to my work server, and I'm stumped. I found this http://urbangiraffe.com/2011/08/13/remote-editing-with-sublime-text-2/ (among many other posts) that looks like it might help, but I don't follow it exactly, particularly with what values I should put in for the remote variable in line 5. I set "/Users/path/to/local/copy" to my local root directory, but I don't know if that's right or if there's more to do. Any thoughts? I'm on OSX10.8

15
I've found it easier to use osxfuse and sshfs on my mac to locally mount remote directories and then edit via ST2.AGS
There is a popular ST2 plugin for sftp. Here is a further explanation of a system to which I believe AGS is referring: superuser.com/questions/134140/…. I had a problem with auto-load on login, and had to use a workaround login script made with Platypus. I also needed a better version of macfuse -- I'll see if I can find the link if you are interested.lawlist
With Snow Leopard (10.6.8), I needed an updated core for MacFuse (i.e., macfuse-core-10.5-2.1.9.dmg) -- here is the link to where I got it: blog.urbaninsight.com/2011/04/18/… If you are interested, that should save you a lot of headaches.lawlist
It wouldn't be live, and maybe less suitable for watching log files and stuff, but often setting up gitolite can be worth it. Just git pull and you have everything local to play with. Then again alot of people have fast internet these days and wouldn't feel the netwok lag... It all depends on your setup.user1115652

15 Answers

165
votes

There are three ways:

Also, in theory, you can install X11 on the remote server and run Sublime there over VNC or X11 forwarding, but there would be no point doing this.

103
votes

You can use rsub, which is inspired on TextMate's rmate. From the description:

Rsub is an implementation of TextMate 2's 'rmate' feature for Sublime Text 2, allowing files to be edited on a remote server using SSH port forwarding / tunnelling.

Here's a good tutorial on how to set it up properly.

67
votes

I'm on Windows and have used 4 methods: SFTP, WinSCP, Unison and Sublime Text on Linux with X11 forwarding over SSH to Windows (yes you can do this without messy configs and using a free tool).

The fourth way is the best if you can install software on your Linux machine.

The fourth way:

MobaXterm

  1. Install MobaXterm on Windows
  2. SSH to your Linux box from MobaXterm
  3. On your linux box, install Sublime Text 3. Here's how to on Ubuntu
  4. At the command prompt, start sublime with subl
  5. That's it! You now have sublime text running on Linux, but with its window running on your Windows desktop. This is possible because MobaXterm handles the X11 forwarding over SSH for you so you don't have to do anything funky to get it going. There might be a teeny amount of a delay, but your files will never be out of sync, because you're editing them right on the Linux machine.

Note: When invoking subl if it complains for a certain library - ensure you install them to successfully invoke sublimetext from mobaxterm.

If you can't install software on your Linux box, the best is Unison. Why?

  • It's free
  • It's fast
  • It's reliable and doesn't care which editor you use
  • You can create custom ignore lists

SFTP

Setup: Install the SFTP Sublime Text package. This package requires a license.

  1. Create a new folder
  2. Open it as a Sublime Text Project.
  3. In the sidebar, right click on the folder and select Map Remote.
  4. Edit the sftp-config.json file
  5. Right click the folder in step 1 select download.
  6. Work locally.

In the sftp-config, I usually set:

"upload_on_save": true,
"sync_down_on_open": true,

This, in addition to an SSH terminal to the machine gives me a fairly seamless remote editing experience.

WinSCP

  1. Install and run WinSCP
  2. Go to Preferences (Ctrl+Alt+P) and click on Transfer, then on Add. Name the preset.
  3. Set the transfer mode to binary (you don't want line conversions)
  4. Set file modification to "No change"
  5. Click the Edit button next to File Mask and setup your include and exclude files and folders (useful for when you have a .git/.svn folder present or you want to exclude build products from being synchronized).
  6. Click OK
  7. Connect to your remote server and navigate to the folder of interest
  8. Choose an empty folder on your local machine.
  9. Select your newly created Transfer settings preset.
  10. Finally, hit Ctrl+U (Commands > Keep remote directory up to date) and make sure "Synchronize on start" and "Update subdirectories" are checked.

From then on, WinSCP will keep your changes synchronized.

Work in the local folder using SublimeText. Just make sure that Sublime Text is set to guess the line endings from the file that is being edited.

Unison

I have found that if source tree is massive (around a few hundred MB with a deep hierarchy), then the WinSCP method described above might be a bit slow. You can get much better performance using Unison. The down side is that Unison is not automatic (you need to trigger it with a keypress) and requires a server component to be running on your linux machine. The up side is that the transfers are incredibly fast, it is very reliable and ignoring files, folders and extensions are incredibly easy to setup.

33
votes

As a follow up to @ubik's answer, here are the three simple (one-time) steps to get the 'subl' command working on your remote server:

  1. [Local] Install the rsub package in Sublime Text using the Sublime Package Manager
  2. [Local] Execute the following Bash command (this will set up an SSH tunnel, which is rsub's secret sauce):

    printf "Host *\n    RemoteForward 52698 127.0.0.1:52698" >> ~/.ssh/config
    
  3. [Server] Execute the following Bash command on your remote server (this will install the 'subl' shell command):

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

And voila! You're now using Sublime Text over SSH.

You can open an example file in Sublime Text from the server with something like subl ~/test.txt

12
votes

I am on MacOS, and the most convenient way for me is to using CyberDuck, which is free (also available for Windows). You can connect to your remote SSH file system and edit your file using your local editor. What CyberDuck does is download the file to a temporary place on your local OS and open it with your editor. Once you save the file, CyberDuck automatically upload it to your remote system. It seems transparent as if you are editing your remote file using your local editor. The developers of Cyberduck also make MountainDuck for mounting remote files systems.

8
votes

You can try something that I've been working on called 'xeno'. It will allow you to open up files/folders in Sublime Text (or any local editor really) over an SSH connection and automatically synchronize changes to the remote machine. It should work on almost all POSIX systems (I myself use it from OS X to connect to Linux machines and edit files in Sublime Text). It's free and open source. I'd love some feedback.

For more information: it's basically a Git/SSH mashup written in Python that allows you to edit files and folders on a remote machine in a local editor. You don't have to configure kernel modules, you don't need to have a persistent connection, it's all automatic, and it won't interfere with existing source control because it uses an out-of-worktree Git repository. Also, because it's built on Git, it's extremely fast and supports automatic merging of files that might be changing on both ends, unlike SSHFS/SFTP which will just clobber any files with older timestamps.

5
votes

You can use sftp to mount the remote directory on your location machine and then simply open the files using Sublime text the way you normally would.

To mount remote directory using sftp, enter the following on your Linux file manager;

sftp://user@remote_box.com:22/home/user/code_directory

It might seem slow depending on your internet speeds. But this worked for me.

5
votes

I know this is way old, but I have a really cool way of doing this that is worth sharing.

What is required in Conemu and WinSCP. These are simple instructions

  1. Open WinSCP.exe and login to my desired remote server (I have
    found that it's important to login before attaching ... ).

  2. In the preferences for WinSCP - two settings to change. Choose Explorer type interface and rather than Commander - so you don't see local files. Unless you want to (but that seems like it would suck here). Set up Sublime as your default editor.

  3. With ConEmu open, right click the tab bar and select the option Attach to.... A dialog box will open with your running applications. Choose, WinSCP and select OK. ConEmu will now have an open tab with WinSCP displaying your remote files.

  4. Right click on the WinSCP tab and choose New console.... When the dialog box opens, enter the path to the Sublime executable on your system. Before you press Start, In the box that says New console split select the radio button to right and set the percentage. I usually choose 75%, but you can customize this to your liking, and it can be changed later.

    1. Now you will see Sublime in the same window running to the right of WinSCP. In Sublime, from the View menu, choose Sidebar->Hide Sidebar, and bam, you now have remote files in exactly the same manner as you would locally - with a few caveats of course that comes with editing anything remotely. WinSCP is lightening fast though.

I have two monitors - left monitor display's Chrome browser, right monitor displays code editor. Also in ConEmu, I create another tab and ssh into the site I'm working on, so I can do things like run gulp or grunt remotely and also manipulate files from the command line. Seriously sped up development.

Here's a screenshot:

Setup Screenshot

5
votes

This is the easiest way to locally edit files which live on remote host where you have previously setup ssh to remote IP

# issue on local box

sudo apt-get install sshfs   # on local host install sshfs ( linux )

# on local box create secure mount of remote directory

export REMOTE_IP=107.170.58.249 # remote host IP

sshfs myremoteuserid@${REMOTE_IP}:/your/remote/dir  /your/local/dir # for example

Done !!!

Now on local host just start editing files ... when you list dir locally it may not list anything until you cd into subdir or list a specific file ... lazy loading ... this does not impact editing files

subl /your/local/dir/magnum_opus.go # local file edit using sublime text

so above is actually editing remote file at

/your/remote/dir/magnum_opus.go  # remote file on box $REMOTE_IP

For OSX or Windows see this tut from the kind folk over on Digital Ocean

4
votes

Another mac solution similar to osxfuse is to just use Transmit FTP client from Panic Software, which allows you to mount a remote folder as a local disk. It supports SFTP, which is very secure.

3
votes

I've been working on a project called GiySync. It still needs some work, but it's open source and I've been using it every day for a couple of years. I'm also working on a native OS X version I've called GitSyncApp

Right now it's OS X only but it should be easy to add support for Linux, and possibly Windows too.

It works by watching file system events and it uses to git to sync a project folder on your local machine and a server.

I tried the other solutions like osx fuse, Expand Drive, Transmit, several solutions that used rsync, etc. They all work 'OK' for small projects, but if you're working with a lot of code they did not work for me.

A lot of the file system options do caching to improve performance, which is fine, until it's not. Like if you're working with other people and someone else changes the files on the server.

I also ran into issues if I was on a flaky or slow network where I'd end up with empty files. Or file that didn't sync, then the caching got weird; hopefully you committed recently. Using git solves this problem because it checks each commit's integrity.

Two bonus features:

  1. You end up with a commit for every save. It's not super useful but if you ever have to go back in time you can.
  2. It works with any text editor.
0
votes

Depending on your exact needs, you may consider using BitTorrent Sync. Create a shared folder on your home PC and your work PC. Edit the files on your home PC (using Sublime or whatever you like), and they will sync automatically when you save. BitTorrent Sync does not rely on a central server storing the files (a la Dropbox and the like), so you should in theory be clear of any issues due to a third party storing sensitive info.

0
votes

A solution that worked great for me - edit locally on Mac, and have the file automatically synchronized to a remote machine

  1. Make sure you have passwordless login to the remote machine. If not, follow these steps http://osxdaily.com/2012/05/25/how-to-set-up-a-password-less-ssh-login/

  2. create a file in ~/Library/LaunchAgents/filesynchronizer.plist, with the following content:

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>filesynchronizer</string> <key>ProgramArguments</key> <array> <string>/usr/bin/rsync</string> <string>-avz</string> <string>/Users/USERNAME/SyncDirectory</string> <string>USERNAME@REMOTEMACHINE:~</string> </array> <key>WatchPaths</key> <array> <string>/Users/USERNAME/SyncDirectory</string> </array> </dict> </plist>

  3. In a terminal window run

    launchctl load ~/Library/LaunchAgents/filesynchronizer.plist

  4. That's it. Any changes to any files in ~/SyncDirectory will be synchronized to ~/SyncDirectory on the remote machine. Local changes will override any remote changes.

This creates a launchd job that monitors SyncDirectory, and whenever anything changes there runs rsync to synchronize the directory to the remote machine.

0
votes

lsyncd seem to be nice alternative to the sshfs approach. If you use "-delay 0" it works in real-time.

0
votes

Use FileZilla

This applies to Mac and Windows users (I use on Mac) . I've used several of the listed answers over the years and have found that FileZilla suits my needs well when editing files on a remote host that I have SSH access to. It's also quick to setup.

  • I config a new server connection
  • connect to the server
  • right click on the file I'd like to edit and select View/Edit.

This brings up my default editor (Sublime) but it will work with any editor you have installed.

  • Once I save the file, Filezilla automatically prompts me asking if I'd like to "Upload this file back to the server", I click "Yes" and then it's updated.