HACKER Q&A
📣 E_Evan

Best practices for editing remote code locally?


Working on a remote codebase from a local computer accessible via ssh, what’s the best/easiest way to write, edit and test code?


  👤 JamesMcMinn Accepted Answer ✓
VS Code + The Remote SSH extension is a remarkable solution to developing code (not just editing!) on a remote machine.

When Covid hit and my main work machine was still a desktop, I worked from my home using VS Code and the remote plugin. This lasted for 18 months, and the only time I ever had an issue was due to a power outage in the office. Data, code (everything, really) lived on my work desktop that was sat in an empty office while I was at home.

There's no latency, the terminal opens as if you were on the remote machine, and ports are automatically forwarded. It runs code, tests, etc. all on the remote machine.

If there's a better solution out there it's almost certainly down to IDE preference.


👤 jve
Visual Studio Code Remote SSH? https://code.visualstudio.com/docs/remote/ssh it will however install VS Code Server on target machine. So, for permanent development it is good. Not great if you only want to change one config file in PROD environment.

> The Visual Studio Code Remote - SSH extension allows you to open a remote folder on any remote machine, virtual machine, or container with a running SSH server and take full advantage of VS Code's feature set. Once connected to a server, you can interact with files and folders anywhere on the remote filesystem.

Once connected, even terminal runs on remote host. Moreover you get to forward ports from remote host to local using VSCode UI.


👤 rank0
Don’t overthink it!

Keep it traditional baby all you need is vim and tmux.

The initial learning curve for these sorts of cli apps is a bit steep, but it’s a lifelong skill and easily learnable for any competent developer.

Writing code is 1000x more difficult than learning vim philosophy and memorizing some key bindings.

Since I do all my editing in terminal, I just have a portable environment in a git repo. It has an install script that soft links all my scripts and config files to the appropriate locations. My work environment comes with me everywhere!


👤 jitl
- My preference is to run my IDE or editor on the remote, and only run a thin client (RDP > X11, mosh > ssh) on the local. Because I’m happy in nvim, I would just install nvim and my dot files on the remote and access it via mosh/tmux. But this is not for everyone; if you’re doing Java an IDE is a must. So, try RDP or X11 forwarding for those.

If you can’t install software on the remote (or you can’t install a GUI stack), read on:

- Most IDEs like Intellij can be configured to do all their execution on a remote over SSH. I worked this way using PyCharm for my student job at UC Berkeley in 2012 and it worked great.

- SSHFS is okay but not great because of slowness. It’s fine for editing but sucks for running interpreted code locally. So, try to do all execution on the remote.

- VS Code has handy support of editing on a remote without needing SSHFS

- if permitted, a two-way file sync solution like Unison or Mutagen gets you native file system performance on the local. We used Unison for local editing with remote execution for Airbnb’s Ruby codebase for several years (2015-2018+). But it’s more fiddly to work with than SSHFS.


👤 chrisshroba
Can you elaborate on the situation? Personally I’d just keep a local copy of the code and then use git or rsync to sync the remote system to my local version whenever I’m ready to.

If it’s just small things like a quick config change or something, I’d personally just ssh in and modify with vim.

For testing, you probably shouldn’t be doing that on a production system, perhaps you could stick the code in a docker container and run the tests locally? If you’re familiar with docker, that shouldn’t take more than a couple hours to set up, and likely much less time than that if the project isn’t super complex.

Feel free to explain your use case further and I bet people could give more targeted advice!


