Set up a Virtual Machine on VirtualBox.

Install

For Windows and Mac OS, follow the installation guide

For Ubuntu:

sudo apt-get install -y virtualbox

Make sure to enable Virtualization (e.g., VT-x, and optionally VT-d) in BIOS.

Setup VM (Ubuntu 22.04 LTS)

Download Ubuntu 22.04 LTS ISO file (ubuntu-22.04.1-desktop-amd64.iso) from the download page.

Add a new Virtual Machine with Type Linux and Version Ubuntu (64-bit).

Set the memory size depending on your use case, I suggest you can use half of your host memory. This can be easily modified later.

Create a virtual hard disk with dynamic size, set an upper bound depending on your use case. I suggest setting 100-500 GB. If your disk size is too small, you may need to change it afterwards, and the process is non-trivial.

Insert the ISO file to the VM and start the installation process. You should have a fresh Ubuntu VM after installation.

Depending on your region (e.g., Taiwan), you may need to change your Language/Format in Language Support, you don’t need to donwload anything. Simply choose English / United States, and use Apply System-Wide and reboot. See this post for more details.

If everything looks fine, shutdown the VM (Power off the machine). Add a snapshot, name it with Fresh Install.

Install VirtualBox Guest Additions

Boot the VM, insert VirtualBox Guest Additions ISO by Devices > Insert Guest Additions CD image..., you may need to download it if you haven’t downloaded it.

You can install it easily by double-clicking the VBoxWindowsAdditions.exe file if you’re using a Windows VM.

For Linux, run the following:

sudo apt update
sudo apt install -y build-essential
cd /media/$USER/VBox_GAs_6.1.34
sudo ./VBoxLinuxAdditions.run

You may now remove the Guest Additions CD from Machine > Settings... > Storage.

Reboot and you should be able to change the screen resolution of the VM by resizing the window.

If everything looks fine, shutdown the VM (Power off the machine). Add a snapshot, name it with Install build-essential & VirtualBox Guest Additions.

Shared Clipboard

Click Devices > Shared Clipboard > Bidirectional. Verify you can copy-and-paste between host and VM. You may need to use Ctrl+Shift+V if pasting to the Terminal.

If everything looks fine, shutdown the VM (Power off the machine). Add a snapshot, name it with Setup Shared Clipboard (Bidirectional).

If the Shared Clipboard somehow stops working afterwards, you may fix it with the following command:

pkill 'VBoxClient --clipboard' -f & sleep 1 && VBoxClient --clipboard

or simply reboot the VM.

See this post for more details.

Shared Folders

Click Devices > Shared Folders > Shared Folder Settings.... Click the add icon, and then add a shared folder by choosing Folder Path > Other..., create a folder to be shared (e.g., /home/$USER/Desktop/Shared (host)).

Folder Path: /home/$USER/Desktop/Shared
Folder Name: Shared
Read-only: False
Auto-mount: Yes
Mount point: /home/$USER/Desktop/Shared
Make Permanent: Yes

replace $USER to your host username and VM username respectively, and click OK.

In Linux, since the mounted folder’s owner group is vboxsf, add the current user to that group by:

sudo adduser $USER vboxsf

and reboot.

See this post for more details.

If you forgot adding yourself to vboxsf, you may encounter the Permission denied error when cd into the folder.

If everything looks fine, shutdown the VM (Power off the machine). Add a snapshot, name it with Setup Shared Folder and Add user to vboxsf group.

Open SSH Server & Fail2Ban

sudo apt-get install -y openssh-server
sudo apt-get install -y fail2ban

Open SSH Server allows to connect into VirtualBox through SSH.

To prevent bruteforce attack, fail2ban can be installed.

To further protect your SSH server, disable password authentication by following this post and use SSH keys instead.

Vino VNC Server & Tunneling

(TODO)

Port Forwarding

Machine > Settings... > Network > Adapter 1 > Advanced > Port Forwarding, add a new rule as follows:

Host IP: 127.0.0.1
Host Port: 10022
Guest IP: 10.0.2.15 # Use `ip a` to get your VM IP
Guest Port: 22
(Others): (Default)

ZSH and Oh-My-ZSH

You may use the script provided in this post

Updated:

Posted: