Linux – Putty->Cygwin X11 Forwarding “Can’t open display” Error

cygwin;linuxputtyssh

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!

Best Answer

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.