Skip to content

Instantly share code, notes, and snippets.

@RhubarbSin
Last active November 28, 2024 20:45
Show Gist options
  • Save RhubarbSin/3e66d067e0ca7702e9c1278258a81b1c to your computer and use it in GitHub Desktop.
Save RhubarbSin/3e66d067e0ca7702e9c1278258a81b1c to your computer and use it in GitHub Desktop.
Use SSH to forward local Emacs server socket to remote host so emacsclient on remote host can open buffers in Emacs on local host
  • Get path of remote socket: execute on remote host
    emacs --batch --execute "(progn
            (require 'server)
            (princ (expand-file-name \"remote\" server-socket-dir)
                   #'external-debugging-output))"
        
  • Get path of local socket: execute on local host
    emacs --batch --execute "(progn
            (require 'server)
            (princ (expand-file-name server-name server-socket-dir)
                   #'external-debugging-output))"
        
  • Create SSH connection: execute on local host
    ssh -v -N -R /run/user/1000/emacs/remote:/var/folders/gk/rnw58qsx7t30_4rsndpzwww80000gn/T/emacs501/server remotehost
        
  • Launch emacsclient: execute on remote host
    emacsclient -s remote -T /ssh:remotehost: .
        
  • Configure ~/.ssh/config on local host to obviate need for -R option on command line
    Host remotehost
        RemoteForward /run/user/1000/emacs/remote /var/folders/gk/rnw58qsx7t30_4rsndpzwww80000gn/T/emacs501/server
        StreamLocalBindUnlink yes
        
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment