|
| 1 | +# Setting up an Ubuntu VM with Vagrant on Windows 10 |
| 2 | + |
| 3 | +## Set up an Ubuntu VM |
| 4 | + |
| 5 | +1. Install VirtualBox (https://www.virtualbox.org/wiki/Downloads) |
| 6 | + - Download and install the latest version of VirtualBox for Windows hosts (as of this writing, [version 6.1.10](https://download.virtualbox.org/virtualbox/6.1.10/VirtualBox-6.1.10-138449-Win.exe) |
| 7 | + - Follow the install and use all the defaults. |
| 8 | + - After install, open the VirtualBox GUI |
| 9 | + - Go to menu *File -> Preferences* |
| 10 | + - In the *General* tab, look for the *Default Machine Folder* setting. |
| 11 | + Set it to `C:\files\VirtualBox VMs`. |
| 12 | + This will avoid your VM being created in your user's home directory, which could cause issues later. |
| 13 | + - Now click *Extensions*. |
| 14 | + - Make sure there is no Oracle VirtualBox Extension Pack listed. If there is, select it, and click the "X" button to the right to uninstall it. |
| 15 | + The license for this Extension Pack is not free for commercial uses, and you don't need it for a basic headless Linux VM. |
| 16 | + |
| 17 | +2. Install Vagrant 64-bit (https://www.vagrantup.com/downloads.html) |
| 18 | + - Download and install the latest version of Vagrant for Windows (as of this writing, [version 2.2.9](https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_x86_64.msi) |
| 19 | + |
| 20 | +3. Open a command-line window (cmd.exe) |
| 21 | + |
| 22 | +4. Run the following commands: |
| 23 | + ``` |
| 24 | + C:\Users\willis> mkdir c:\files\vagrant\devbox |
| 25 | + C:\Users\willis> cd c:\files\vagrant |
| 26 | + C:\files\vagrant> git clone [email protected]:pwillis-els/vagrant-ubuntu-windows-10.git devbox |
| 27 | + C:\files\vagrant> cd devbox |
| 28 | + C:\files\vagrant\devbox> vagrant up |
| 29 | + ``` |
| 30 | + |
| 31 | +## Login to your Vagrant machine |
| 32 | +1. To SSH in from the Windows console, open a command-line window (cmd.exe) and run the following: |
| 33 | + ``` |
| 34 | + C:\Users\willis> cd c:\files\vagrant\devbox |
| 35 | + C:\files\vagrant\devbox> vagrant ssh |
| 36 | + ``` |
| 37 | +2. You can also get the ssh connection information with command `vagrant ssh-config`, convert the IdentityFile to a PuTTY .ppk file, and use PuTTY to log in. |
| 38 | + |
| 39 | + |
| 40 | +## Create a new SSH key |
| 41 | +Vagrant creates an SSH key for you, whose path you can retrieve with the `vagrant ssh-config` command. |
| 42 | +However, you may find it more secure to have a password-protected key that lives only in your Vagrant box. |
| 43 | +1. Login to the Vagrant machine. |
| 44 | +2. Run the following command: |
| 45 | + ```bash |
| 46 | + $ ssh-keygen -o -t ed25519 |
| 47 | + ``` |
| 48 | + |
| 49 | +## Set up GitHub Access |
| 50 | +1. Navigate to [Add new SSH key](https://github.com/settings/ssh/new) |
| 51 | +2. Put in a title ("Vagrant Devbox") and paste in your SSH public key, which you can get from: |
| 52 | + ```bash |
| 53 | + $ cat ~/.ssh/id_ed25519.pub |
| 54 | + ``` |
| 55 | +3. Navigate to [Add a New personal access token](https://github.com/settings/tokens/new) |
| 56 | +4. Add a description ("Vagrant Devbox") and select the scopes ("repo" is enough to start), and click **Generate Token** |
| 57 | +5. Immediately copy down the token on the screen. |
| 58 | +6. If your GitHub account is SSO-linked, click **Enable SSO** next to the new Personal Access Token, and then click **Authorize**, and follow the prompts. |
| 59 | +7. In your Vagrant box, add your GitHub login credentials to the file `/home/vagrant/.netrc`. Use your new Personal Access Token as the password. (Instructions: https://stackoverflow.com/questions/6031214/git-how-to-use-netrc-file-on-windows-to-save-user-and-password) |
| 60 | +8. In your Vagrant box you can now use `git` to checkout GitHub repos using either the HTTPS or SSH protocol. |
| 61 | + |
| 62 | +## Extras |
| 63 | + |
| 64 | + - Use Docker inside the Vagrant box to run applications, as Ubuntu's versions are not the latest. Examples: |
| 65 | + - Terraform: |
| 66 | + ```bash |
| 67 | + $ mkdir $HOME/bin |
| 68 | + $ printf '#!/bin/bash\ndocker run -i -t hashicorp/terraform:light "$@"\n' > $HOME/bin/dterraform |
| 69 | + $ chmod 755 $HOME/bin/dterraform |
| 70 | + $ ~/bin/dterraform version |
| 71 | + Terraform v0.11.11 |
| 72 | + ``` |
| 73 | + |
| 74 | + - AWS CLI: |
| 75 | + ```bash |
| 76 | + $ mkdir $HOME/bin |
| 77 | + $ curl -o $HOME/bin/aws.sh https://raw.githubusercontent.com/mesosphere/aws-cli/master/aws.sh |
| 78 | + $ chmod 755 $HOME/bin/aws.sh |
| 79 | + $ export AWS_ACCESS_KEY_ID="<id>" |
| 80 | + $ export AWS_SECRET_ACCESS_KEY="<key>" |
| 81 | + $ export AWS_DEFAULT_REGION="<region>" |
| 82 | + $ aws.sh s3 ls |
| 83 | + ``` |
0 commit comments