I’m a huge fan of VNC. It’s a great way to get X access to a server, without having to install X on your PC. VNC aka Virtual Network Computer, also has an advantage that the X session is running on the target machine, which means if the network drops you don’t loose what you are working on. This is huge for anyone on a questionable network that doesn’t want to loose what they are working on.
With later releases of Oracle Linux 8, VNC has changed a bit. It now can run as a service, and also gives you more control over user passwords and what VNC port is assigned to what user.
Install is simple, first start off as root and run these commands. Also, the commands are the SAME on ARM and X86.. at least when you use Oracle Linux. I know I keep saying this, but folks still think ARM is rocket science.. yet it’s all but the same a Oracle Linux that you already know on x86! As a note, selinux is disabled on this system.
First install the VNC sever and related configuration files;
dnf install tigervnc-server -y
Next, you need X on the server, the easiest way is to install a group of RPMs, since I mainly work on severs I usually install the GUI components with the following command;
dnf -y groupinstall 'Server with GUI'
Next, we need to set the system to use a graphical login, and that is done with the following commands;
systemctl set-default graphical.target
systemctl isolate graphical.target
Up next, the firewall. I don’t recommend disabling the firewall, but instead add the VNC ports to the config. VNC uses port 5901 onwards. Session 1 is 5901, session2 5902 etc. For simplicity you can add a range of ports with the following commands;
firewall-cmd --permanent --zone=public --add-port 5901-5910/tcp
The latest version of tigervnc server uses systemctl to start and stop sessions. To do this, you need to copy a blank config to a session ID. In the following example, I setup sessions 1 and 2.
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:2.service
One last step as root, we need to assign a user to a session, to do this you need to edit a config file, and put in a line for each session number mapping it to a user. The format is :$NUMBER=$USER
then add in the line. In this example I map :1 to erik, and :2 to oracle
Next su – to the user that will be using the session. As the user you will need to set the vnc password with the vncpasswd command.
Next, we will set the session to use gnome with the following command
echo 'session=gnome' > ~/.vnc/config
Personally, I also like more resolution than the default, you can change the default session resolution to 1920×1080 with the following command;
echo ‘geometry=1920x1080’ >> ~/.vnc/config
Now, exit the session, and go back being root.
You can now start the session with the following command;
systemctl start vncserver@:1.service
Next, I like VNC to run as a service, so when the system reboots, the VNC session automatically starts. This being said, the system does take up a few more resources… so if you are tight on RAM/CPU don’t do that.
systemctl enable vncserver@:1.service
As a note, VNC does not encrypt the session, but you can easily forward the ports via ssh.
Now kick off your favorite VNC client; put in the $SERVER:$SESSION in the remote host
Put it the password you set previously
And you now have a nice, reliable, and recoverable X session!
If you have any questions or comments, please us the comment section in the BLOG.