Skip to content

Instantly share code, notes, and snippets.

@ddaws
Last active August 29, 2015 14:16
Show Gist options
  • Save ddaws/a426bcd5bf69fa1c66d8 to your computer and use it in GitHub Desktop.
Save ddaws/a426bcd5bf69fa1c66d8 to your computer and use it in GitHub Desktop.
Prepare linux VMs for packaging as a Vagrant Box
#!/bin/bash
# Dawson Reid
# Feb 25, 2015
# Note : Currently only supports Debian.
VAGRANT_USERNAME="vagrant"
VAGRANT_PASSWORD="vagrant"
LANGUAGE_LOCAL="en_US"
# run as root. this should not be a problem because this script it intended to be
# executed on a disposable VM.
sudo su root
if id -u $1 >/dev/null 2>&1; then
echo "$VAGRANT_USERNAME already exsists."
else
adduser $VAGRANT_USERNAME
fi
echo $VAGRANT_PASSWORD | passwd $VAGRANT_USERNAME --stdin
# give the vagrant user password-less sudo
echo "$VAGRANT_USERNAME ALL=(ALL) NOPASSWD: ALL" >> "/etc/sudoers.d/$VAGRANT_USERNAME"
# sudo is required from this point forward because we are now executing as the
# vagrant user.
apt-get update && apt-get install build-essential git openssh-server curl dkms linux-headers-generic
# disable SSHD DNS
echo "UseDNS no" >> /etc/ssh/sshd_config
# set language settings
locale-gen $LANGUAGE_LOCAL.UTF-8
dpkg-reconfigure locales
echo "LANG=\"$LANGUAGE_LOCAL.UTF-8\"" >> /etc/default/locale
echo "LANGUAGE=\"$LANGUAGE_LOCAL\"" >> /etc/default/locale
# -----
# Setup SSH
# -----
sudo su $VAGRANT_USERNAME
mkdir $HOME/.ssh
curl 'https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub' >> /home/vagrant/.ssh/authorized_keys
# set owner and permissions
#chown -R vagrant /home/vagrant/.ssh # not required because we are operating as the vagrant user
chmod 0700 $HOME/.ssh
chmod 0600 $HOME/.ssh/authorized_keys
sudo su root
service ssh restart
@ddaws
Copy link
Author

ddaws commented Feb 26, 2015

I still need to download and install the virtual box guest additions and disable password-less login.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment