Question

I am running into problems with setting up X11 forwarding on vagrant VM.

I am running Xming for X server and PuTTY as my SSH client.

This is what I get when I run vagrant ssh-config:

Host default
  HostName 127.0.0.1
  User vagrant
  Port 2200
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile C:/Users/MyName/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL
  ForwardAgent yes
  ForwardX11 yes

My PuTTY has X11 forwarding enabled and X display location set to 0.0.

When I do echo $DISPLAY I get no response.

I am unsure as to what I configured wrongly. I followed the following advice in setting up my PuTTY client. If there is an easier way to set up VM with X11 forwarding, please, let me know.

For reference these are contents of my Vagrantfile.

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.ssh.forward_agent = true
  config.ssh.forward_x11 = true

end
Was it helpful?

Solution 2

Install Cygwin with the following packages to resolve the problem as specified in this website:

  • xorg-server
  • xinit
  • xorg-docs (for documentation)
  • openssh (in case this wasn't installed previously)

Then load up the window using startxwin from the cygwin terminal.

A note that I discovered later is that it is better to ssh into vagrant using the following command:

vagrant -Y ssh

Than:

vagrant -X ssh

The latter is performed in untrusted mode as in this answer and times out after a while.

OTHER TIPS

I had a very similar issue, but in my case it was an issue with the Vagrant VM. Here are some things to check:

  • X11Forwarding needs to be set to yes in /etc/ssh/sshd_config
  • Enable verbose logging for ssh (vagrant ssh -- -vvv -X in Linux, Putty also seems to have a -v command line flag) and look for interesting messages.

With my Vagrant VM the latter revealed the following message:

debug1: Remote: No xauth program; cannot forward with spoofing

After installing a package that provides xauth (xorg-xauth, xorg-x11-xauth or similar), vagrant ssh -- -X worked fine.

Use "startxwin" to run the cygwin X server. Use putty or the cygwin ssh client to ssh to your guest virtual machine.

If using cygwin ssh, do "export DISPLAY=:0" before running ssh (ie "vagrant ssh -- -vvv -X").

For putty: Run "startxwin -- -listen tcp", enable ssh-X11 forwarding in the putty connection config, set "X display location" to "localhost:0" and set the correct path of the .Xauthority file (browse, it is probably in your home directory; startxwin output will tell you where).

Perhaps do not use msys2 ssh (the vagrant default installed environment is msys2 but vagrant also works fine under cygwin) with the cygwin X server. (see details for more info about why)

Details:

If you get "connect /tmp/.X11-unix/X0: No such file or directory" (under ssh verbose mode) or putty error "PuTTY X11 proxy: unable to connect to forwarded X server: Network error: Connection refused", try using tcp sockets rather than the default unix domain sockets.

When you run your Cygwin X server, go "X -listen tcp -multiwindow" (multiwindow is optional - it opens new windows for each app).

If using openssh "ssh" from the command-line: Before going "vagrant ssh -- -vvv -X", go "export DISPLAY=localhost:0" (not ":0" but "localhost:0" so it uses tcp). I am running git bash which uses msys2 which seems to not communicate properly with my cygwin X server over emulated unix domain sockets. But if I use "vagrant ssh -- -X" under my cygwin prompt (with DISPLAY=:0 for unix domain sockets), it works.

Great info source: http://dustwell.com/how-x-over-ssh-really-works.html

Also, you can add "config.ssh.forward_x11 = true" to your Vagrantfile. I think this sets X11Forwarding in /etc/ssh/sshd_config when the guest virtual machine is set up or "vagrant reload" is run. - https://coderwall.com/p/ozhfva/run-graphical-programs-within-vagrantboxes

Update: It is not recommended to run X without xauth security (as shown above). It is not secure. For example, other computers on the same LAN can connect to your x-server via tcp and sniff your keypresses using xkeys. Use "startxwin" instead of running X directly so it uses the "-auth" option of XWin. This makes it difficult for me to get my msys2 ssh to redirect X to my cygwin X server. The ssh log while connecting says it cannot find the xauth command - that is because it is not present in my msys2 environment. Cygwin ssh X-redirection still works fine. Putty works fine as long as you set the .Xauthority file path (it is probably right in your home directory) in the putty session config.

I discovered the tcp/unix-domain socket problem/solution is actually in the cygwin faq (this faq is quite helpful and has a lot of info):

6.7. X sessions forwarded by PuTTY can't connect. Non-cygwin local X clients can't connect.

The X server now uses -nolisten tcp by default, which increases the security of the X server by not opening a TCP/IP socket, only a local (UNIX domain) socket. Non-cygwin applications cannot connect to that socket.

https://x.cygwin.com/docs/faq/cygwin-x-faq.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top