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.
To install Xfce, enable EPEL repo
1 |
yum install -y epel-release |
Install Xfce
1 |
yum groupinstall Xfce |
You can see other groups available with command “yum grouplist”.
Insall vnc server
1 |
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
1 |
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
1 |
su - serverok |
To create initial vnc config files and set password, run
1 |
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
1 |
vncserver -kill :1 |
Edit file
1 |
vi /home/serverok/.vnc/xstartup |
Replace contents of this file with following
1 2 3 4 5 6 |
#!/bin/sh unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS /etc/X11/xinit/xinitrc /bin/startxfce4 |
Now you can start vncserver manually with command
1 |
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
1 |
vi /usr/lib/systemd/system/vncserver@.service |
Find
1 |
ExecStart=/usr/bin/vncserver_wrapper <USER> %i |
Replaced with
1 |
ExecStart=/usr/bin/vncserver_wrapper serverok %i |
reload systemctl
1 |
systemctl daemon-reload |
Enable vncserver to start on boot
1 |
systemctl enable vncserver@:1.service |
Start vncserver
1 |
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.
1 2 3 4 5 6 |
[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
1 2 |
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