Enable X11 forwarding in Vagrantbox running in Cygwin

References:

http://x.cygwin.com/docs/ug/setup.html

https://coderwall.com/p/ozhfva/run-graphical-programs-within-vagrantboxes

https://superuser.com/questions/310197/how-do-i-fix-a-cannot-open-display-error-when-opening-an-x-program-after-sshi

  1. First, you need to install Cygwin/X packages as below:
    xorg-server
    xinit
    xorg-docs (optional)
    xlaunch (optional)
  2. In your Vagrantfile, add the following:
    Vagrant.config(2) do |vb|
    config.ssh.forward_agent = true
    config.ssh.forward_x11 = true
    end
    reboot your vagrant box by running ‘vagrant reload’
  3. In your vagrant box, install xauth ‘sudo yum install -y xauth’ (assume you are using CentOS)
  4. Start X Server in Cygwin:
    startxwin — -multiwindow -listen tcp &
  5. Pay attention to the output of startxwin, set up DISPLAY environment variable in Cygwin, ex. ‘export DISPLAY=’localhost:0.0’
  6. In your Vagrant box, make sure /etc/ssh/sshd_config has ‘X11Forwarding yes’ set up.
  7. Run a GUI app in Vagrant box such as:
    ssh -Y -p 2222 -i vagrant@localhost xclock
    (You need to make sure your private key has a mode of 600)

Note:

if you get error ‘Permission denied (publickey,gssapi-keyex,gssapi-with-mic)’, you need to make sure ‘config.ssh.forward_agent=true’ is added to your vagrant file and ‘Vagrant reload’ is executed.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s