Creating a Linux VM in OCI and Remotely Accessing its GUI in NoMachine

Jared Bach
15 min readSep 3, 2021
What I wanted to do to my computer before there was a solid tutorial blog on how to actually create a Linux VM in OCI and remotely access its GUI in NoMachine.

Please note: This blog assumes that you already have a working tenancy in OCI and a working compartment that you can place your resources in. This blog also assumes that your local computer is running MacOS. While the majority of the steps in this blog are most likely the same, regardless of what your local machine is, I just wanted to make a note of this at the beginning of this blog to minimize any confusion.

Today, we are going to be creating a Linux VM in OCI and then installing a GUI in the VM that we will be able to access using NoMachine. The purpose of this blog is to walk through all of the steps associated with this process. While this process may seem straight forward at a glance, it is actually quite complicated. In fact, I nearly threw my computer out the window trying to do this. I was just about halfway through completing this objective when the programs inside my VM began to crash and commands began to fail. I realized that I desperately needed to backtrack. Of course, because there were no centralized instructions on how to do any of this anywhere on the internet, I decided to just scrap the VM that I was working in and start from the beginning — this time I was going to document the entire process. Then, nobody has to go through the agony and pain that I went through if they are also trying to do this.

Without further ado, let’s get started.

Sign-in to your OCI tenancy

Let’s start by logging into our OCI tenancy. To do this, navigate to this website. You should see a page that looks like this.

Where it says “Cloud Account Name” circled in red above, enter your tenancy name and then click “Next.”

Click “Continue” to sign-in using SSO.

Click “Oracle SSO” to sign-in using SSO. You will then, finally, be brought to the page where you will input your SSO credentials to sign-in to OCI. The screen will look like this.

Input your SSO credentials, and if necessary, complete the 2-factor authentication. At long last, you will arrive in the OCI Console.

Creating the Linux VM instance

Don’t pull out the champagne and celebrate yet — we are just getting started. Once you are in the OCI console, navigate to the hamburger menu in the left-hand corner of the screen. Under “Compute,” click “Instances.”

After clicking “Instances,” your page will look like something like what I have below. Circled in red, you will see “Compartments.” I have already created a compartment and selected the one that I wish to place the instances that I will be creating into. If you do not have a compartment, please create one. I will not be covering how to create a compartment in this blog.

Once the compartment you would like to place your instances into is selected, we are finally going to begin creating our instances. Select the “Create Instance” button circled in red above. Your page should now look something like this.

Here is how you are going to configure your instance:

  • Name: select a name for your instance. It can be whatever you want. I am naming my instance “JIB-Linux_VM.”
  • Compartment: select the compartment that you wish to place your instance into. The name of my compartment is JaredBachCMP.
  • Placement: keep this as the default, AD 1
  • Image: keep this as the default, Oracle Linux 7.9
  • Shape: click “Shape” and change the number of OCPUs from the default of 1 to 8. Everything else can be left-as is.
  • Networking: under “Primary Network,” select the “Create a new virtual cloud network” option and name your new virtual cloud network (VCN). I named my VCN “JIB-VCN.” Make sure that you have the correct compartment selected. Under “Subnet,” select the “Create new public subnet” option and name your new public subnet. I named mine “JIB-Subnet.” Make sure that you have the correct compartment selected. Leave the CIDR block and the public IP address as-is.
  • Add SSH keys: select the “generate a key pair for me” option and save the private key to your computer. You do not need to worry about the public key. I recommend creating a folder on your desktop called “LinuxKey” and saving the key there for now. Trust me, this will make things easier later-on. I also renamed the file as “LinuxKey.key.”
  • Boot volume: keep this as the default and do not select any options.

Once you have everything configured correctly in your instance, click the “Create” button. Mazel tov. You just created a Linux VM. Give the instance some time to provision. Once it is done provisioning, your screen will look like this. Make note of the “Public IP address,” which I have circled in red. You will need this to connect to your virtual machine using SSH.

Please note that the public IP address in this picture is different than the one that I will be using for the rest of this blog. It is also different than the one that you will be using when you create an instance.

Connecting to your virtual machine using SSH on your local computer

Remember when I told you to create a folder on your desktop called “LinuxKey” and to place your newly created “LinuxKey.key” file in that folder? Great — navigate to that folder on your desktop and right-click on it. At the bottom of the right-click menu, you will see the option to create a “New Terminal at Folder.” Select that option. Your terminal screen should look something like this on your local computer.

First, you are going to want to change the permissions so that only you can read the file. You can accomplish this by using the following format.

chmod 400 <private_key_file>

In our case, our code should look like this.

chmod 400 LinuxKey.key

After running this, nothing should happen. The next snippet of code is the moment we have all been waiting for — we are going to connect to our virtual machine. To do this, use the following format.

ssh –i <private_key_file> <username>@<public-ip-address>

In our case our code should look like this.

ssh -i LinuxKey.key opc@158.101.102.28

