# Ubuntu setup

# Installation tips

  • When prompted to update to the new installer, do so.

  • Ubuntu Server (minimized) works best, but once it's finished you need to install extra stuff not usually found in server distros, including basic ones such as bash-completion, nano, ping and similar. It's not a big deal though.

  • When prompted, disable LVM. It's rarely used anyways. Even more so for this use-case.

  • When prompted, enable OpenSSH server. This will make our life easier later.

# Post-installation steps

Once you've installed Ubuntu, there are some steps we need to follow to make our own WSL2 install work correctly. Such steps are outlined here.

# Enable OpenSSH to login remotely

Open a command prompt and run this to enable port forwarding from localhost:22 to the VM at port 22, so we can connect to it with ssh localhost:

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm "WSL2" natpf1 "TCP22,tcp,,22,,22"

In the same command prompt, run ssh user@localhost to connect to your VM (replace user with the username you set in the Ubuntu install step, of course)

# Add SSH key to enable automatic login

To enable automatic login, you need an SSH key. This can easily be done using Putty. Download and then install it, then follow these steps:

  1. Run PuTTY Key Generator (puttygen.exe)
  2. Click Generate
  3. Save all your keys (usually a good idea. Setting a passphrase isn't recommended)
    1. Click Save public key
    2. Click Save private key
  4. Click Conversions menu
  5. Click Export OpenSSH key. Save it as user.key or something. We'll need it later.
  6. In the box below the text "Public key for pasting into OpenSSH authorized_keys file", there should be a bunch of text starting with ssh-rsa .... In that box, do this:
    1. Right-click
    2. Select all
    3. Right-click
    4. Copy
    5. Paste and save this somewhere in a text file. You'll need it later.

Now that you're there, run this to enable your current user to use the SSH key we generated. Of course, replace LONG_KEY_GOES_HERE with the value you got from the PuTTY Key Generator:

echo "ssh-rsa LONG_KEY_GOES_HERE" > ~/.ssh/authorized_keys

# Configure the new host in your SSH config

This step is optional, but it's nice to have. If you don't have it already, create a file as %USERPROFILE%\.ssh\config and add the following contents:

Host *
    AddressFamily inet
    ServerAliveInterval 10
    StrictHostKeyChecking no

Host wsl2
    HostName localhost
    User user
    PasswordAuthentication false
    IdentityFile "C:\Users\User\.ssh\keys\user.key"

Of course, replace user with your username and "C:\Users\User\.ssh\keys\user.key" with the full path of the user.key file we saved in PuTTY Key Generator, step 5.

# Set up apt-get and update your distro

In this last step, you'll configure apt-get to be a little bit faster, and get your distro up-to-date. This will make our life easier later:

sudo apt update
cat <<EOF > 99parallel
APT::Acquire::Queue-Mode "access";
APT::Acquire::Retries 3;
EOF
sudo mv 99parallel /etc/apt/apt.conf.d/99parallel
sudo apt update
sudo apt dist-upgrade -y

# Disable IPv6

For some reason, Ubuntu 21.10 is a little bit slow waiting for network to be configured even if we already have IPv4 configured. We can speed up this process by editing /etc/default/grub and changing the following lines with this content:

GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1"
GRUB_CMDLINE_LINUX="ipv6.disable=1"

Then run sudo update-grub and reboot the VM.

# Install VirtualBox Guest Additions

In the VirtualBox window, click Devices -> Install Guest Additions CD Image... , then do this:

sudo apt install -y build-essential
sudo mkdir /media/cdrom
sudo mount -t iso9660 /dev/cdrom /media/cdrom
cd /media/cdrom
sudo ./VBoxLinuxAdditions.run

Then reboot the VM.