Professional Documents
Culture Documents
7
RAJ JULY 25, 2014 28 COMMENTS CENTSO 7, REMOTE, REMOTE DESKTOP, RHEL 7, VNC
The following simple guide helps you to setup the VNC server on RHEL 7/CentOS
7 machines, VNC help to share the desktop with the other machines which have a client
installed. VNC server and client are not installed by default, you need to setup the vnc
server manually.
Before installing the VNC server, let us install Gnome desktop.
[root@server ~]# yum groupinstall "GNOME Desktop" "Graphical Administration Tools"
Copy the VNC server configuration file to /etc/systemd/system/ for configuring the system
service. While copying, you can mention which port it should listen. By default VNC server
listens on 5900, but if you setup port-offset for VNC; we can run a service on a sub-port of
the default port 5900. For example, if we mention port 5, it will be accessible on 5905. You
can connect the VNC server by specifying ipaddress:sub-port (192.168.2.109:5 or
192.168.2.109:5905)
[root@server ~]# cp /lib/systemd/system/vncserver@.service
/etc/systemd/system/vncserver@:5.service
At the end of the file, you will find the lines like below.
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
PIDFile=/home/<USER>/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
Replace <USER> with your real user, in my case, i replaced with a user called raj .
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/sbin/runuser -l raj -c "/usr/bin/vncserver %i"
PIDFile=/home/raj/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
Add firewall rules to allow the VNC connection, the following rule is set as per the port-offset
mentioned in the previous step.
[root@server ~]# firewall-cmd --permanent --zone=public --add-port=5905/tcp
[root@server ~]# firewall-cmd --reload