Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSH into vagrant with X server set up

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
like image 804
Matt Avatar asked Nov 20 '13 11:11

Matt


People also ask

How do I SSH into vagrant machine?

Simply CMD-SHIFT-P then "Remote-SSH: Connect to Host..." and the ssh . config entry you just added is automatically listed - you simply select it and voila, vscode connects to your remote vagrant vm!

What is vagrant SSH command?

Command: vagrant ssh [name|id] [-- extra_ssh_args] This will SSH into a running Vagrant machine and give you access to a shell. On a simple vagrant project, the instance created will be named default.


2 Answers

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.

like image 128
m01 Avatar answered Oct 18 '22 18:10

m01


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.

like image 5
Matt Avatar answered Oct 18 '22 19:10

Matt