Putty->Cygwin X11 Forwarding “Can't open display” Error

24,362

Solution 1

Recent Cygwin updates have changed its X server to not listen for TCP connections by default. Instead, Cygwin's X uses (the Cygwin implementation of) Unix domain sockets, and PuTTY (as a native Windows program) doesn't know how to use these.

The Cygwin X FAQ and Cygwin mailing lists have more details.

My solution was to take the standard Cygwin shortcut that uses startxwin to launch X:

C:\cygwin\bin\run.exe --quote /usr/bin/bash.exe -l -c "cd; /usr/bin/startxwin"

and replace it with a direct invocation of xinit with my desired options (add -listen tcp and remove -auth):

C:\cygwin\bin\run.exe --quote /usr/bin/bash.exe -l -c "cd; /usr/bin/xinit /etc/X11/xinit/startxwinrc -- /usr/bin/XWin :0 -multiwindow -listen tcp"

This is less secure than Cygwin's new defaults; it should only be used on a single-user system, and configuring your firewall to block connections to XWin may be wise.

Solution 2

As an alternative to what Josh Kelley said, you can also edit the startxwin file and add the "-listen tcp" to the default server arguments.

Old: defaultserverargs="-multiwindow"

New: defaultserverargs="-multiwindow -listen tcp"

Also with authentication enabled, I had to point putty to the authentication file created by the startxwin script. Mine was located here: c:\cygwin64\home\USERNAME.Xauthority

Since this file is recreated, you will have to restart putty sessions after you reset your xserver.

For security, you might also only allow connections from localhost, as this is where putty forwards it through.

Solution 3

I tried setting the "X display location" to localhost:0

Please try to set the "X display location" to ':0.0' instead!

export DISPLAY=:0.0

Josh Kelley mentioned the Cygwin X FAQ:

3.13. I upgraded and now X clients can't connect

A1:

Since X server 1.17, by default the server does not listen for TCP/IP connections, only accepting local connections on a unix domain socket.

For local clients, use DISPLAY=:0.0, rather than DISPLAY=localhost:0.0, DISPLAY=127.0.0.1:0.0, DISPLAY=::1:0.0, etc.

Share:
24,362

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin almost 2 years

    I am using Putty on a Windows machine to ssh into another server. Once there, I am trying to use X11 forwarding to pop windows onto my computer. The remote system is not the issue since it is a large system that is successfully used by many other users in this same manner.

    I log into the system via Putty without issue and then run startxwin in cygwin. However, upon running xterm in Putty, I am given the error xterm Xt error: Can't open display: localhost:##.0 where the pound signs are two integers whose value changes each time I log in.

    • I have X11 forwarding enabled in the Putty settings
    • I tried setting the "X display location" to localhost:0
    • I have ensured to download the X11 package for cygwin
    • I have tried using just startx instead of startxwin
    • I have tried setenv DISPLAY localhost:0 and setenv DISPLAY my.ip.address

    Unfortunately, the issue persists. I've exhausted my Googling resources on this topic and so I would greatly appreciate any help. Thanks!

  • yellowandred
    yellowandred almost 6 years
    where to run this?? in cygwin terminal / PS / CMD
  • Josh Kelley
    Josh Kelley almost 6 years
    @yellowandred It starts with `C:`, so it's a Windows-style path, not Cygwin terminal. I just put it in the Target section of my Windows shortcut. CMD ought to work. PowerShell should work, but you may have to update the quoting.