Just remember to change your public IP address to whatever your public IP address is inside the OCI Console, which I circled in red a few steps ago. After running this line of code, your terminal will say something like this.

Please note that the public IP address in this picture is different than the one that I will be using for the rest of this blog. It is also different than the one that you will be using when you create an instance.

Write “yes” and hit enter. You are now connected to your Linux VM instance. Write “clear” inside your terminal to clear your screen. You terminal should look like this.

If you wish to also increase the size of your boot volume, I wrote a blog post on how to do this here.

Creating a new sudo user

Now that we are logged into our Linux VM instance, we need to create a new user. This user, however, must have sudo privileges. We can accomplish this in a few, simple steps. First, decide what you want your user’s name to be. I am going to name my user “jaredb.” To add jaredb as a user, you will need to run the following command.

sudo useradd jaredb

To assign a password to our newly created jaredb user, run the following command. When prompted, create a password that you can remember. I recommend placing your password in a password manager, but that is your decision.

sudo passwd jaredb

After you successfully update your password, your terminal screen should look something like this.

We now need to make jaredb a sudo user. To do this, we need to edit the /etc/sudoers file. Never edit the sudoers file in a normal text editor. This could lead to simultaneous editing and corrupt files. We can edit the sudoers files by using the visudo command.

sudo visudo

Your terminal should look something like this.

Press Shift+G to navigate to the bottom of the document. Press the letter “i” on your keyboard to begin editing the document. Create a new line at the bottom of the document and add the following text.

Defaults timestamp_timeout=1800

This will set your sudo timeout to 1800 seconds (30 minutes), so you will have sudo permissions for 30 minutes after you execute the first command. If you prefer a different interval, enter that value in seconds instead.

You will then want to navigate up in the document to this snippet of text.

Underneath where it says root, paste this snippet of text.

jaredb  ALL=(ALL)       ALL

This snippet of text will give jaredb root privileges. Of course, replace jaredb with whatever you decided to name your user. Your terminal should now look like this.

Once you complete this task, hit the ESC button, scroll down to the bottom of the document and type the following text. Then, hit enter.

:wq

This sequence will save the file and exit the editor. We now need to switch users so that we are working under jaredb and not opc. We can do this by running this command.

su - jaredb

We have now granted sudo privileges to jaredb.

Create a folder in the directory

While we are still in our terminal, for convenience sake, let’s create a folder. We will need this folder in future steps.

First, we need to log-in as root. We can do this with the following code.

sudo su -

Please note that you may need to restart the session and sign-in as opc to run as root. Then, this command should work. After you logged into the terminal, type the following line of code to create a folder called NoMachine.

mkdir /NoMachine
chmod 777 /NoMachine

Installing NoMachine on MacOS

Wouldn’t it be much easier to work with Linux if we had a graphical user interface (GUI) to interact with? I definitely think so. So — let’s create one. While there are many different ways that you can go about creating a GUI for your Linux VM, I have decided to use NoMachine to help me do this.

On your MacBook, you are first going to want to install XQuartz. You can download and install this program here. Simply complete the install through the package manager. It should take no more than a few minutes for the installation to be completed. Once the installation is completed, you should see this screen.

Next, you are going to want to install NoMachine, which can be downloaded here. Select NoMachine for Mac. Simply complete the install through the package manager. It should take no more than a few minutes for the installation to be completed. Once the installation is completed, you should see this screen.

Be sure to also open your system preferences to give NoMachine access to accessibility features on your Mac. Once the installation finishes, you should receive a pop-up that prompts you to do this, like the one below.

After opening your system preferences, simply unlock your Mac accessibility options in the bottom right hand corner of the window. Then, check nxnode in the list on the right of the window.

When you are finished, click the lock in the bottom right hand corner of the window again. You can now close the window. You will now see the NoMachine app listed with your other applications in your launchpad and in your application folder.

Take a drink if you need to at this point — I know it is tricky…and it is only going to get trickier. Take a deep breath, it is going to be okay. Let’s keep pushing forward. You now have NoMachine installed on your local computer, in our case, this is our MacBook. We now need to install NoMachine on our Linux VM. We can do this through the terminal.

Installing NoMachine on Linux VM

In a browser on the MacBook that you are working on, you need to download the Linux installation package for NoMachine. You can download it here. Select the RPM download for Linux -x86_64, amd64. Save the RPM file that you just downloaded in the LinuxKey folder on your local desktop.

Navigate to the LinuxKey.key on your desktop and right-click on it. At the bottom of the right-click menu, you will see the option to create a “New Terminal at Folder.” Select that option. Your terminal screen should look something like this on your local computer.

To transfer the Linux RPM file that we downloaded to our MacBook to the Linux VM, we will run a code in our terminal with this format.

scp -i <name_of_private_key> <name_of_file_you_want_to_upload_to_linux> <username> @ <public_ip_address>:/<location_in_linux_you_want_file_to_go>/

