VNC With Oracle Cloud
SSH-ing into OCI (Oracle Cloud Infrastructure) servers is a breeze. Simply download the private key file, and load it into your favorite SSH client software. Boom! You're in and off you go!
But what if your application needs... GUI
Personally having a difficult time running GUI applications on my Free-Tier server, I found that a VNC connection would be necessary. After looking online for tutorials or general help, I quickly realized there was no straight answer. People said things that contradicted one another, and none of their ideas worked. In the end, I figured it out. I write this in hopes of helping those few people like me struggling with similar problems.
Supplies
- You will need a running OCI server instance (Linux in this case (e.g. Ubuntu))
- A working SSH connection to set up the VNC software and perform necessary installs.
- A VNC viewer for testing and eventually establishing connection when appropriate.
- This tutorial...
Connect to Your Server Via SSH
If you have not already established a connection with your server, now is the time to do so! If you already have, skip to the next step.
- Using your favorite SSH client software (I will be using PuTTY for Windows) enter the IP address and upload the proper authentication credentials (Private key file)
- If you are using PuTTY, you will need to use the built-in PuTTYgen software that comes with PuTTY during install. The .key file provided by OCI does not work by default in PuTTY. Using PuTTYgen, you can convert it.
- Open PuTTYgen and load the .key file provided by OCI during the server instance creation.
- Follow the pop-up when it appears.
- Click Save private key button to save it to your computer. This will now work in PuTTY.
- Now, open (if not already opened) PuTTY software and load the private key. This can be done by navigating thru the tree menu in PuTTY to Connection > SSH >Auth > Credentials
- Once the file is loaded, be sure the correct IP address is saved (in the main session tab)
- Save the PuTTY config with a name if desired.
- Press Open to initialize the connection to the server...
- If a message appears warning you about how the key is not in the cache, ignore it and click Accept connection.
Install the VNC Server
Once connected to your server via SSH, we can start running commands to install the VNC server.
Run the following command to update and upgrade your system packages/ dependencies. (This step IS important!)
sudo apt-get update && sudo apt-get upgrade
Install the VNC server and lightweight display manager. We will use TightVNC here as it is lightweight and easy to use.
sudo apt-get install lxde-core lxterminal tightvncserver
Set up the VNC server password by running: (Type "n" if it asks if you want a view-only password)
vncserver
End that VNC instance to configure it:
vncserver -kill :1
Set Up VNC Startup Script
Copy the existing startup command as a backup just in case:
mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
Create a new startup script: (This one will be actually used)
nano ~/.vnc/xstartup
Add the following lines to the file and save it (Save it by pressing CTRL+X, y, Enter)
#!/bin/bash
xrdb $HOME/.Xresources
startlxde &
Make the script executable:
chmod +x ~/.vnc/xstartup
Configure Oracle Ingress Rules (VCN)
In order for the VCN (not to be confused with VNC lol 😂) to allow external connections on port 5901 (default VNC port) you will need to configure it appropriately. This can be tricky so follow this Step-By-Step to ensure proper configuration!
- Log into the Oracle Cloud dashboard and navigate to the Virtual cloud networks (VCN) page.
- Click the main VCN link. For example vcn-20240307-2120
- Click the main subnet link. For example subnet-20240307-2120
- Click the Default Security List link. For example Default Security List for vcn-20240307-2120 (omg... 🙄)
- And finally you are at the Ingress Rules page of your VCN! Click the "Add Ingress Rules" button and follow the configuration specified below. (This is very important!)
- Stateless: Checked
- Source Type: CIDR
- Source CIDR: 0.0.0.0/0
- IP Protocol: TCP
- Source port range: (leave-blank)
- Destination Port Range: 5901
- Description: VNC_SETUP
Need help? Look here for the official Oracle docs: https://docs.oracle.com/en-us/iaas/developer-tutorials/tutorials/apache-on-ubuntu/01oci-ubuntu-apache-summary.htm
Configure Ubuntu Firewall
Once you have finished setting up the Ingress Rules, jump back to the SSH window to execute a couple more commands on you server to get it working with the VNC setup.
Run the following commands to let the Ubuntu iptables know that port 5901 should allow traffic:
sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 5901 -j ACCEPT
sudo netfilter-persistent save
Need help? Look here for the official Oracle docs: https://docs.oracle.com/en-us/iaas/developer-tutorials/tutorials/apache-on-ubuntu/01oci-ubuntu-apache-summary.htm
Start VNC Server and Connect to It
Great! You've done it! 🥳👏 All you need to do now is start up the server and connect.
In the SSH terminal, type:
vncserver
or for additional configuration use this variation: (example suitable for limited-resource servers)
vncserver :1 -geometry 1024x768 -depth 16
Now, open up a VNC viewer/ client on your local machine (I used RealVNC, a popular choice) and enter the Server's IP address in the top bar.
Hit enter, and the connection should be starting. If you see warnings about encryption, press Continue.
When prompted to enter your password, it is the same one you entered back in step 2. It is NOT the same one as your server password (unless you made them the same...)
You should now see your Server's Desktop! Congratulations! You've done it! 🥳😁🙌👌👏
Troubleshooting - Screensaver Password Problem
Q: Screen saver shows up asking for password! Idk what it is!!!
A: Try entering your server's password or the VNC's password.
If that doesn't help, you can disable it by doing the following:
Open the LXDE autostart file:
nano ~/.config/lxsession/LXDE/autostart
Look for a line that starts with @xscreensaver and comment it out by adding a # at the beginning:
#@xscreensaver -no-splash
Kill any running xscreensaver processes:
pkill xscreensaver
Restart the VNC server:
vncserver -kill :1
vncserver :1 -geometry 1024x768 -depth 16
If you are still experiencing issues, please leave a comment down below and I will respond ASAP!!
Other Problems
If you have any other issues during this process, just leave a comment and I'll respond ASAP!