Installing Ubuntu Server 18.04 Using Virtual Box on [Windows 7, 8 & 10]

It’s almost impossible to learn ubuntu on a real web server that is running your live application (you shouldn’t even toy with anything running a live application), which is why it’s a good idea to utilize virtualization that is indistinguishable from a real server, to put it in another perspective, it’s recommended to learn/run an experiment on a local machine.

In this guide, we would virtualize Ubuntu server on Windows 7, 8, and 10, with the help of Virtualbox, this way we would be able to run Ubuntu OS on our local machine, this should work for Mac users too as Virtualbox supports Mac.

Before anything, Let’s download VirtualBox and Ubuntu Server 18.04:

Download VirtualBox & Ubuntu Server, You can also use the below image as an aid:

1. Download VirtualBox
Download VirtualBox By Clicking on the Download button ↑
2. Download Ubuntu Server
Download Ubuntu server By Clicking on the Download button ↑

Installing VirtualBox

Since we would be virtualizing Ubuntu in VirtualBox, we don’t have to do anything with the Ubuntu file.

For now, just note down the location you downloaded the Ubuntu Server file.

Let’s install VirtualBox:

Double-click on the downloaded VirtualBox file to start the installation process:

3. Install Virtualbox

Click on the subsequent next to finish the installation, wait, untick this boxes if you don’t want VirtualBox to start whenever you restart your system or you don’t want the icon hanging in the quick launch bar:

4. Untick boxes when installing virtualbox

Having done that, you should receive a warning stating the Oracle VirtualBox Network features will reset your network connection temporarily:
5. Warning Network Interface

Please proceed and Install.

One last thing!

You would be prompted to install the VirtualBox driver:

6. Install Driver When Installing VirtualBox

Install and Finish VirtualBox Installation:

7. Finish VirtualBox Installation7. Finish VirtualBox Installation

Good! We have VirtualBox installed, it is time to create our new Virtual Machine.

If you are used to creating servers on DigitalOcean, think of Creating a Virtual Machine as your droplets, and if you aren’t used to DigitalOcean, think of creating a virtual Ubuntu operating system.

Creating A New Virtual Machine

  1. Open VirtualBox, Goto Machine and Click Add:

    8. New VirtualMachine In Virtual Box
    Click on New To Create a New Virtual Machine ↑
  2. The next thing is to choose a descriptive name, your destination folder for your new machine, and the other two would automatically update themselves base on your machine name, for example, if I have the word ubuntu in the field name, it automatically knows I want Ubuntu installed:

    9. Name and Operating System of your virtual machine
    Add server name, destination and click next ↑
  3. Use the slider to choose your memory size, 2GB or 4GB is better if your system can handle it, I’ll be going with 2GB!

    10. Choose your memory size and Click next
    Choose Memory and click next ↑
  4. The next step is to add a virtual add disk. Since this is a new machine, check “Create a Virtual Hard-disk Now” and click on Next.
    11. Add a virtual hard disk
  5. Select Virtual Disk Image as your hard disk type
    12. Hard disk type in virtualbox
  6. Choose dynamically allocated, so it can use space on your hard disk as it fills up.
    13. Dynamically Allocated in Virtualbox
  7. Select the size of the virtual hard disk, it’s 10GB by default, so depending on what you plan working on, it might be different, I’ll go with 20GB for safe measure

    14. Amount of hard disk in virtualbix
    Select the amount of hard disk and Create ↑
  8. Final Result:
    15. Create a virtual machine in virtualbox final
  9. Bonus: When working with intensive applications, it is recommended you increase the number of cores, this way your machine can perform multiple processes simultaneously, to do this, click on the Setting at the Upper section, Navigate to System at the left, click on the Processing Tab and change the number of cores to two:
    Click on Settings ↑
    Click on System at the left section ↑

    Goto Processor and Change the number to two. Click Ok ↑

Now, let’s boot up our machine and Install Ubuntu Server:

Installing Ubuntu Server In VirtualBox

Before start our server, there are a few things we need to know:

Normal Start: The Normal Start would open your Virtual Machine and displays a virtual monitor.

When you close the VM machine window, it would give you three options:

Do you want to Save the Machine State (this way, you can go back to the task you are doing), or you want to Send the Shutdown Signal (This way, your system is shut down correctly, an example is when you properly shutdown your Windows 10 system), and the Last option is Power off the Machine (This is like unplugging the power cable from a physical computer).
19. Normal Start In VirtualBox

Headless Start: This option would open your Virtual Machine with no Virtual monitor, so instead of starting the Virtual Machine from the VirtualBox GUI, it would be started from the command line, this is useful if you are planning to connect through a remote desktop or SSH connection.

Detachable Start: This is the combination of the normal and headless start, so, when you close the VirtualBox Virtual Machine window, one more option is added, which is “Continue running in the background”, this is useful if you want to close the VirtualBox VM window and allow the server to run in the background.

20. Detachable Start in VB

That said, I would be going with Detachable because sometimes I’ll want to allow the server to continue running in the background.

  1. Click on the Start Icon arrow pointing down and select Detachable:
    21. Select Detachable Start
  2. The next thing is to select the location you stored your Ubuntu server.
    22. Select Disk 1
    Choose that folder icon ↑
    22. Select Disk 2
    Click Add ↑
    22. Select Disk 3
    Find the location you downloaded Ubuntu, select and push the Open button ↑
    22. Select Disk 4
    Once again, choose Ubuntu in the list and click on Choose ↑
    22. Select Disk 5
    Click Start ↑

    Note: You might see “FATAL: No bootable medium found! System halted.” This took me longer than I thought to fix, this is what I did, Close the Virtual Machine by Clicking the X icon, then Goto Setting:

    16.Navigate to setting in your nw machin
    Go to settings

    Navigate to Storage, Click on Empty and Tick the Live CD/DVD and Click Ok, Start from Detachable and Reset the Machine

    23. Boot Live CD
    Click Empty and Click The tick the Live CD/DVD

    Reset the Machine to Start the installation, doing the above would avoid trouble with the installation:

    23. Machine reset VirtualBox

  3. Now, let install Ubuntu:
  4. The first option would be to select your preferred language, you can use the Up and Arrow to Navigate, and Enter Key to select your Language
  5. In the next section Navigate with Up or down Key To Identify Keyboard, Use the Enter Key To Select. You will be asked a few questions when you are done, click Ok to confirm
  6. This section would ask you to confirm one interface the server can use to talk to other machines, choose the default and proceed.
  7. Unless you have a proxy address you use to connect to the internet, please Leave the proxy address blank and proceed
  8. Choose the Default Ubuntu mirror address and proceed
  9. Choose use an Entire Disk
  10. Choose the Disk to Install the Server, this would be the one we created before, mine is 20Gb, so, I’ll be choosing that
  11. Review the details and click Done, you will be prompted about the warning of a disk, just Continue as this is a new OS
  12. This next stage is about the user info such as  Your name, Username, Password, e.tc, fill in the details and proceed (You can use the Tab Key to Jum to the Next field)
  13. Install OpenSSH and proceed, this way you would be able to enable secure remote access to your server, you don’t have to import SSH from Github, Select No for Now and Proceed
  14. The next option would show different snaps (Snaps are self-contained software packages that work across a range of GNU/GNU/Linux distributions.), select or deselect with the Space Bar, It depends on your use case, but we don’t need those, for now, Select Done, and wait while it installs.
  15. When the installation completes, Please Reboot
    24. Reboot Virtual Machine
  16. Once you’ve rebooted, you will be asked to remove the installation medium, many guides said Ubuntu can do that automatically, but that didn’t work for me, so remove it to play safe:25. Remove Ubuntu installation medium
  17. Once you are done removing, press Enter key and you would be prompted to log in with the User and Password you created the other time, log in with your details, Let’s configure the network so we would be able to access external Networks

Network Configuration in VirtualBox

If you’ve already logged in, please use the Command logoutand Close the machine. Once you’ve closed the machine, you will be prompted different option, Choose,  Send the Shutdown Signal, and Click Ok
26. Shutdown signal