In our case, we will want our code to look something like this.

scp -i LinuxKey.key nomachine_7.6.2_4_x86_64.rpm opc@158.101.102.28:/NoMachine/

Copy and paste this code into your terminal. Make sure you change the public IP address to whatever your VM’s public IP address is. The, hit enter. After this is completed, your terminal should look like this.

The RPM file has now been uploaded to the Linux VM. You can close this terminal window now. In a new terminal window, reconnect to your Linux VM if you closed the terminal that you were using in previous steps. If it still open and you are logged in as root, go back into that terminal. The terminal screen should look like this.

In the terminal, type the following code to navigate to the NoMachine directory that we created in a previous step.

cd /NoMachine

Then, type ls into the terminal. You should be able to see the file that we uploaded into the NoMachine folder from our MacBook. Your terminal screen should look something like this.

To install the RPM package on your Linux VM, run the following line of code in your terminal.

rpm -ivh nomachine_7.6.2_4_x86_64.rpm

The installation should not take more than a few minutes. Once the installation is completed, before continuing onto the next step, while we are still root, we are going to want to also install a graphical user interface using yum to the Linux VM.

Installing GUI on Oracle Linux 7 VM

Before continuing, make sure that your terminal looks like this and that you are logged-in as root.

First, we are going to want to update yum. Run this line of code in your terminal. If prompted, write “y” in the terminal to continue the update process. This could take a few minutes. Be patient.

yum update

When the updates are complete, your terminal screen will look like this.

Next, run this code. This will install the GUI. If prompted, write “y” in the terminal to continue the installation process. This could take a few minutes. Be patient.

yum groupinstall "Server with GUI"

When the updates are complete, your terminal screen will look like this.

Lastly, enable the GUI on system start-up by running this code.

ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target

Once this is complete, shut down your session in the terminal. We are now going to need to navigate back to the OCI Console. Find your way back to where your instance is located in OCI and reboot the instance. If prompted with the option to “force reboot the instance by immediately powering off, then powering back on,” select this option.

Let it reboot in the background. You do not need to wait for the reboot to be completed before moving onto the next steps. The reboot, nonetheless, should not take more than a few minutes. At this point, we just need to make one last small configuration to our VCN before we can officially connect to our Linux VM through the GUI.

Opening ports in our VCN

If we tried to connect to our VM in NoMachine, we would not have any success because a connection would not be able to be established. In order to allow a connection to be established, we need to open up port 4000. We can do this easily in the OCI Console.

In your browser, navigate back to the OCI Console and log-in. Navigate to the hamburger menu in the left-hand corner of the screen. Under “Networking,” click “Virtual Cloud Networks.”

Once you are inside the Virtual Cloud Networks, make sure that you are in the correct compartment. Click on the VCN, circled in red below. It is the VCN that we created earlier in this tutorial.

After clicking on the VCN, your screen should look like this. Click on security lists, circled in red below.

After clicking on “Security Lists,” then click on “Default Security List for JIB-VCN.”

Once you are inside the “Default Security List for JIB-VCN,” click-on the “Add Ingress Rules” button.

Add the following ingress rule to your security list. This will open up port 4000 and essentially allow our VM to be accessed over the internet through NoMachine on our local computers. Change the IP Protocol to SSH and the Destination Port Range to 4000. The description is optional. When you are done, click the blue “Add Ingress Rules” button.

You should now see the new ingress rule we added to our security list. We are almost done. The next step is to log-into the Linux VM from the local NoMachine that we installed on our local Mac earlier in this tutorial.

Logging into our Linux VM from our local NoMachine application

And now — the moment of truth. Let’s try to connect to our Linux VM from the local NoMachine application on our MacBook. First, open NoMachine on your MacBook. A window should pup up that looks like this.

Check “Don’t show this dialog anymore” and then click “OK” to continue. Your screen should now look like this.

Click “Add” to add a new computer to NoMachine. Your screen should now look like this.

You can name your connection whatever you would like. I am going to name mine “Jared’s Linux VM.” In the “Host” box, put your public IP address from the OCI Console. This is the same address that we used when we would use SSH to create a connection with our Linux VM. When you are done with this step, click the back arrow button. Your screen should now look like this.

Click “Jared’s Linux VM” to create a connection to it. Your screen should now look like this.

Sign-in to the VM using the credentials that you created in the terminal in a previous step — for me, that user was jaredb. If you would like, you can click the option to “Save this password in the connection file.” Then, click log-in. After some loading, your screen should now look like this. Keep clicking “Ok” until your log-in screen loads.

At long last you will have arrived at the log-in screen. Pat yourself on the back.

Click the user and log-in with the password that you used earlier to log into NoMachine. Once you are logged-in, follow the prompts on the screen until you arrive at your desktop. At long last, you have arrived.

Stop here and take a break. A celebration is in order.

--

--

GenZ business techie 👨🏻‍💻📉 lover of dogs and hummus 🇮🇱