Creating a Vagrant Box

15 minutes
  • 3 Learning Objectives

About this Hands-on Lab

Although a number of base Vagrant boxes are available on the Vagrant box repository, there may be times where we need to create our own virtual machine image that Vagrant can use to provision new environments. And while some of this configuration is provider-specific, there are still a number of tasks that all base boxes require in order to work with Vagrant out of the box.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Install Needed Packages
  1. Switch to root:

    sudo -i
  1. Install the linux-headers package for the appropriate release, build-essential and dkms. Note: Please wait several minutes for the dpkg lock to release if you have trouble installing the software.:

    apt-get install linux-headers-$(uname -r) build-essential dkms -y

Configure Vagrant Users
  1. Create a new vagrant user:

    useradd vagrant -m -G sudo -s /bin/bash
  1. Set the default password for both vagrant and root users to vagrant:

    passwd vagrant
    passwd root

  2. Ensure the vagrant user can use passwordless sudo:



    Save and exit visudo.

Add the Vagrant Public Key
  1. Switch to the vagrant user:

    su - vagrant
  1. Create an .ssh directory:

    mkdir .ssh

  2. Pull down the public key and add it to the authorized_keys file:

    mv .ssh/authorized_keys

  3. Set the permissions for the new directory and file:

    sudo chmod 700 .ssh
    sudo chmod 600 .ssh/authorized_keys

Additional Resources

You are a DevOps Engineer who has been tasked to create a new base image for your Vagrant infrastructure based on an Ubuntu 18.05 image. Consider Vagrant best practices for base box configuration, and install any necessary packages, create any needed users, and ensure the Vagrant public key is provided on the machine.

The URL for the Vagrant public key can be found at:

Note: Please wait several minutes for the dpkg lock to release if you have trouble installing the software.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?