What if you use Arch Linux (you should) and you have a crappy program that works only on a specific version of Ubuntu?

Sure you could use Dual Boot or a Live Image temporarily, but that’s boring.

Or you could containerize things, put Docker in the mix and start digging into strange problems related do different kernel versions.

What about a Virtual Machine? That’s boring too… It takes 15 minutes to install!

But what if we can skip the installation and just boot a shiny VM?

Vagrant to the rescue

Vagrant is a nice tool to provision virtual machines based on textual configuration. It could be used to create VMs for different hypervisors, such as KVM, VirtualBox and others.

The main advantage is how easy is to build a Virtual Machine:

    vagrant init hashicorp/bionic64

Will create a machine will reasonable resources, which could be run with vagrant up. And vagrant ssh will grant you a shell directly in the VM.

Are you not happy with the default configuration? Just change the Vagrantfile in the current folder.

But I need a UI!

OK now we have a new virtual machine, but it won’t have a UI (unless you install a -desktop image…). Most likely a X tunnel is enough, the X server (or WayLand for you that are reading from the future) will take care of displaying the actual application.

To skip all the libraries installations, install any UI program, such as Firefox. You’ll also need auth: sudo apt install firefox xauth

Then, you should be able to forward the X server and good to go.

Wait where is the ssh connection?

vagrant ssh is a shortcut to reach a shell, but it won’t handle all the little options that you may want to set, such as a nice -X to forward the X server.

Just save the following as sshX in the current folder:

#!/bin/bash

# Just a wrapper to ssh to establish X connection to the machine without
# caring about keys and authentication
# (C) 2018-2022 Massimo Girondi

MACHINE=$1
PPATH=".vagrant/machines/$MACHINE"
PROVIDER=`ls -1 $PPATH`
PORT=2200

shift 1

if [ ! -f $PPATH/$PROVIDER/port ]; then
	PORT=`vagrant port | grep -e '=> [0-9]*' -oh|cut -c4-`
	OUT="$PPATH/$PROVIDER/port"
	echo $PORT | tee $OUT
	echo "ssh-keygen -R '[127.0.0.1]:'$PORT"
else
	PORT=`cat $PPATH/$PROVIDER/port`
fi


ssh vagrant@127.0.0.1 -p $PORT \
            -i $PPATH/$PROVIDER/private_key \
            -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null\
            -X \
	    -oLogLevel=FATAL \
            -oCompression=yes \
            -oDSAAuthentication=yes -oIdentitiesOnly=yes\
	$@

And then ./sshX machine_name