CentOS - How to set up XFCE4 and VNC
Intro
In this tutorial I’ll show you how to configure a remote desktop session, using XFCE 4 and VNC in CentOS 7.x.
Install needed packages
Install XFCE and X Window Manager:
sudo yum groupinstall "X Window system"
sudo yum groupinstall xfceInstall some other handy tools:
sudo yum install nano tmux xarchiver mousepad wgetInstall TigerVNC:
sudo yum install tigervnc-server tigervnc-server-minimalConfiguration
Initiate the vnc configuration:
vncserverList any vnc session:
vncserver -listIf any vnc session is available, close it (using the session number):
vncserver -kill :1Now backup the default configuration and create a new one using vim.
mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
nano ~/.vnc/xstartupPaste the configuration below.
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &Save and exit.
Next, copy the default ‘Xresources’ configuration in the user home directory.
cp /etc/X11/Xresources ~/.XresourcesAnd make the ‘xstartup’ script executable by changing its access permissions. Then run the ‘vncserver’ command again.
chmod +x ~/.vnc/xstartup
vncserverThe new vnc session is running with our default desktop XFCE.
In this tutorial, we will run the VNC server as a service. So we need to create new service file for it.
Goto the /etc/systemd/system directory and create a new service file vncserver@.service.
cd /etc/systemd/system
sudo nano vncserver@.servicePaste the following configuration there (assuming the user is called pier).
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
User=pier
PIDFile=/home/pier/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.targetSave the file and exit nano.
Now reload systemd and start the VNC server service.
sudo systemctl daemon-reload
sudo systemctl start vncserver@1.serviceIf you don’t get any error, enable the service to launch at system boot and check the service status using systemctl.
sudo systemctl enable --now vncserver@1.service
sudo systemctl status vncserver@1.serviceNow, in order to allow a remote access to CentOS, we need to open the Firewall port (in this case port 5901):
sudo firewall-cmd --permanent --zone=public --add-port=5901/tcp
sudo firewall-cmd --reload