If you are familiar with Droplets, you would know whenever we create one, we are given a server IP address, this way, you would be able to reach your server remotely from anywhere in the World or perhaps use it to access a web server. The same logic applies to this, we need to give our Machine a Static IP address, doing this would give you the full experience of running an actual live server.

To start with,

  1. Goto Setting, and Navigate to Network
  2. Tick the “Enable Network Adapter” and Select Bridged Adapter from the Dropdown, this way your Virtual Machine would be exposed to the external network the host machine(Physical) connects to.
    27. Network Adapter 1 - Brigded adpater
  3. Navigate to Adapter 2, Tick the “Enable Network Adapter and Choose “Host-only Adapter” from the dropdown, this is useful in the scenario where you would like to expose network between host machine (Physical) and your guest machine (Virtual Machine). You can even network between multiple virtual machines running on the same host with the “Host-only Adapter” you can’t just access external Networks.
    28. Network Adapater 2, Host-only Adapter
  4. Lastly, Click File -> Preference or use Ctrl + G on your keyboard, then go to Network and finally create a new one:

    29. File, preference in Virtualbox
    Create a new nat network and click OK ↑

Congratulation, you’ve just configured your Network, now start your virtual machine in a detachable mode. Once everything is in place, log in and let’s find our new server IP address.

But before we do, let’s update and upgrade necessary packages, use the below command:

sudo apt-get update
sudo apt-get upgrade

To save you a lot of headaches we would be using Putty to connect to our server, this way we would be able to copy and paste from the terminal (Don’t sweat it, you can’t copy from say your windows into the terminal if you rely on Virtualbox, Putty would help in this case), you can also Navigate Up and Down using Putty as that won’t work if you rely on your virtual machine and lastly, you would be able to perform a real web server task remotely with Putty, let’s get downloading and installing putty:

Goto PuTTy website, and download the setup:

PuTTy setup
Download the 32-bit version if you are on a 32-bit system, I am on a 64-bit system, so I would be downloading the 64-bit version

Install PuTTy on your local computer by double-clicking the putty program file,

 Putty installation wizard 1

Upon clicking on Next in the above image, click on the subsequent Next and wait for PuTTY to complete the installation.

Once that is done, search for PuTTYgen or locate it inside this folder: C:\Program Files\PuTTYand open puttygen.exe

Go to this folder on a 32-bit system: C:\Program Files (x86)\PuTTY

Open PuTTY gen

Click Generate and move your mouse randomly over the blank area. This is called the entropy of mouse motion, bring in thousands of users, and no one would ever predict your mouse movement, this means no one can reproduce your keys. If you are curious you can read this StackExchange answer .

Your key looks like this, once it is generated:
The generated ssh key alt

The good thing is that you can also password protect your ssh key, by filling the Key passphrase field, this way, when someone gains access to your computer, they will need to provide a passphrase to access it and on top of that, you must provide this passphrase every time you use this key. You can skip using a password, but this is what I will always do on a real server, so I recommending adding password as another security layer

Save your Private Keys in a folder in your local computer:

Save private key

We are getting there!

Copy the Public Key and follow the next step:

Open Putty.exe:

30. New Putty

Leave it open, and open your Virtual Machine, use the ifconfig command to show your IP address, this is mine:
31. IFCONFIG SHOW IP ADDRESS

Now, Input the IP address in Putty Hostname or IP address field, note that you can’t copy from the terminal, just write it out and input it in Putty’s field:
32. Input IP ADDRESS in putty field

Once you are done with the above steps, you can open up putty and access your server.

Note: The first time you connect to the Droplet, PuTTY security alert would pop-up asking you to confirm that you trust the server. Please choose yes to save the server host key as this is the first time you are connecting or No to connect without saving the identity.

Log in with the VM server details, and the next step is to copy the public key we generated

Now, create a new directory called .ssh and restrict its permissions using the following command:

mkdir ~/.ssh
chmod 700 ~/.ssh

mkdir – this means, make a new directory called .ssh 

~/ – This means the home directory

