Search code examples
vimemacssshsftpfilezilla

Editing Files on a Remote server


I am wondering what the best way is to edit files on a remote linux server.

I have been using Emacs over ssh which has worked very well.

However, I also like the idea of copying files to my local machine and then editing them in the graphical Emacs application.

Are there advantages or drawbacks to editing over SSH or copying files and editing them locally? Is it better to copy files back and forth for editing using rsync or SFTP?


Solution

  • As can be seen from the posted answers, there are a number of different approaches to your requirement. Each has some advantages and disadvantages. Which suits you best will depend on your preferred workflow.

    Tramp

    Advantages

    • Good integration between local and remote work. It is all in one emacs and editing the remote files is not very different from working on local files.
    • Remote compilation. You can set things up so that when you compile a remote file, you can also use other emacs modes which assist in development, such as jumping to next error
    • Multi-hop. sometimes, it is not possible to connect directly to a remote server. You may need to first login to a bastion host before then logging into the target machine. Tramp can make this process pretty much automatic
    • Easy to use. Provided you have ssh setup with keys and use an ssh agent, accessing the remote files is no different to the local file

    Disadvantages

    • Requires a reliable internet connection
    • Can be a little tricky to get working initially, depending on your local and remote environments
    • Can be difficult to get exactly the right workflow sorted out if your workflow is a little complicated i.e. can be hard to get remote build tools integrated, especially if they are very site specific

    sshfs

    Advantages

    • This is a great way to go if you have non-emacs tools on your local machine which you also want to use on the files
    • No need to do any special config of emacs. As far as emacs is concerned, these are just local files

    disadvantages

    • Can be a bit unreliable if your internet connection is not stable
    • Effectiveness depends a bit on the remote file system
    • May not be acceptable to your company depending on their security policies/procedures

    Remote Emacs in Terminal

    Advantages

    • If you have a configured remote emacs, can be very easy.
    • Does not require local configured emacs and can work well from different platforms - just need a terminal and remote connection

    Disadvantages

    • Requires local and remote emacs config
    • Can sometimes be difficult to get all key bindings to work correctly under a terminal and ssh connection
    • No GUI support. Means to access menus you need to use the text based menus bound to F10, which can be problematic depending on terminal and ssh config

    Remote X11

    Advantages

    • Run remote GUI version of emacs using X11

      Disadvantages

    • Can be slow. Really need to use an X11 compression protocol to reduce X11 traffic

    • Requires remote emacs config setup
    • Requires good internet connectivity. Best on LAN rather than WAN

    Remote Desktop

    Advantages

    • Just run a rdp client and you see your remote system as if directly logged in. Lots of choices (perhaps too many) depending on your platform
    • Great if you just want to access your workstation remotely i.e. your owrk system which is all fully configured to support what you need

      Disadvantages

    • seems to be a fair amount of variation in quality of RDP type clients. Good if you want to go from Linux to Linux, but less flexible when involving mixed platforms

    • Generally requires remote software setup to support the rdp type session

    My personal choice is to use Tramp. I use to use the remote X11 stuff, but as fonts became more sophisticated under emacs, performance dropped significantly (especially when using font-lock). I've also used the sshfs sshfs solution, which works great when you have whole directory trees you want to work on or when you want to use local tools on groups of remote files outside of emacs etc.

    I use tramp for both remote files and when wanting to access local files as a different user. for example,, if I want to access a local config file which normally needs su/sudo access, you can use tramp to do this.