Tuesday, November 24, 2015

Configuring an OS X Guest for a Vagrant base box

In the guest OS we need to complete four tasks in order for vagrant to be able to do the things it expects to be able to do. In simple terms we need to do the following:

  1. create a user vagrant with password vagrant
  2. install VMware Tools
  3. enable and configure ssh
  4. configure sudo

1. create a user vagrant with password vagrant

To meet the first requirement we can simply go through Setup Assistant in the guest OS X instance specifying the account name vagrant and the password vagrant.




2. install VMware tools

Once we have a usable machine the next thing we should do is install the VMware Tools. This allows the vagrant project folder to be mounted in the guest at /vagrant. To do this VMware will mount a disc inside the virtual machine that contains the VMware tools installer.
  • In the host OS select the Virtual Machine menu in VMware Fusion
  • Select Install VMware Tools
  • Fusion will present a warning sheet informing you that it will mount a fake disc in order to complete the installation. Simply click Install
  • In the guest OS double click on the Install VMware Tools package and restart the VM when prompted. (doing this in Catalina may require approving, restarting, and installing again)



3. To enable and configure ssh we need to do the following:

  • enable ssh aka Remote Login in System Preferences' Sharing pane

  • Vagrant boxes typically allow login via publicly available keys. This can be changed, if required, for security reasons but that is beyond the scope of this document. Also, when `vagrant up` detects that the public key is in use it automatically creates a new key and injects it into the machine increasing the security somewhat. To enable login via key we need to create a hidden folder and obtain the public key from github.
  • The Vagrant docs suggest that we disable DNS lookups to increase ssh performance for VMs that may not have a connection to the internet.
    • still within Terminal open sshd_config in your editor of choice (EDIT: since written this post has incorrectly stated that you should edit ssh_config but that is incorrect)
      • sudo vim /etc/ssh/sshd_config
    • uncomment the existing line for this entry and save the file
      • UseDNS no



4. configure sudo

The last thing we need to configure in the VM is sudo. Vagrant uses sudo to perform tasks in the guest OS that require elevated privileges. The docs also suggest setting the root password to vagrant but this is not required, especially in OS X where root availability is not an expectation. Configuring sudo properly is very important to prevent errors later.

Use visudo to edit /etc/sudoers

EDIT: key presses removed as they are no longer accurate.
  • add an entry below the %admin group as shown in the screenshot below
The vagrant line should look like this before you :wq



Cleanup

As a final bit of cleanup before shutting down:
  • type the command "history -c" in Terminal and then quit it
    • clearing history in zsh (Catalina+) is a bit more annoying.
      • by default you need to exit the shell, run a new one, and `rm .zsh_history`
        • yes this will still show that rm
  • clear Recent Folders in the Go menu of Finder
  • clear Recent Items in the Apple Menu


In the next post we will pack up the VM into a box and finally start playing with vagrant.

No comments:

Post a Comment