Why does my X11 forwarding attempt fail with “connect /tmp/.X11-unix/X0: No such file or directory”?

On my local machine, I run:

ssh -X <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6a070f2a180f07051e0f070b090203040f44090507">[email protected]</a>

(For completeness, I have also tested all of the following using -Y with identical results).

As expected, this accesses remotemachine.com fine, and all appears well. If I then attempt to run xcalc however, I get:

 connect /tmp/.X11-unix/X0: No such file or directory
 Error: Can't open display: localhost:10.0

But,

$ ls -la /tmp/.X11-unix/
total 36
drwxrwxrwt 2 root root  4096 2012-11-23 09:29 .
drwxrwxrwt 8 root root 32768 2012-11-29 08:22 ..
srwxrwxrwx 1 root root     0 2012-11-23 09:29 X0

So not only does /tmp/.X11-unix/X0 exist, it has universal r/w/x permissions!

I’ve previously used x-forwarding without issue, though not in some time…

uname -a on the server for reference:

Linux machinename 2.6.32-25-generic #45-Ubuntu SMP Sat Oct 16 19:52:42 UTC 2010 x86_64 GNU/Linux

Been searching around on the web for a couple hours now without success. Other mentions of the same problem, but no solutions.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I had the same problem with Cygwin and Xming, connecting to a remote Linux server.

My $DISPLAY variable was simply “:0.0” in Cygwin, and although that works locally, it didn’t work with the remote ssh command.

Changing the variable to “localhost:0.0” on the local machine fixed the issue.

export DISPLAY=localhost:0.0

Once I did that, my command worked:

ssh -Yf <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dca9afb9ae9cb4b3afa8">[email protected]</a> gvim somefile.c

Method 2

If you have a X server running and the DISPLAY environment variable is set to :0, that tells applications to connect to the X server using a unix domain socket which is generally to be found on Linux in /tmp/.X11-unix/X0 (though see below about the abstract namespace on recent Linux).

When you ssh to machine remotemachine, sshd on remotemachine sets DISPLAY to localhost:10 (for instance), which this time means that X connections are do be done over TCP to port 6010 of machine localhost. sshd on remotemachine listens for connections on there and forwards any incoming connection to the ssh client. The ssh client then tries to connect to /tmp/.X11-unix/X0 (on the local end, not the remote) to contact your X server.

Now, maybe you don’t have a X server running (are you on Mac?) or maybe the unix domain socket is not to be found in /tmp/.X11-unix which would mean ssh hasn’t been configured properly at compile time.

To figure out what the proper path is for the unix socket, you could try a strace -e connect xlogo (or the equivalent on your system) on your local machine to see what a normal X application does.

netstat -x | grep X may also give a clue.

For the record, on a Linux Debian wheezy machine here, Xorg listens on both /tmp/.X11-unix/X0 in the filesystem and /tmp/.X11-unix/X0 on the abstract namespace (generally written @/tmp/.X11-unix/X0). From strace, X11 applications seem to now use that abstract namespace by default, which explains why those still work if /tmp/.X11-unix is removed, while ssh doesn’t use that abstract namespace.

Method 3

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).

Method 4

If your display host happens to be macOS, make sure you have XQuartz running.

This error message is telling you the ssh tunnel is working, but it can’t figure out how to connect to the X server on your side of the tunnel.

In the good old days, Mac OS X used to start XQuartz for you, but we have apparently abandoned this nice little feature in the macOS version of terminal.

Method 5

I just had the same problem. The confusing thing is that you get the no-such-file error on the remote machine, but actually this file is missing on the local (display) machine.

Just to see what would happen, I manually created the missing file (fifo, actually), on the display machine, like this:

mkfifo /tmp/.X11-unix/X0

Then ssh’ed into remote machine again, and lo and behold, X11 connected fine.

I don’t know if this is relevant or not, but my display machine is not Linux, it’s Windows with cygwin and VcXsrv. (The remote machine is Linux)

Method 6

I ran into this problem using the Windows Subsystem for Linux. The issue is I didn’t have a GUI installed on the client, because of the assumption that since it’s a Windows machine, I have a GUI.

To test if you have a GUI, execute xclock on the client. If you get the error Error: Can't open display: :0 then you need to install a GUI program for Windows. I used Xserver.

Once you have a GUI installed, try the following commands:

export DISPLAY=:0
xclock

If a clock comes up, then success!

Now try ssh’ing into the server, then running xclock. Did you get still get the error messages connect /tmp/.X11-unix/X0: No such file or directory
Error: Can’t open display: localhost:10.0
? That’s because the server is trying to connect to itself to display the GUI. Instead, you want the DISPLAY variable set to an address where the server can get your computer. So if it’s on a LAN, you would just put in your computer’s name. If you are connecting to a server on the WAN, then you need to specify your router’s external IP and have the proper port forwarded.

LAN: export DISPLAY=ComputerName:0
WAN: export DISPLAY=257.257.257.257:0

Method 7

I found that in WSL/Ubuntu, my ~/.bashrc had the line

$ export DISPLAY=:0

at the end of it.

Removing this line and restarting the WSL/Ubuntu app, I found that the DISPLAY environment variable was set correctly to

$ echo $DISPLAY
localhost:0

Now ssh into the remote machine using

ssh -X <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="30454355425e515d5570585f43441e5940">[email protected]</a>

works and can pop up windows in the remote machine.

Method 8

I had the same issue with cygwin.

I solved it with starting following *.bat-script

@echo off

C:
chdir C:cygwinbin
run XWin -multiwindow -clipboard -silent-dup-error
run mintty.exe -i /Cygwin-Terminal.ico -

source: https://www.asc.tuwien.ac.at/eprog/download/win10_Anleitung.mp4

Method 9

If it was working fine and stopped working without any proper reason, Probably it could be an uncontrolled X instance running in the background. Please close that using task manager.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x