reddit / emacs

connect `emacsclient` with an emacs daemon that is running in a remote machine

crazyjoker96 · 2022-09-04 17:07
I search around all the afternoon, and I did not find a solution for this, and I found only alternative where I'm not interested in. I'm working with emacs for a few years now and I'm tired to run it in ssh inside the terminal, because in a GUI mode for my disability it is more nice and helpful. Now, I'm looking for a solution to use in my local machine the emacs daemon that is running in my remote machine. I tried to run the `emacs --daemon` on the remote machine with the following configuration ``` (require 'server) (setq server-use-tcp t server-host "<IP>" server-socket-dir "~/.emacs.d/server") (unless (server-running-p) (server-start)) ``` and after I'm copy the `.emacs.d/server/server` in my local machine and run `emacsclient -c` but I have the following result ``` ➜ ~ emacsclient -c emacsclient: can't find socket; have you started the server? emacsclient: To start the server in Emacs, type "M-x server-start". emacsclient: connected to remote socket at <IP> Waiting for Emacs... *ERROR*: Could not open file: /dev/ttys000 ``` There are any suggestion and update guide on how to make this configuration working?
sickofthisshit · 2022-09-04 17:17
A couple things are not clear to me: are you trying to invoke emacsclient to just open a window for manual interaction? Or is it being invoked by a tool referring to a file? If what you want is for the remote Emacs to have a new GUI window open on your local machine, then you might want to have a small script which invokes emacsclient *on the remote machine* and "$DISPLAY" set to point back to the SSH tunnel and the emacsclient argument includes the Elisp to open a frame there. Otherwise, you are going to have to bridge the gap that your two machines have different file systems.
JohnathanDee · 2022-09-04 17:20
Ah yah it's not really supposed to work that way. Yes it's client-server architecture, but intended for running both locally as they communicate via unix sockets, not via an internet protocol. To do what you want, `emacsclient` and the remote server must be configured to communicate over TCP for that to work, and the results are less than spectacular. If you have an amazing internet connection, you might pull it off, but honestly you'd probably have better luck using X-forwarding over SSH. Or just use Tramp
crazyjoker96 · 2022-09-04 17:26
\>To do what you want, emacsclient and the remote server must be configured to communicate over TCP for that to work, and the results are less than spectacular. There are some example of this?
BettaGeorge · 2022-09-04 17:44
As others have already said, emacs is at a very basic level not designed for this, so even if you do get it working, you'll wish you hadn't. Is there any reason to not just use tramp? It does everything I want from a remote system.
crazyjoker96 · 2022-09-04 18:06
mh! this solution sound interesting, there are some example out there?
crazyjoker96 · 2022-09-04 18:13
Maybe I did not evaluate with a lot of attention tramp? I was trying it and it works fine but when I run a change and it did not syncronize the change with my remote machine I just give up! &#x200B; There is some basic introduction to this mode?
samsjj · 2022-09-04 18:50
If you have admin rights on the remote machine you can install vncserver and use vnc viewer on the local machine. RealVNC is good
plm314 · 2022-09-04 20:20
If you already have an emacs daemon running on the remote then a simple ssh remote -Y emacsclient -c will suffice. If not, perhaps start a daemon (or, if it is a once only test try: ssh remote -Y emacs, though I don’t recommend depending on the X connection for your work, so first try ssh remote emacs -daemon and then the emacsclient -c)
sickofthisshit · 2022-09-04 20:39
Protip: `-Y` is less secure, despite the confusing documentation and internet advice. Unfortunately, to get it to work with `-X` you have to do some extra work to authorize the remote Emacs to access your display.
aaronemassey · 2022-09-04 20:43
My recommendation is to use terminal emacs + mosh + term-keys.el for remote development.
xtifr · 2022-09-04 20:53
There's a manual for Tramp included with Emacs. It's not part of the main Emacs manual, but you can find it by pressing `C-h i` and then searching for Tramp.
plm314 · 2022-09-04 21:17
Thanks. Any forwarding increases the attack surface by a lot. I use terminals, occasionally VNC/DCV, and once in a blue moon -X or -Y depending on the machines and application. To the OP: if you don’t trust the remote system, and don’t have full control and a good configuration of the local system, then probably don’t try either of the -Y or -X options.
mee8Ti6Eit · 2022-09-04 22:56
> even if you do get it working I don't think this works at all. IIRC, the emacsclient socket is used only to initiate the session. After that, the main emacs process takes over, either taking over the tty or spawning a new X window. The socket IS NOT used for the session (e.g., keystrokes are not sent over the socket). So emacsclient fundamentally doesn't work remotely. You should SSH into the remote machine and then run emacsclient.
mee8Ti6Eit · 2022-09-04 23:00
> To do what you want, emacsclient and the remote server must be configured to communicate over TCP for that to work, and the results are less than spectacular. I don't think this works at all. The emacsclient socket is used only to initiate the session. After that, the main emacs process takes over, either taking over the tty or spawning a new X window. The socket IS NOT used for the session (e.g., keystrokes are not sent over the socket, display updates are not sent over the socket). Basically, the emacs server supports only a single APi request: start editing this file. Check `server-process-filter`. So emacsclient fundamentally doesn't work remotely. You should SSH into the remote machine and then run emacsclient.
czernebog · 2022-09-04 23:38
This is correct. I did at one point in recent memory get a local emacsclient to talk to a remote Emacs server over TCP, and it opened a frame on the machine running the Emacs server.
JohnathanDee · 2022-09-05 00:43
Agreed. X-forwarding is the way to go because SSH doesn't have anything else to do.
DrReadIt · 2022-09-05 10:09
Shit works for me, flawlessly.
jtr3322 · 2022-09-05 12:53
Hi. I didn't read all the comments, but I wanted to throw in my solution. I run emacs at work using tramp. It connects to my file server (a raspberry pi back at home) and works great. My agenda in org mode loads all the files remotely. Bonus: when I want to attach a local file to my server I use org attach on orgmode for the local attachment and it saves it to the server in seconds. Only thing you need to watch out for is to work with less files or decrease the cycles emacs do with indexing or you'll have slow loading times. Depends on your load.
eli-zaretskii · 2022-09-05 16:10
Reading all the answers here, one wonders whether people bother reading the manual before answering... To the OP: Yes, this should be possible. Read the description of the `-T` (a.k.a. `--tramp-prefix`) command-line argument in the "emacsclient Options" node of the Emacs manual. It explains how to set this up and gives an example. Caveat: using TCP sockets between 2 machines is less secure, since the Emacs client-server protocol isn't encrypted.
Thaodan · 2022-09-11 15:44
I used to forward the socket with Ssh then it would work.
Thaodan · 2022-09-11 15:46
It depends if you just want to open a file or go into an existing session. The latter sometimes is more important than opening a single file.