In part one of this series, I described how to get the basic distribution copied down from AWS to a local partition within a virtualized environment.
For part two of this series, I described putting a working kernel and kernel tool building environment on the virtual disk created during part 1, and boot it up for the first time.
You need to boot this VM into single user mode so we can add a password to the ec2-user so we can configure the instance. This is explained all over the Internet so I am going to skip this piece of the documentation.
Since we are building this for vagrant, we need to allow vagrant to use sudo without any password prompts.
Log in as the ec2-user and become root:
sudo su - rootCreate user, set the password the same as the username (required):
adduser vagrantpasswd vagrantThe base install of Amazon Linux has the OpenSSH server package already installed and set to start-up on boot but we need to change a couple of items to allow vagrant to bring the instance up and configure it.
Now we need to allow the user vagrant to use sudo without a password.
visudoand add the following at the end:
Defaults:vagrant !requiretty#Defaults !visiblepwDefaults env_keep = "SSH_AUTH_SOCK"
vagrant ALL=NOPASSWD: ALLNow we need to edit the SSH daemon configuration so that the vagrant user can automatically log in via SSH public key.
vi /etc/ssh/sshd_configAdd or change lines in the file above with the information below, as needed.
Port 22
PubKeyAuthentication yesAuthorizedKeysFile %h/.ssh/authorized_keys
PermitEmptyPasswords noPasswordAuthentication noNow, log out completely and log in as user vagrant (simplifies the next step).
Install the SSH key needed for vagrant to automatically provision the server. This very simple to do, and required.
mkdir -p /home/vagrant/.sshwget --no-check-certificate https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub \ -O /home/vagrant/.ssh/authorized_keyschmod 700 /home/vagrant/.sshchmod 600 /home/vagrant/.ssh/authorized_keysVagrant requires the installation of the virtualization tools to bring the instance up. As this series of posts is using VMware Fusion the steps required is very simple.
If you follow this exactly then you will be testing your sudo configuration.
Go to ‘Virtual Machine’ and select the “Install VMware Tools’ menu item and follow these steps:
sudo su - rootmount /dev/cdrom /mnttar vxzf /mnt/*.tar.gz -C /tmpumount /mntcd /tmp/vmware-tools-distrib./vmware-install.pl -dThe ‘-d’ in the command line means use defaults, which works great for what we are doing. This will configure and install the tools and required kernel modules.
When complete, just reboot, log in as vagrant and do your first tests to make sure everything is working.
In part 4 I will explain how to take this VMware Fusion image and turn it into a vagrant box ready for install.