Quick guide to setting up a VNC Server on CentOS

Install packages
yum install vnc vnc-server

User configuration
Assuming the user has already been configured on your system and have passwords already set.
For a user to be granted VNC access, they must have a VNC password set.
From within that user’s account (or you can su into it, e.g. su vnc_user), run:
vncpasswd
And type in your desired password and confirm.

VNC configuration
Using a text editor, open: /lib/systemd/system/vncserver@.service
Search for and replace with the actual required user name.
Example:
(ExecStart=/usr/sbin/runuser -l -c "/usr/bin/vncserver %i"
PIDFile=/home//.vnc/%H%i.pid)

Becomes:
(ExecStart=/usr/sbin/runuser -l vnc_user -c "/usr/bin/vncserver %i"
PIDFile=/home/vnc_user/.vnc/%H%i.pid)

Save and exit from the file. Run the following commands:
systemctl daemon-reload
systemctl enable vncserver@:1.service

Test setup
service vncserver@:1 start
service vncserver@:1 stop
If the service starts and stops without any errors, then you are ready to set to load at boot up.

Set to run at bootup
chkconfig vncserver on

Set the window manager
Edit your user’s VNC xstartup file: /home/vnc_user/.vnc/xstartup
Add the following to the bottom of the file:
gnome-session &
Save and close the file.

Add exception to iptables:
Edit /etc/sysconfig/iptables and add the following line:
-A INPUT -m state —state NEW -m tcp -p tcp -m multiport —dports 5901:5903,6001:6003 -j ACCEPT
Exit the file and restart iptables:
service iptables restart

Start the VNCServer:
service vncserver@:1 start

Using your client software, you can now connect via the IP address and display number. e.g. 192.168.0.5:1

Leave a Reply

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