Skip to content

Commit b940f8b

Browse files
author
Peter Willis
committed
Initial commit
0 parents  commit b940f8b

File tree

3 files changed

+172
-0
lines changed

3 files changed

+172
-0
lines changed

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
```

Vagrantfile

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
Vagrant.configure("2") do |config|
5+
# https://docs.vagrantup.com.
6+
7+
# boxes at https://vagrantcloud.com/search.
8+
config.vm.box = "bento/ubuntu-20.04"
9+
10+
# config.vm.box_check_update = false
11+
12+
# config.vm.network "forwarded_port", guest: 80, host: 8080
13+
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
14+
# config.vm.network "private_network", ip: "192.168.33.10"
15+
# config.vm.network "public_network"
16+
17+
# Uncomment this and set your adapter index to create a static private interface
18+
#config.vm.network "private_network", ip: "192.168.88.10", :adapter => 2
19+
20+
config.ssh.forward_x11 = true
21+
22+
# This is superfluous, as "/vagrant" is already shared to your Vagrantfile dir
23+
#config.vm.synced_folder "./data", "/vagrant_data"
24+
#config.vm.synced_folder "c:\\Users\\willis\\OneDrive", "/onedrive"
25+
26+
config.vm.provider "virtualbox" do |vb|
27+
# Customize the amount of memory on the VM:
28+
vb.memory = "4096"
29+
vb.cpus = 2
30+
end
31+
32+
# Enable provisioning with a shell script. Additional provisioners such as
33+
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
34+
# documentation for more information about their specific syntax and use.
35+
config.vm.provision "shell", inline: <<-SHELL
36+
export DEBIAN_FRONTEND=noninteractive
37+
38+
apt-get update -y
39+
apt-get install -y apt-transport-https ca-certificates curl software-properties-common
40+
41+
# Install Docker
42+
curl -fsSL https://download.docker.com/linux/"${release_name}"/gpg | apt-key add -
43+
apt-key fingerprint 0EBFCD88
44+
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
45+
apt-get update
46+
apt-get install -y "docker-ce"
47+
unset http_proxy https_proxy no_proxy
48+
usermod -a -G docker vagrant || true
49+
docker info
50+
51+
# Apt-get upgrade is disabled here because it'll hang the provisioner trying to ask questions.
52+
#apt-get upgrade -y
53+
apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
54+
55+
apt-get install -y python3 python3-pip python3-wheel python3-virtualenv
56+
57+
# Install a graphical terminal for X11 forwarding
58+
apt-get install -y xauth rxvt x11-xserver-utils
59+
60+
# If you need to modify your DNS servers, you may need the following configuration:
61+
# 1. Create this file
62+
# # /etc/systemd/resolved.conf
63+
# [Resolve]
64+
# DNS=10.90.163.133 10.90.131.133 8.8.8.8 1.1.1.1
65+
#
66+
# 2. Copy /lib/systemd/system/docker.service to /etc/systemd/system/
67+
# 3. Add '--dns <ip1> --dns <ip2> ...' to /etc/systemd/system/docker.service
68+
# 4. Run 'systemctl daemon-reload ; systemctl restart docker ; systemctl enable docker
69+
# 5. Enable tcp mode in docker daemon
70+
71+
# Install miscellaneous useful tools
72+
apt-get install -y bash-completion ldap-utils sendmail bsd-mailx
73+
74+
# Set timezone
75+
#sudo timedatectl set-timezone US/Eastern
76+
SHELL
77+
end

vagrant_openssh.conf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This is an example OpenSSH config you can SSH into your Vagrant machine on Windows.
2+
Host default
3+
HostName 127.0.0.1
4+
User vagrant
5+
Port 2222
6+
UserKnownHostsFile /dev/null
7+
StrictHostKeyChecking no
8+
PasswordAuthentication no
9+
IdentityFile C:/files/vagrant/devbox/.vagrant/machines/default/virtualbox/private_key
10+
IdentitiesOnly yes
11+
LogLevel FATAL
12+
ForwardX11 yes

0 commit comments

Comments
 (0)