03-20-2019, 06:01 PM
CentOS 7 with XFCE & VNC
This is a brief installation instruction for VNC with the XFCE desktop environment on CentOS 7 Core (a.k.a server version without a GUI). I have written this guide using a CentOS 7.6.1810 Core x86_64 (minimal installation) VM based on Virtualbox (Ubuntu 18.04 LTS host). Depending on the virtualization technology you are using you might not have the same experience.
I'm not responsible for bricked system. I recommend to perform this installation on a clean and update to date system. Fiddling around on a system that has been modified before is mostly a nightmare and almost always a guarantee for something to go really wrong.
Let's start now.
1. Connect to your server and login as root.
2. Update your system using the command below:
I would also recommend to reboot the server after installing all updates. And after that continue with step three.
3. Install and enable the EPEL repository using the command below:
4. Install the XFCE desktop environment using the command below:
Depending on the Internet connection and the performance of the server the installation process will take a while now. Just wait until it finishes the download and installation. In my case over 280 packages had to be downloaded and installed. Even on a Intel Core i5 system running on SSDs only it takes a little while.
5. Install the VNC server using the command below:
6. Run the vncserver to generate the first configurations using the command below:
You might be asked for a password. At this point you can set a password for VNC access. So type in a password you want to use to protect the VNC access to your server. You can also set a view-only password if you like.
8. Rename the existing xstartup file into xstartup.backup using the command below:
9. Create a new xstartup file with nano or any other text editor (following code is using nano):
10. Paste the following code into the file
Save the content and exit the text editor. In nano you can use CTRL + O to save the content and CTRL + X to exit the text editor.
11. Set execution permission for the xstartup file using the command below:
12. Copy the X11 Xresources folder to the root home folder using the command below:
13. Run the vncserver again to start a session using the command from step six.
14. Now you can use the command below to check running sessions:
You should see a session running at :1.
15. Create a service for the vncserver using the command below:
16. Paste the following code into the file:
You can adjust the resolution from 1280x800px to what you prefer. Save the file and exit the text editor.
17. Reload the systemd service daemon and start the vncserver service with the commands below:
You can use the command from step 14 to check if the session is running.
18. Enable the vncserver.service to be executed at boot:
19. The VNC server will now listen on IP:5901. You need to open that port in your firewall:
20. Connect to the server with a VNC client at IP:5901. Enter the password your set at step six.
21. Once logged in your will see a screen like this:
Click on "Use default config" and it will generate a default taskbar and dock.
No idea about that XFCE PolicyKit error. Just click on OK and carry on I guess.
That's it I guess.
What have I learned? Don't attempt this on any system where you have no been working on before. You never know what exactly has been done to that system and what leftovers of possible failed attempts of previous installations there are. I could end up in a disaster like it did for me when I tried to help someone while on this clean VM it works without any big issues.
On the other hand it might be just crap OpenVZ that causes these issues. I'm not going to go into detail here. All I can say is that the system where I tried to help with has been modified before and had serve issues when attempting to install the GNOME environment (hence why I went for XFCE as that worked). So it had its fair share of issues before I even touched it. Everything actually worked until I rebooted it and it didn't come back up (neither SSH nor VNC). Would probably been half so bad if the server had a control panel I could use to start a emergency console and fix the issue that caused the server not to come back up.
P.S: I'm not really a big fan of CentOS and VNC. Sure it is really dangerous to run VNC as root. Just a tutorial for the installation though. If you plan on using this seriously I would suggest to create a special user for this and adjust a few things like the username in the service config and the PID directory. Also when running vncserver the first time you need to do it as the special user. So you bascially need to perform the whole setup as that special user and only use root where necessary (package installation, setting up permission, creating the service config and such tasks).
WARNING: If you use this guide on OpenVZ keep the following in mind! The desktop environment installs a network manager. This network manager is not capable of supporting and configuring network adapters on OpenVZ! What will happen is that it will override the network adapters with nonsense and the network will stop working after the first reboot. To fix this you have to disable the network manager service and reconfigure the network of the VPS through SolusVM (it's literally a button called "Reconfigure Network" in the control panel). After that the network connection should start to work again and also VNC should work.
Disable the network manager service using these two commands:
After that use the network reconfiguration button in SolusVM.
TL;DR: OpenVZ is whack crap.
This is a brief installation instruction for VNC with the XFCE desktop environment on CentOS 7 Core (a.k.a server version without a GUI). I have written this guide using a CentOS 7.6.1810 Core x86_64 (minimal installation) VM based on Virtualbox (Ubuntu 18.04 LTS host). Depending on the virtualization technology you are using you might not have the same experience.
I'm not responsible for bricked system. I recommend to perform this installation on a clean and update to date system. Fiddling around on a system that has been modified before is mostly a nightmare and almost always a guarantee for something to go really wrong.
Let's start now.
1. Connect to your server and login as root.
2. Update your system using the command below:
Code: (Select All)
yum update -y
I would also recommend to reboot the server after installing all updates. And after that continue with step three.
3. Install and enable the EPEL repository using the command below:
Code: (Select All)
yum install epel-release -y
4. Install the XFCE desktop environment using the command below:
Code: (Select All)
yum groupinstall "XFCE" -y
Depending on the Internet connection and the performance of the server the installation process will take a while now. Just wait until it finishes the download and installation. In my case over 280 packages had to be downloaded and installed. Even on a Intel Core i5 system running on SSDs only it takes a little while.
5. Install the VNC server using the command below:
Code: (Select All)
yum install tigervnc-server tigervnc-server-minimal -y
6. Run the vncserver to generate the first configurations using the command below:
Code: (Select All)
vncserver
You might be asked for a password. At this point you can set a password for VNC access. So type in a password you want to use to protect the VNC access to your server. You can also set a view-only password if you like.
8. Rename the existing xstartup file into xstartup.backup using the command below:
Code: (Select All)
mv ~/.vnc/xstartup ~/.vnc/xstartup.backup
9. Create a new xstartup file with nano or any other text editor (following code is using nano):
Code: (Select All)
nano ~/.vnc/xstartup
10. Paste the following code into the file
Code: (Select All)
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &
Save the content and exit the text editor. In nano you can use CTRL + O to save the content and CTRL + X to exit the text editor.
11. Set execution permission for the xstartup file using the command below:
Code: (Select All)
chmod +x ~/.vnc/xstartup
12. Copy the X11 Xresources folder to the root home folder using the command below:
Code: (Select All)
cp /etc/X11/Xresources ~/.Xresources
13. Run the vncserver again to start a session using the command from step six.
14. Now you can use the command below to check running sessions:
Code: (Select All)
vncserver -list
You should see a session running at :1.
15. Create a service for the vncserver using the command below:
Code: (Select All)
nano /etc/systemd/system/vncserver.service
16. Paste the following code into the file:
Code: (Select All)
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
User=root
PIDFile=/root/.vnc/%H:1.pid
ExecStartPre=-/usr/bin/vncserver -kill :1 > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :1
ExecStop=/usr/bin/vncserver -kill :1
[Install]
WantedBy=multi-user.target
You can adjust the resolution from 1280x800px to what you prefer. Save the file and exit the text editor.
17. Reload the systemd service daemon and start the vncserver service with the commands below:
Code: (Select All)
systemctl daemon-reload
systemctl start vncserver.service
You can use the command from step 14 to check if the session is running.
18. Enable the vncserver.service to be executed at boot:
Code: (Select All)
systemctl enable vncserver.service
19. The VNC server will now listen on IP:5901. You need to open that port in your firewall:
Code: (Select All)
firewall-cmd --permanent --zone=public --add-port=5901/tcp
firewall-cmd --reload
20. Connect to the server with a VNC client at IP:5901. Enter the password your set at step six.
21. Once logged in your will see a screen like this:
Click on "Use default config" and it will generate a default taskbar and dock.
No idea about that XFCE PolicyKit error. Just click on OK and carry on I guess.
That's it I guess.
What have I learned? Don't attempt this on any system where you have no been working on before. You never know what exactly has been done to that system and what leftovers of possible failed attempts of previous installations there are. I could end up in a disaster like it did for me when I tried to help someone while on this clean VM it works without any big issues.
On the other hand it might be just crap OpenVZ that causes these issues. I'm not going to go into detail here. All I can say is that the system where I tried to help with has been modified before and had serve issues when attempting to install the GNOME environment (hence why I went for XFCE as that worked). So it had its fair share of issues before I even touched it. Everything actually worked until I rebooted it and it didn't come back up (neither SSH nor VNC). Would probably been half so bad if the server had a control panel I could use to start a emergency console and fix the issue that caused the server not to come back up.
P.S: I'm not really a big fan of CentOS and VNC. Sure it is really dangerous to run VNC as root. Just a tutorial for the installation though. If you plan on using this seriously I would suggest to create a special user for this and adjust a few things like the username in the service config and the PID directory. Also when running vncserver the first time you need to do it as the special user. So you bascially need to perform the whole setup as that special user and only use root where necessary (package installation, setting up permission, creating the service config and such tasks).
WARNING: If you use this guide on OpenVZ keep the following in mind! The desktop environment installs a network manager. This network manager is not capable of supporting and configuring network adapters on OpenVZ! What will happen is that it will override the network adapters with nonsense and the network will stop working after the first reboot. To fix this you have to disable the network manager service and reconfigure the network of the VPS through SolusVM (it's literally a button called "Reconfigure Network" in the control panel). After that the network connection should start to work again and also VNC should work.
Disable the network manager service using these two commands:
Code: (Select All)
systemctl stop NetworkManager
systemctl disable NetworkManager
After that use the network reconfiguration button in SolusVM.
TL;DR: OpenVZ is whack crap.