Skip to content

How to prepare your devbox for Vagrant

Vagrant is an incredibly useful way to manage and control development setups, it allows you to define a base box and install extras in a repeatable manor.


With this as a starting point, you may find you want to configure your own base box and export it ready for Vagrant. To do this, a few steps need to be performed to the machine before it can be used.

Set up the Vagrant User
Install sudo, add the user and set the password to vagrant.

yum install -y sudo
useradd -m -G wheel vagrant
passwd vagrant

Next we are allowing the vagrant user passwordless sudo access.

echo "vagrant ALL=(ALL) ALL" >> /etc/sudoers
echo "%wheel ALL=NOPASSWD: ALL" >> /etc/sudoers
echo 'Defaults env_keep="SSH_AUTH_SOCK"' >> /etc/sudoers

Finally comment out the line “Defaults requiretty” in /etc/sudoers

Include the Vagrant SSH Key
mkdir ~vagrant/.ssh
curl -L > ~vagrant/.ssh/authorized_keys
chown -R vagrant:wheel ~vagrant/.ssh
chmod 0700 ~vagrant/.ssh
chmod 0600 ~vagrant/.ssh/authorized_keys

Export the Box
Cleanup first

yum clean all
history -c
cat /dev/null > ~/.bash_history

Shutdown the box, then we’ll export externally
shutdown -h now

vagrant package --base "My Dev Box"

Be First to Comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.