I'd like to be able to run emacs on one computer:

server $ emacs --daemon

And then connect to it from another:

local $ emacsclient -c server

Is this possible? If so, how?

  • 1
    Just a hint: if you don't need to keep the remote Emacs session running and you just want to edit files on the remote host with Emacs then you might want to try out TRAMP, which lets you edit files over the network transparently. – paprika Sep 27 '14 at 20:04
  • @paprika I think OP wants to use a remote emacs configuration locally. Hence TRAMP might not be suitable. That is the reason I prefixed my answer with the disclaimer. – Vamsi Sep 27 '14 at 20:15
  • 3
    There has been a discussion on StackOverflow on the subject: stackoverflow.com/questions/12546722/… – Crash Coredump Sep 29 '14 at 12:25

You cannot use emacsclient to connect to an Emacs instance running on a remote computer. This client-server concept is related to (local) processes, not network nodes. However, you can use various network technologies to log in to the remote computer, attach to an emacs server running there and display the emacsclient's screen locally. Depending on the operating system that is used the networking could be done via SSH (terminal/X-Forwarding), VNC, RDP etc.

As some people pointed out, emacsclient actually does have an option to connect to the server via TCP. However, emacsclient was never meant to be used remotely, the TCP socket option is required for compatibility with non-UNIX systems (i.e. operating systems where UNIX domain sockets are not available, like Windows).

  • 4
    According to this post your statement is not exactly right. Could you be more specific?. – DJJ Aug 29 '15 at 19:56
  • 5
    @paprika: No, the authentication mechanism used for the TCP connection was designed specifically for the remote-access case. I pushed for the use of TCP on the Windows side so that the code is also useful on POSIX for remote connections, thus reducing Windows-specific code and adding functionality to the POSIX side. – Stefan Aug 1 '16 at 14:31

Probably not what you asked for but assuming you have ssh setup with X-forwarding, you could start emacsclient on the server and forward it to remote DISPLAY. (Disclaimer: code typed directly into webform)

 local> ssh server -f emacsclient -c --display=$DISPLAY
  • No, this is irrelevant to the question. – heroxbd Nov 22 '18 at 10:52

This may be not what you want but just in case see if it can help you some way.

I usually work inside a virtual machine bootstrapped with Vagrant, I have my ~/.emacs.d directory synced between my machine (local) and the virtual machine (remote) putting the following in the Vagrantfile file:

config.vm.synced_folder "~/.emacs.d", "/home/vagrant/.emacs.d"

Also, my Emacs config automatically starts a server on startup:

(require 'server)
(setq server-use-tcp t
      server-socket-dir "~/.emacs.d/server")
(unless (server-running-p)

So when I launch an Emacs server inside the virtual machine, I can connect to it with the following:

ssh -Y -i ~/.vagrant.d/insecure_private_key "<virtual machine hostname>" 'emacsclient -c -f ~/.emacs.d/server/server'

virtual machine hostname is the hostname of the virtual machine I have configured in my ~/.ssh/config:

Host <virtual machine hostname>
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /home/anler/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL
  ForwardAgent yes

Note: Before launching the Emacs server inside the virtual machine I check that the ~/.emacs.d/server/server file is not present (if it is I just remove it) because otherwise it won't work.

  • Just realized you are calling emacsclient in the remote server. In that case, you do not have to pass the server file explicitly as emacsclient will automatically connect to the first server it finds. – Vamsi Sep 27 '14 at 20:25
  • You don't need to specify the private key file in the command line if you have your identity file correctly set in your .ssh/config file. You just need to specify the Host. In doubt you can use the output of the command: vagrant ssh-config to set your ~/.ssh/config file. – Alexandro de Oliveira Jun 28 '17 at 23:04

emacsclient and TRAMP

Automatically open remote files in local emacs

I have had success with the first solution. The second seems to be simpler, I'm yet to try it out.

  • 6
    Answer looks interesting, but please don't just post links. Include some excerpts and snippets so the answer stands on its own feet. – Malabarba Sep 29 '14 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.