Raspberry PI X11 forwarding with Cygwin

After my little Raspberry PI Mono installation accident, that fucked up everything with Mono, I decided to reinstall Raspbian Wheezy. I know a lot of people that love touchy and clicky interfaces, the tablet market rise reflect this. I personally use my RPi through command line, SSH it over LAN, because I one Desktop environment (my Windows machine) is more than enough for me.
But after a couple mails with a friend trying to view his PI’s lxsession on his Windows machine and explaining him my setup using Cygwin only, he told me there’s no tutorial on this. Nothing new or super cool, just another way.
This guide should work ok with any linux environment, not only RPIs, provide you properly set ssh configurations.

The first thing to do is downloading Cygwin installer, be sure to add xorg, xint and openssh packages while installing. There may be some other needed packages, if you get somenthing like a “command not found”, you have to add that package too.

Now open a Cygwin shell with its nice desktop shortcut and type:
cygstart xwin
cygstart tells Cygwin to run a command and give you back your shell control. Removes the need for two shells (one for launching the Xserver and one for SSH connection). It can be omitted.
xwin Launches the XWin application, which is our Xserver
This is usually enough, but as default setting, xwins create a window big as my current resolution. I prefer using this command:
cygstart xwin -screen 0 1440x900@1 -wgl
Fast explanation:
-screen 0 1440×900@1 tell xwin to create the remote screen window number 0, with a resolution of 1440×900 at monitor 1. Use this parameter as this, modifying only the resolution part. See Note 1 for better explanation.
-wgl will enable OpenGL accelerated graphics on the remote screen window. It is not mandatory and if not enabled the remote screen window will use software rendering.

After that we must make sure that Cywin is aware of this remote display, it can be done by setting and exporting the environment variable DISPLAY.
The newly created window will have name like: Cygwin/X:0.0, make sure to set this variable to whatever is written after the X, like
export DISPLAY=:0.0

Now, using Cygwin, SSH to your PI
ssh -Y pi@address
and after logon, start you windows manager:
lxsession
This should show your Raspberry PI desktop inside your XWin window.

Final notes:
If you want to do all of this stuff at cygwin’s startup, just add the lines
cygstart xwin #+your parameters
export DISPLAY=:0.0

at the end of cygwin\home\user\.bashrc.

Note 1:
See XWin manual for possible parameters.
-screen 0 1440×900@1 explanation:
0 Create windows number 0. It’s like an ID to identify which windows is this. If you want to use multiple remote screens, for each new screen you have to increment this value by one.
1440×900 Is pretty self explanatory. Sets the PI’s max resolution to this size.
@1 Tell XWin on which (real) monitor you want the window to appear. So in case of a multiple monitor setup 1 is the main monitor, while 2, 3, 4, …, are the other monitors. If you have a single monitor this value is always 1.

About Andrea Giorgio "Muu?" Cerioli

Italian developer who loves everything in technology, from mechanics to electronics to IT. A guy who actually messed up with his school education and dropped it at 17, pursuing his own interests only.

4 thoughts on “Raspberry PI X11 forwarding with Cygwin

  1. hello. I followed your TUTO but when i writed this command “ssh -Y pi@address” of course after changing the @ , the terminal showed this message
    “$ ssh Raspberry@169.254.120.126
    ssh: connect to host 169.254.120.126 port 22: Connection timed out”.
    Also when i used Putty ,it didn’t work and it showed “Network error: Connection timed out” .
    Help me pleeeeeeeeeeeease. thank you . 🙂

    1. Looks like you are trying to connect your raspberry pi eth directly to your pc eth.
      Windows (Some linux distros and OSX, too) automatically use a link-local address (169.254.x.x) when it can’t find a DHCP server but Rpi needs to be specifically configured for that.

      An easy solution is to connect your Rpi eth to your router and use the DHCP assigned ip for connecting via ssh. You can usually find the ip assigned to Rpi through your router’s web interface.

      If you have the absolute need of connecting Rpi and pc’s ethernet, I found this long and detailed guide that may help you configure your devices correctly.

Leave a Reply

Your email address will not be published. Required fields are marked *