Skip to content

Instantly share code, notes, and snippets.

@joekiller
Last active December 22, 2015 16:28
Show Gist options
  • Save joekiller/6499137 to your computer and use it in GitHub Desktop.
Save joekiller/6499137 to your computer and use it in GitHub Desktop.
centos6 vagrant
#!/bin/bash
#This script will prep a centos6 box for vagrant box packaging
cat << EOF | tee /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="dhcp"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
EOF
service network restart
yum -y update
yum -y install sudo
yum -y groupinstall "Development Tools"
useradd vagrant
groupadd admin
echo vagrant | passwd --stdin vagrant
usermod -a -G admin vagrant
# Setup sudo privileges
sed -i -e's/^Defaults.*requiretty/#Defaults requiretty/' /etc/sudoers
echo %admin ALL=NOPASSWD: ALL | tee -a /etc/sudoers
echo Defaults env_keep += \"SSH_AUTH_SOCK\" | tee -a /etc/sudoers
# Setup SSH permissions for vagrant
mkdir -p /home/vagrant/.ssh
cd /home/vagrant/.ssh
curl -O https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub
mv vagrant.pub authorized_keys
chown -R vagrant:vagrant /home/vagrant/.ssh
chmod 700 /home/vagrant/.ssh
chmod 600 /home/vagrant/.ssh/authorized_keys
sed -i -e's/^#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
sed -i -e's/^#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config
sed -i -e's/^#AuthorizedKeysFile.*\.ssh\/authorized_keys/AuthorizedKeysFile \.ssh\/authorized_keys/' /etc/ssh/sshd_config
# Reboot and then install updates and guest additions
echo Reboot the server and then install the virtual guest addons
echo shutdown -r 0
echo yum -y update
echo mount /dev/cdrom /media
echo /media/VBoxLinuxAdditions.run
echo umount /media
echo shutdown -h 0
# Package the file using
# vagrant package --base vagrant-centos63-nochef --output centos63-base-nochef.box
# vagrant box add centos63-nochef centos63-base-nochef.box
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment