This is complementing other answers with information specific from Windows-Subsystem for Linux (WSL). The accepted answer is correct: your DISPLAY
variable is incorrectly configured. It's not exactly clear, however, why that's the case from that answer alone, so I'm remediating with this answer.
If you are running cygwin, or Windows-Subsystem for Linux, and your X11 server is windows-based (e.g. VcXsrv
, or XMing
), it is more likely that your X11 server is listening on a TCP port (such as 127.0.0.1
port 6000-6010
) than on the default Unix domain socket (/tmp/.X11-unix/X0
). Unix sockets are not well-supported on Windows at this point in time, even inside WSL. Communicating between programs in the Linux-like environment and programs running directly on the windows host is also generally easier over IP sockets.
When you run graphical applications locally (i.e. from the Cygwin or WSL environment of your host), and your DISPLAY
variable is set to the default (i.e. DISPLAY=:0.0
), applications will first attempt to connect to the X server via the Unix socket /tmp/.X11-unix/X0
. This will fail, but most applications will then fallback to a TCP connection on localhost
, which should succeed in reaching the server, assuming your X server is configured with defaults.
You could confirm that this is happening by looking for connect()
calls in strace logs from a run of your graphical application. Those would generally happen early on, before the main window of the application appears.
The catch: That fallback behaviour doesn't happen when ssh is redirecting a connection from the remote side, so you are getting that error. sshd
on the remote will indeed forward the X11 connection to the local side, but the ssh client's local connection dead-ends as it fails to reach out to the server over the Unix socket. You are then getting the ENOENT
error. It doesn't try the fallback connection to TCP localhost.
The fix: In such cases, changing your DISPLAY
variable to use the TCP syntax instead of the :0.0
syntax, can fix the issue:
DISPLAY=127.0.0.1:0 ssh remote some-gui-application
Like other answers mention, you can also export that variable interactively from your shell prompt:
$ export DISPLAY=127.0.0.1:0
...
$ ssh remote some-gui-application
You can also store this setting more permanently by adding that line to your login shell profile initialization script (e.g. ~/.bash_profile
).
Note: Some shells have a different initialization script for login and non-login sessions. For instance, with bash you could write that line to the non-login script, i.e. ~/.bashrc
, instead of ~/.bash_profile
. If you do, be careful not to override any custom value that might have been set by ssh. That would be the case if you were hopping first into your host via ssh and then hopping again into another host (thus nesting your X11 forwarding).
strace -fo /tmp/trace ssh....
to check that it does try to connect that Unix domain socket. – Stéphane Chazelas Nov 29 '12 at 14:27