This guide will teach you how to configure X11 forwarding to use on Virtual Machine instances managed by Vagrant.This is a series Tutorial on building Virtual Labs with Vagrant and VirtualBox.
We also have the following tutorials on Vagrant:

Step by step guide on how to extend Vdi and VMDK Hard disks on VirtualBox

X11 forwarding is crucial when you want to launch an application/utility on a Virtual Machine with no Gui, using the GUI interface of your Host machine. The Vagrant instance running will use X11 to talk to the display system of the host machine.
Before enabling X11 forwarding on the Vagrantfile, first ensure that you have required packages on the Vagrant instance that will enable X11 to work.The required utility required is
  •  xauth: This program is usually used to extract authorization records from one machine and merge them in on another (as is the case when using remote logins or granting access to other users)
  • If it doesn’t exist install it on the Vagrant instance.

For Debian based systems: Ubuntu/Debian/Linux Mint, Kali Linux e.t.c, do

sudo apt-get install xauth
For CentOS 7 and below, Fedora 21 and below run
yum install xorg-x11-xauth

 

For Fedora 22 and 23, run
dnf install xorg-x11-xauth
  • Once you’ve installed xauth if it didn’t exist, stop the Vagrant instance
vagrant halt
  • Open Vagrantfile
vim Vagrantfile

or

nano Vagrantfile
  • Now edit the Vagrant file and add below lines just after the vagrant.vm name
 config.ssh.forward_agent = true
 config.ssh.forward_x11 = true
  • Save changes and start the Vagrant instance
vagrant up
  • Now ssh to Vagrant instance by running the command vagrant ssh
vagrant ssh

You will get the message  “/home/vagrant/.Xauthority” does not exist. This is okay since we’re running it for the first time.The “xauth” program will create .Xauthority file for you.

  • Do a test on the vagrant instance running to check if indeed the X11 forwarding is working.On Vagrant Virtual Machine’s terminal run any of below commands. If you see window popup, then it’s working just fine.
xeyes
xclock

To use xeyes and xclock on CentOS 7 and below install it using

yum install xorg-x11-apps.x86_64

For Fedora 21,20 and below, use

yum install xorg-x11-apps

For Fedora 22 and Fedora 23

dnf install xorg-x11-apps

Tags:
How to enable X11 forwarding on Vagrant
Running Virtual Machine with X11 enabled on vagrant environment
X11 Forwarding for SSH on Vagrant instances
SHARE
Previous articleHow to install Adobe Reader 9.5.5 on Fedora 23,22 and Fedora 21
Next articleANGULARJS GENERIC FACTORY FOR CONSUMING REST API
I'm a fan of Linux and open source enthusiast with bachelor's degree in Electrical and Communications Engineering.The Swiss Army Knife syndrome makes me an expert in the fields of Virtualization, Cloud Computing,VoIP,Linux Containers and Server Hardening. Currently i have the following certifications: 1. LPI 2. SUSE Certified Linux Administrator ( CLA) 3. SUSE Certified Linux Professional ( CLP) 4. CCNA And working on RHCSA, RHCE, RHCVA, and Openstack Cloud Certification. I have a strong desire to learn, develop, and share knowledge with others.