Install Xfce VNC remote desktop on CentOS 7

Xfce is a lightweight linux desktop environment. You can install Xfce on a remote server or virtual machine, connect to it using VNC to use it as a desktop.

xfce remote desktop

To install Xfce, enable EPEL repo

yum install -y epel-release

Install Xfce

yum groupinstall Xfce

You can see other groups available with command “yum grouplist”.

Insall vnc server

yum install -y tigervnc-server

Creating User

We need to create a normal linux user to use with Xfce. Using it as root is not recommended.

To create user, run

useradd -m --shell /bin/bash serverok

Replace “serverok” with whatever username you want to use.

Configure VNC server

Change to the user we created before

su - serverok

To create initial vnc config files and set password, run

vncserver -fg

We used -fg option to keep vncserver in forground. vcnserver will ask you to set password, this will be used to connect to VNC server.

When i run “vncserver -fg” on CentOS, it exited with error. If it keep running, press CTRL+C to stop vnc server.

If you run with out -fg option, you can stop vnc server with command

vncserver -kill :1

Edit file

vi /home/serverok/.vnc/xstartup

Replace contents of this file with following

#!/bin/sh

unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
/etc/X11/xinit/xinitrc
/bin/startxfce4

Now you can start vncserver manually with command

vncserver -fg

You will be able to connect to VNC server with YOUR_SERVER_IP:1

Auto start VNC server

Following need to be done as user root.

Edit file

vi /usr/lib/systemd/system/[email protected]

Find

ExecStart=/usr/bin/vncserver_wrapper  %i

Replaced with

ExecStart=/usr/bin/vncserver_wrapper serverok %i

reload systemctl

systemctl daemon-reload

Enable vncserver to start on boot

systemctl enable vncserver@:1.service

Start vncserver

systemctl start vncserver@:1.service

Open port in firewall

You need to open VNC port in firewall. vnc ports start at 5900, for :1, it will be 5901.

[root@centos7 ~]# netstat -lntp | grep vnc
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      1951/Xvnc           
tcp        0      0 0.0.0.0:6001            0.0.0.0:*               LISTEN      1951/Xvnc           
tcp6       0      0 :::5901                 :::*                    LISTEN      1951/Xvnc           
tcp6       0      0 :::6001                 :::*                    LISTEN      1951/Xvnc           
[root@centos7 ~]# 

If you are using firewalld, you can open port 5901 with

firewall-cmd --zone=public --add-port=5901/tcp
firewall-cmd --zone=public --add-port=5901/tcp --permanent

firewall-cmd command is run 2 times as first command only make changes in current session. second command with –permanent option make changes permanent, but that only happens after you reload firewalld or reboot server. Running command 2 times make the changes permanent and apply changes to current session.

See VNC, Remote Desktop

Need help with Linux Server or WordPress? We can help!

Leave a Reply

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