سؤال

I'm ssh'ing into a CentOS 6 VPS (from Mac Terminal) and trying to run emacs:

emacs ~/.bashrc &

At first I get nothing. Then, I try:

export DISPLAY=:0

Now, when I try emacs again, I get:

Display :0 unavailable, simulating -nw

What am I missing?

Thank you!

هل كانت مفيدة؟

المحلول

It is not clear from your question whether you actually have an X server set up on your Mac, so I’ll explain that first.

In order to use Emacs in graphical rather than terminal mode, you need an “X Server.” The X Window System is a standard and protocol which allows programs to draw on a display by sending messages over a communications channel, either locally or over a network (TCP). The machine with the display/keyboard/mouse runs the X server; programs such as Emacs which want to draw on the display are called X clients.

OS X does not come with an X server. You can get one from here: http://xquartz.macosforge.org/landing/. Apple used to include one, but they dropped it recently.

Once you have X working on your Mac, you can then run Emacs on your VPS and have it display on the Mac. You could set the DISPLAY variable (and adjust your firewall etc.) to have Emacs connect directly to your X server over the Internet, but this is a bad idea: the X protocol is insecure, and you don't want to expose that to the Internet. Instead, you can use SSH “X forwarding.” ssh -X is a specialized form of ssh -R: it sets up a TCP port listening on the loopback of the remote host, and sets the DISPLAY variable when you log in to point to this proxy. X clients on the remote side then transparently connect to your local X server, tunneled over the SSH connection.

Because of the network delay, it may take a few seconds for remote X clients to appear on your display. Emacs takes a particularly long time to appear, though I find that once it does ongoing operation is usually pretty smooth.

I installed xquartz and now get: X11 forwarding request failed on channel 0

Please post the output of your SSH session with ssh -vv, when you try this. Do you have the xauth program installed on the VPS? sshd uses that to establish a separate X authentication token (“MIT-MAGIC-COOKIE”) on the server side. It intercepts the initial X protocol authentication message and substitutes the remote (“spoofed”) token; this avoids exposing your local token on the remote host.

You might also try ssh -Y instead of ssh -X.

I should add that echo $DISPLAY (in Terminal, before I ssh into the VPS), now gives me this: /tmp/launch-ZMvHpM/org.macosforge.xquartz:0

That’s normal. This is general mechanism OS X uses to launch services on demand; this is set by launchd (I believe), and it automatically starts the X server when you run your first X client.

نصائح أخرى

Emacs tries to open a window in the remote machine, without an X Windows server running.

Try to enable X forwarding to your local machine with ssh -X, or run emacs there in console mode with emacs -nw (no windows).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top