0
[kevin@serverA myFolder]$ emacs sample
emacs: Cannot connect to X server <IP Address>
Check the DISPLAY environment variable or use `-d'. Also use the `xhost'
program to verify that it is set to permit connections from your machine.

I did run xhost+ prior to ssh'ing to my server.

Why can't I open emacs?

2 Answers 2

3

xhost isn't really relevant in this case, if you're ssh tunneling X. You didn't really mention what your setup is, so I'll assume that your display client is a mac, and your server is a linux box of some sort, and you're ssh'ing into it.

  1. Are you forwarding X11 over your ssh session? You can do this either by adding -X to your ssh command line, or by putting "ForwardX11 yes" in ~/.ssh/config. Once that's done, check your DISPLAY variable on the server (after sshing into it) by running "printenv DISPLAY". It should print something like "localhost:10.0" or similar, the important part being the localhost part.

  2. Is X11 installed on your mac? If not, get it. For Mountain Lion, you need to download XQuartz and install it. For older versions, It should be in a folder marked "Optional Installs" on your installation DVD.

  3. If that's set properly, do you have xauth installed on your server? Try running xauth on your server and see if you get a response. If not, you'll need to get that installed.

If all those stars are in alignment, you should be able to successfully display X applications on your mac.

3
  • Also, is sshd on the server configured to allow X forwarding? Check X11Forwarding in /etc/sshd_config; it defaults to no.
    – legoscia
    Commented Aug 10, 2012 at 9:42
  • So if I ssh into server b, and it does not allow X11 forwarding according to its /etc/sshd_config, can I just update it to yes? Commented Aug 10, 2012 at 14:59
  • Yes, assuming you have root privileges on the server. Commented Aug 10, 2012 at 16:27
0

Are you able to open ANY other X programs at all? What if you try xclock? The Command line defaults its X display output to expect "displays" created on the machine you are remoted into. The error leads you to provide the forwarding info so it can send the display window to your local X11 system. If you don't already have X11 running in your local system, then skip to the end of this post for an alternative.

I think forwarding is not done automatically for you with just the X11Forwarding in /etc/sshd_config from discussion in your first answer. So follow the guide here to use the display command-line option (must be done every time):

emacs sample -display your-actual-hostname-or-ip:0.0

If all that fails, use the text-only workaround while you're remoted in: emacs -nw sample If you're using this, keep in mind that nothing, even the menus can be clickable. You may need to do [F8] and then follow the text-based menu guidance to get at the menu options. There may be a .emacs workaround for that.


Knowing emacs, you can tackle this the other way around if you have downloaded a local version of emacs (I suggest xemacs) --Tramp mode for emacs will INITIATE ssh sessions to your remote host and edit files seamlessly. There's open Stack Exchange questions like one about such slave ssh shells. Here is one with a few more details about eshell and tramp mode. Having options is great for the right moment.

2
  • I had the problem where all other x applications were coming up fine, only emacs was failing. Specified the display argument to :10.0 (instead of the default localhost:10.0 being picked up through ssh -X option) and it started working.
    – Rumbleweed
    Commented Jan 6, 2019 at 1:05
  • @Rumbleweed Same situation, but that did not work for me.
    – Michael
    Commented Feb 27, 2020 at 4:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .