It has been a few releases of Fedora since I have installed a VNC server, and it appears that there is a great deal of confusion on the internet about how to do this… so I’m writing up what worked for me, so that some other poor soul can get this working. The end goal is to have a VNC server that: runs on Fedora 19, persists across reboots, and allows access to the XFCE4 Desktop Environment.
NOTE: I don’t have Gnome/KDE even installed. This presents a challenge (not really) because the majority of the Fedora scripts are written to detect and work with Gnome/KDE and nothing else. In fact, if you dont have Gnome/KDE, you will usually end up failing back to TWM (yikes!).
First, we need to install the tigervnc-server:
[root@localhost ~]# yum install tigervnc-server
Loaded plugins: langpacks, refresh-packagekit
Resolving Dependencies
--> Running transaction check
---> Package tigervnc-server.x86_64 0:1.3.0-7.fc19 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
tigervnc-server x86_64 1.3.0-7.fc19 updates 196 k
Transaction Summary
================================================================================
Install 1 Package
Total download size: 196 k
Installed size: 481 k
Is this ok [y/d/N]: y
Downloading packages:
tigervnc-server-1.3.0-7.fc19.x86_64.rpm | 196 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : tigervnc-server-1.3.0-7.fc19.x86_64 1/1
Verifying : tigervnc-server-1.3.0-7.fc19.x86_64 1/1
Installed:
tigervnc-server.x86_64 0:1.3.0-7.fc19
Complete!
For the moment we are going to configure the VNC service to be running on a sub-port of the VNC service port (port 5900). In this example, we will be creating port-3 (offset from 5900). This means that port 5903 will need to be opened, but when we connect to the system from a remote host using the VNC protocol, we will only have to specify something like “10.16.2.22:3”.
To create a configuration for port-offset 3, lets perform the following copy:
[root@localhost ~]# cp /lib/systemd/system/vncserver@.service \
/etc/systemd/system/vncserver@:3.service
Once you have a port-specific configuration file, open the file in your favorite editor, and you will see lines like the following:
ExecStart=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
PIDFile=/home/<USER>/.vnc/%H%i.pid
Replace the “<USER>” tags with the appropriate user. In the case of “root” (which is what I used) you have to make sure you change the PIDFile path to be inside “/root/.vnc”. In the end, my configuration file looked like this:
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
After configuring, we need to make sure the Fedora 19 firewall is prepared to allow VNC traffic in. To do this as a one-off for run-time only, you could use the following command:
[root@localhost ~]# firewall-cmd --zone=public --add-service vnc-server
However, if you want to have the firewall setting persist across reboots, you need to make that change permanent. To do so, just add the permanent option, like so:
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service vnc-server
If we were to start up our VNC server now, we would be able to log in (as I insinuated earlier), but would find ourselves dropped into a TWM desktop environment. I have nothing against TWM, but since the goal of this guide was to drop us into an XFCE4 desktop environment, TWM will simply not do.
Based upon soo many things out there on the interwebs, you may be tempted to edit some scripts, but I’m here to tell you that there is an easier way. The “/etc/sysconfig/desktop” file!
If your Fedora 19 system is like mine, then that file does not exist, and you need to create it. If that file does exist on your system, then there is one check you need to do: make sure “DESKTOP” is not specified in the file. I do that via a simple in-place sed-deletion:
[root@localhost ~]# sed -i '/DESKTOP/d' /etc/sysconfig/desktop
Then once we have eliminated any possibility that another desktop variable might be defined, we need to define another variable in this file. What you will see below is simply a way of defining the variable “PREFERRED” to be the full-path to the “startxfce4” program. Feel free to hard-code it instead of the lookup that I am doing:
[root@localhost ~]# echo 'PREFERRED="$(type -p startxfce4)"' \
>> /etc/sysconfig/desktop
Finally, we should setup a password for the VNC user to log in with. To do so, we first need to switch to that user, and then run “vncpasswd”, like so:
[root@localhost ~]# su root
[root@localhost ~]# vncpasswd
Password:
Verify:
That is 100% of the configuration necessary to start your VNC server. Now all we need to do is actually start it. (and since we will probably reboot at some point, lets make the service persistent too)
systemctl enable vncserver@:3.service
systemctl start vncserver@:3.service
At this point, (assuming your network is working) you should be able to access this VNC server from another host. To do so, I simply open VNCViewer on my Windows box, specified “10.16.2.22:3”, typed username/password… and VOILA!
I really hope this makes life easier for somebody. (Most likely me, the next time I try to remember what I did)