chmod 700 – the user can read, write and execute

The next step is to copy the public key we generated from putty into file authorized_key in the .ssh directory.

Go into .ssh directory using:

cd .ssh

create .authorized_keys & open authorized_keys file: (Note: You don’t have to create a new file, using the below command would automatically do it for you)

nano ~/.ssh/authorized_keys

Paste the public key you generated from putty in the file: (Make sure you copy everything from Top to down in the Public Key box below)

5. paste the publick you created in putty to authorized_keys file

Use Ctrl + X to exit, then press Y to save and lastly press the enter key to confirm.

Now, restrict the authorize_keys permission with the following command:

chmod 600 authorized_keys

You might get directory not found if you copy and paste the command above, type the above command by hand instead.

Restart Putty and you should be fine.

Bonus 1: Save Your Putty Session, So You Won’t Have To Type Your IP Adress Every Time You Login

It would be a pain in the ass to type the IP address in the putty field every time you plan on logging into your server, let’s save our session:

    1. Input The IP Address in Putty IP address field
    2. Save your username in the auto-login username field, so, you won’t have to input your username anytime you log in:

      33. Putty username auto-login
      Type Your Username In The auto-login field ↑
    3. Secure Login With SSH Key: Goto SSH -> Auth and Browse To The Location of your Private SSH Key
      34. SSH configuration
    4. Select The Private SSH Key and Open
      35. Select Private Key
    5. Lastly, Let’s Save Our Session, Goto Session and Type The Name of Your New Session and Hit Save:

      36. Save Session
      Type the name of your session and save ↑

Whenever you plan to log in, just click on the Saved session, putty would automatically pull in your username, all that is left is just to enter the passkey of the ssh key.
37. New Session

It would show you something like this:

Using username "user".
Authenticating with public key "rsa-key-20200114"
Passphrase for key "rsa-key-20200114":

So, just enter the passkey you use to secure the ssh.

Bonus 2: Disable Password Authentication

Since we are now using ssh to log in, there is no point using the password authentication, so let’s remove it to make our system more secure

Note: If you have any question about ssh, please comment using the comment box below

Login to your server and open the sshd_config

sudo nano /etc/ssh/sshd_config

You might be prompted to verify the user, enter your passkey and you should be presented with the below image:

38. SSHD_CONFIG

Press Ctrl + W and paste in PasswordAuthentication to find that line.

Change it’s value to no, most times, it is changed by default, but it doesn’t hurt to cross-check:

39. Pass_auth to no

Use Ctrl + X to exit, then press Y to save and lastly press the enter key to confirm.

Restart sshd:

sudo systemctl reload sshd

Bonus 3: Disable root login with SSH

The root user is the default administrative user in a GNU/GNU/Linux environment system that has the most superior privileges. The best practice is to disallow root to log in over SSH or password and create a new user that would act in place of the root (which we already have).

The main reason why you shouldn’t use root is that there are lots of bots that try to take advantage of the root, they try guessing if you are using the root user and then they enter some guessed password.

Although, the root is disabled by default when we created the Ubuntu server, but it doesn’t hurt to recheck, so, we won’t have a problem when working on an actual real server in the future.

Open sshd_config using:

sudo nano /etc/ssh/sshd_config

Find this line: PermitRootLoginUsing Ctrl + W, and you would notice it has the word – “prohibit_password”

40. Prohibit Password

You don’t have to do anything as the password has been disabled by default, in case you see “Yes”, change it to “No” or “prohibit-password

Save with Ctrl + X and restart the SSH daemon with: sudo service ssh restart

This sums up the guide on Installing Ubuntu Server 18.04 Using Virtual Box on Windows, so, whenever you want to log in, you fire up your virtual machine and you perform your various task on Putty.

I hope you enjoyed this guide, and if you have any questions, please ask. See you in the next phase!

Comment policy: Respectful and beneficial comments are welcome with full open hands. However, all comments are manually moderated and those that doesn't relate with what the passage is saying or offensive comments would be deleted. Thanks for understanding!

Leave a Reply

Your email address will not be published. Required fields are marked *