Last active
August 29, 2015 14:16
-
-
Save ddaws/a426bcd5bf69fa1c66d8 to your computer and use it in GitHub Desktop.
Prepare linux VMs for packaging as a Vagrant Box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I still need to download and install the virtual box guest additions and disable password-less login.