Amazon Linux to Vagrant Box – part 3

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 - root

Create user, set the password the same as the username (required):

adduser vagrant
passwd vagrant

The 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.


and add the following at the end:

Defaults:vagrant !requiretty
#Defaults !visiblepw
Defaults env_keep = "SSH_AUTH_SOCK"


Now 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_config

Add or change lines in the file above with the information below, as needed.

Port 22

PubKeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys

PermitEmptyPasswords no
PasswordAuthentication no

Now, 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/.ssh
wget --no-check-certificate \
  -O /home/vagrant/.ssh/authorized_keys
chmod 700 /home/vagrant/.ssh
chmod 600 /home/vagrant/.ssh/authorized_keys

Vagrant 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 Tolls’ menu item and follow these steps:

sudo su - root
mount /dev/cdrom /mnt
tar vxzf /mnt/*.tar.gz -C /tmp
umount /mnt
cd /tmp/vmware-tools-distrib
./ -d

The ‘-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.

You can support this work by sending BTC to this Bitcoin address.