I understand that I should be able to use X11 to show graphs from a remote R when I use a local emacs to connect to the remote machine with tramp.

I have tried a few different things but can not get it to work. I know that the server will work with X11 as if I ssh in using a normal terminal it works.

Currently my .emacs file has:

;; emacs x11 tramp
(add-to-list 'tramp-remote-process-environment
              (format "DISPLAY=%s" (getenv "DISPLAY")))

(with-eval-after-load 'tramp
  (add-to-list 'tramp-methods
                 (tramp-login-program        "ssh")
                 (tramp-login-args           (("-l" "%u") ("-p" "%p") ("%c")
                                              ("-e" "none") ("-Y") ("%h"))) ; tried -Y and -X :(
                 (tramp-async-args           (("-q")))
                 (tramp-remote-shell         "/bin/sh")
                 (tramp-remote-shell-login   ("-l"))
                 (tramp-remote-shell-args    ("-c"))
                 (tramp-gw-args              (("-o" "GlobalKnownHostsFile=/dev/null")
                                              ("-o" "UserKnownHostsFile=/dev/null")
                                              ("-o" "StrictHostKeyChecking=no")
                                              ("-o" "ForwardX11=yes")))
                 (tramp-default-port         22)))
  (tramp-set-completion-function "sshx11" tramp-completion-function-alist-ssh))

On my local machine I also have two files, config and sshd_config in my .ssh folder. The latter simply contains X11Forwarding yes whereas the former has Host my_alias Hostname myhost User myusername ForwardX11 yes ForwardX11Trusted yes (with appropriate subs)

I connect to my server with C-x C-f sshx11:user@host:/ I then do M-x shell and select the "remote shell path" (to bin bash) and the starting directory.

Now when in the shell if I try echo $DISPLAY I get /private/tmp/com.apple.launchd.zmPeFoMlxA/org.macosforge.xquartz:0

But if I try to load an xprogram such as xterm to test I get: xterm Xt error: Can't open display: /private/tmp/com.apple.launchd.zmPeFoMlxA/org.macosforge.xquartz:0

  • 1
    Your X11 forwarding is not getting setup correctly. $DISPLAY should be something like "localhost:3.0", not what appears to be the value of $DISPLAY on your local machine. This works for me here, but I don't mess with tramp-remote-process-environment.
    – rpluim
    Commented Oct 16, 2019 at 15:29

1 Answer 1


I managed to kind of fix this by running "echo $DISPLAY" in a normal terminal and copying the value of that into the emacs terminal with "export DISPLAY=localhost:12.0" the value does change some times.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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