👤 Y-bar
If you are on a Mac, using Transmit (https://panic.com/transmit/) you can mount a SSH/SFTP connection as a local disk and edit there in your editor of choice.

👤 paskozdilar
Since I like my local development environment, I mostly use `sshfs`.

It mounts a remote directory onto a local directory and lets you access remote files as if they're local, with slight latency. Then you can use whatever tools you use locally to edit/compile/run the software.


👤 aardvark179
Emacs tramp can edit files over ssh very nicely, along with other things like editing files as another user through sudo.

👤 globular-toast
Best practice is to write, test, build etc. locally using a version control system and deploy a tested bundle to the remote computer when ready.

Editing code directly on a remote server is something I used to do in the 90s before git and other tools made good practices much easier.


👤 blunte
I have recently built a dev server for myself using https://github.com/coder/code-server (VS Code in the browser, hosted on the remote server). With very little effort, you get an always-on dev environment with built in terminal so you don't even have to ssh in if you don't feel like it (if you're happy working within the editor's terminal window pane).

As a bonus, I also setup openvnc, cloudflared (DNS over HTTPS), and pihole. And tmux and mosh of course.

With this setup I can even do my work from an iPad (once you get the VPN setup correctly).

It's nice to be able to reboot my laptop without losing my place in my work.


👤 ChuckMcM
That the answer isn't "well you just tunnel X11 and bring up your regular work flow." is interesting to me. Because for literally decades this was a completely solved problem.

That it is a question always makes me wonder what was in it for the purveyor's of OS software to make this so impossible to do.


👤 emacs28
I use Emacs but don't enjoy the latency of using a remote Emacs session or locally using tramp. Recently my solution is to edit locally, then whenever I need to run the codebase on the remote machine I wrap the run command in a script with two rsync commands. First (using rsync) it will sync the remote codebase with any local changes. Then when the remote command completes, any relevant result files I want to analyze locally after are synced back to the local machine (using rsync). Rsync is very flexible and has lots of options such as ignore filters.

👤 michaelt
I've seen some of my colleagues running 'Visual Studio Code remote' [1] which allowed them to edit source code on a remote machine with a native text editor; run the code and tests remotely with a local interactive debugger, and so on.

I haven't tried it myself, but they seemed to like it.

[1] https://code.visualstudio.com/docs/remote/ssh


👤 drewg123
Old unix tools like vi or emacs and "make" were built when nearly all computers were remote, and work really well for this. Especially when combined with something like "screen" to preserve multiple sessions..

👤 yabones
Ideally, just use a text editor on the remote machine such as Vim, Nano, or Emacs.

If you want a full IDE, or just your set of extensions & tools, you could install it there and use X11 forwarding like so:

    ssh -X me@box /usr/bin/code
I believe VSCode also has a remote mode, but I haven't used it.

👤 rvieira
Couple of solutions (some already mentioned):

- SSH remote editing (e.g. ssh + remote Emacs/Vim)

- VS Code + Remote SSH

- Emacs TRAMP

- JetBrains Gateway

- mutagen? (I haven't played with it, I'm not sure if it's suitable for your case)


👤 maicro
While there are plenty of other more powerful solutions suggested here, I prefer my fairly light weight option - WinSCP connecting to the remote server over SFTP, then opening the files I want to change in my preferred editor (Sublime Text). WinSCP handles uploading file changes to the remote server automatically; there might also be a way to trigger actions on upload, but that gets into specifics of how your codebase is setup / what you need to run to test changes. Bonuses of using WinSCP are drag-and-drop file transfers, and a pretty thorough site manager (/address book / credential storage / login manager, whatever you want to call it).

👤 hokumguru
Nova (https://nova.app) has a remote file browser + terminal that I've found work surprisingly well, it has the advantage of being Mac native as well!

👤 jpn
For Sublime Text users, SFTP is super useful:

https://codexns.io/products/sftp_for_sublime


👤 jraph
Kate is a fantastic code editor (if you don't need an IDE, though it gained support for LSP) and is able to edit files over SFTP (without having to mount anything with SSHFS, which would be less efficient anyway because Kate would not be aware it is editing a distant file this way). KDevelop can probably too, and it is an IDE. I'd try QtCreator too.

In the same vain, Gedit and its forks can do this to if that's your cup of tea.

or vim, emacs or nano through a traditional SSH session :-)


👤 zamalek
The first few minutes of this video[1] shows a typical approach using containers with TTY editors. If you use VSCode then you can take a look at "Visual Studio Code Remote - Containers", if you use JetBrains products then take a look at "Gateway" or "Projector".

[1]: https://www.youtube.com/watch?v=XOOBL3bhFHs


👤 beagle3
A coworker of mine works locally in $editor_of_choice (which is VS for C#, VSC for most others, some weird DB system for SQL), and has a window of Beyond Compare always on top; that allows him to see what files are different locally/remote and push them (he compiles/tests remotely). Might work for you too.

Another useful option, depends on your specifics, is the Plan 9 "cpu" command[0], available for Linux at [1]. It takes an unusual approach, which is IMHO superior for embedded machines, but which may work well for some other use cases (though not all).

[0] https://fosdem.org/2022/schedule/event/plan_9_cpu_cmd/

[1] https://pkg.go.dev/github.com/u-root/cpu/cmds/cpu


👤 Jaruzel
As a Windows guy who uses Linux on servers only, I used to install samba onto the servers and map a drive to that (over a hardware VPN). These were servers that I had full control over. I'd use an IDE on Windows and directly edit the code. Save, reload in Browser, see changes.

Now due to changes in where I host my stuff, I can't do that anymore, and I'm struggling to find a simple solution. I have recently discovered that WinSCP can 'edit' a file by pulling it locally into a temp folder, opening your IDE of choice, and then auto resyncing the file to remote server whenever the local copy changes. It's OK as a workflow, but not as flexible as having an open folder to just drop stuff into.

I know the latest version of Dreamweaver has the same sort of thing built in which would be better... But as a hobbyist, I just can't afford that.


👤 karmakaze
JetBrains IDEs (some/all?) have a menu option Tools->Deployment->Configuration where you can specify remotes via ssh and sync via rsync.

I only use one-way sync from local to remote though 2-way is also supported. I simply git fetch/checkout on remote first, then git fetch/checkout the same branch on local. You can set up a local script to do both together.

Once in that state, any locally changed files get sent to remote faster than I can switch focus to the terminal and enter a command/enter.

There's also a Remote Development (beta) feature that essentially runs the JetBrains IDE headless on the remote and a local 'display server'. Performance largely depends on the performance of remote and network bandwidth much more than the Deployment Configuration rsync method.


👤 kkfx
If it's a serious, non casual/on-the-spot usage work on a local copy and sync it, it does not matter if it's a repo or something you rsync/unison that's the top performant, comfortable and safe way. Networked computing does not means do anything via network and desktops are not despite all tentative in this direction "endpoint" or modern dumb terminal of a remote mainframe-alike server.

If it's casual edit you need to do ssh is enough, via TRAMP (who can work on various protocols transparently, not just ssh) if you are in Emacs or perhaps with sshfs for an editor-neutral solution (knowing it does not offer a full POSIX fs).

For testing again ssh is a very common and friendly option.


👤 throwaway71271
local emacs + TRAMP works really nice

👤 ryangittins
An important tool to find or write is one which will automatically sync your changes made locally (from the comfort of your IDE of choice) to the remote machine every time you save it.

You want to be able to iterate quickly and not have to manually run a command every time you want to sync changes. It's also a huge help to tie this into a way to run the unit tests for files which have been changed so you can get feedback and quickly as possible.

Ideally, everything should be made so automatic that you barely even notice the code isn't running on your machine.


👤 warent
I host my code on a server because the docker-compose required to run the whole stack takes more memory than my macbook can afford (Docker is very memory hungry on Mac and at the moment I "only" have 16gb).

Basically just hosting an SMB server and then mounting it as a volume on my work computer. So it looks like a normal folder/directory but it's over a network.

You can also get fancy and configure your NAT to only allow this over local connections, then spin up a VPN. In this way I'm able to securely work in my server from anywhere.


👤 dezmou
I am used to work with "remote - SSH" vs-code extension with a remote server and it work like a charm, you can't tell that you are not at home. I do all my coding this way BTW

👤 _wldu
The most secure way to do this would be to run Qubes OS [1] and use a qube dedicated solely to your software development. You can do your random web browsing and other risky Internet based things (such as email) in other qubes (not your dev qube). IMPO, isolation is really the best defense we have against modern attacks (supply chain, water hole attacks, whale phishing, etc.)

Hope this helps.

[1] - https://www.qubes-os.org/


👤 IE6
Is it possible to work locally doing all the fun stuff in a kind of "stage" env and then push via scp or some other ssh based mechanism to the remote?

👤 DaOne256
I wish that VS Code had a TUI (Text User Interface) with mouse support like mc to run it in a SSH console.

Vim, emacs or nano are no alternatives for me as I need to browse large C/C++ legacy codebases and some newer JS. And I rely much on CTRL+mouseclick.

Does anyone know a VS Code extension to use it in a shell instead of the desktop GUI?


👤 pbsds
Many editors support the rmate protocol, enabling you to open a remote file from a ssh session in your local editor.

👤 leros
If you have fast internet, I like X forwarding. I used to run IntelliJ on my work computer in the office and render the window on my home computer. Everything is running on my beefy work computer and is local in the office. If you can SSH you can add a few parameters to the SSH command to do X forwarding.

👤 Aperocky
vim with good amount of plugin is my go to.

My vim setup looks like atom in terms of interface: https://github.com/Aperocky/unix-setup/blob/master/.vimrc

Very easy to setup, just add the .vimrc file and run the git clone commands after setting up pathogen (package interface). This setup is pretty nice to edit ts/js/py/rb and C family of languages (add plugin specific to language when you need it). This isn't just for SSH, this is my goto in local as well, but it behaves exactly the same either remote or local.

This doesn't really work for any of the JVM languages however, those you probably want an IDE.. I tried my best in vim and it just don't work.


👤 bayindirh
I personally prefer Eclipse Remote Development Tools, which can either work via a dedicated daemon, or SSH.

👤 hprotagonist
i use emacs+TRAMP for vcs, mosh for remote terminal presence, and vscode+ssh or jetbrains gateway for dev.

👤 ris
This is (partly) why I started using KDE's Kate as my editor. File access is all through a virtual io layer, which supports sftp amongst many others. And I've never switched away from it - long after that project - because it's "good enough".

👤 andi999
What is wrong with using ssh -X and the do the same workflow you would do if you were on premise?

👤 dncornholio
I think we have a XY problem[1] here. Could you explain more details please? Writing, editing and testing on a remote machine seems like a bad practise.

[1]: https://xyproblem.info/


👤 honkler
`sshfs`, to mount a remote directory locally, then edit it with whatever tools you want.

👤 ilovecaching
The answer is so incredibly simple. SSH to the machine. Start vim or emacs. The end.

👤 jesterson
Using Coda 2 for many years already. Tried many other apps, but nothing comes close in terms of convenience and speed.

Tried their new editor Nova and was utterly disappointed. The whole thing is practically unusable. Or I am too old :)


👤 qsort
git?

If it's impossible to clone the environment for some reason, VS Code and JetBrains IDEs have remote support. Even vim can edit remote files.

It's not clear from your question what exactly is your problem, would you be willing to elaborate?


👤 ghishadow
Lapce (lapce.dev) remote development is pretty good, I wish Sublime Text has something like that, Lapce also has good integration with WSL. I tried Vscode but it doesn't work on Firefox level codebase.

👤 barefeg
Has anyone tried something like codespaces? I use vscode with either ssh, container dev, or both. But I feel it’s sometimes a bit slow. I’m wondering if a managed service could provide a better ux

👤 lfkdev
VS Code with remote ssh. This is actually my default workflow. I always rent a small vps and work/code on it over the remote ssh plugin. Worke perfectly

👤 atoav
For my www-data directories mounting them via sshfs on boot turned out to be a good solution.

For one-off stuff, raspbery pis, etc I tend to use sublime text and remoteSubl


👤 yangosoft
Try NetBeans, works quite well for remote projects using SSH.

Also found vscode + remote SSH very useful, as others users recommended.


👤 olekenneth
Use Emacs. You have something called tramp. Which can connect with sftp/scp/more to remote server.

👤 gotts
local code editing + rsync command that you run manually or automatically(e.g. using fswatch)

👤 ipaddr
You can still use dreamweaver mx, 7, etc.

You can use intellj products

Sublime ssh plugins, vs plugins

On android you can use AWD - editor


👤 martopix
I use Atom with an extension called ftp-remote-edit that works quite nicely.

👤 tpoacher
ssh + byobu + your favourite terminal editor.

bonus: collaborative coding by attaching to the same byobu session as your colleague


👤 rubicks
sshfs + $EDITOR

👤 rramadass
((GNU Screen+dvtm) or tmux) + vim + ssh

👤 unmole
Mosh + Tmux + Vim

👤 louissan
vi?

👤 mjh2539
emacs-nox

👤 cudgy
git clone

👤 ddaalluu2
Idk if hn is psychic but I just thought how great it could be if I could use my workstation in the next room as a host for writing code on my phone. Because I can take my phone where I'm comfortable and hold it where I please and lay on the sofa, relaxed as opposed to sitting on a chair where blood flow to my feet is semi cut off. (How I would love one of those walk-apparatuses Linus Torvalds has).

So sorry no answer, but also interested.

I remember there were a few online code editors, but trust is an issue and they cost extra.

The way you intend to use it though... I have done it in my PHP days, long ago. It's not good practice. Version control systems are a good invention, even if you sometimes just need a quick fix. Edit locally, push to repo, auto build or manually.


👤 sillycube
I use atom and remote ftp plugin. With this setup, I can connect to my dev server with my local machines.

1 machine is Macbook air at home, another is windows in the office


👤 evocatus
SSH in and use a terminal editor. Or, create an SMB/CIFS share and mount it locally.