Configure Remote Desktop - Setup VNC to connect to Remote Desktop

It involves installing softwares like GNOME which take time. Hence video is preshot.

As our remote server is running using Centos 7, if we can set up desktop utilities and launch desktop we might be able to set up additional softwares at much better pace. Also when we set up clusters we might want to validate some of the services using browser. Port forwarding from our server might get complicated depending on the services running.

To login to Remote Desktop using a user on a remote Centos 7 server we need to have a service called VNC Server running for the user. Here are the steps to create user training and then set up VNC Server for user training.

Perform all these steps as root unless it is explicitly specified.

  • If it throw warning like this -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory , then update /etc/environment with these values

LANG=en_US.utf-8 LC_ALL=en_US.utf-8

  • Create user useradd -c "User training Configured for VNC Access" training
  • Set password passwd training
  • Add user to sudoer usermod -g wheel training
  • Update visudo by enable nopasswd and disabling passwd sudo authorization. This will facilitate not to enter password when ever user training try to run a command as sudo
  • Install gnome desktop yum groupinstall -y "GNOME Desktop"

Installing components for GNOME Desktop will take some time. While GNOME Desktop is being installed let us check the concepts of Remote Desktop.

  • Reboot the server reboot or init 6
  • When we install CentOS, we should start with minimal installation and take care of the necessary components
  • Unlike on our PC with OS like Windows, we might not need GUI for daily activities
  • Minimal installation will only give access through CLI (we have been connecting to CLI using SSH)
  • But at times we might want to have remote desktop
    • To access some of the services with in the PC
    • To install trial versions where they ask us to register to provide download link
    • Some softwares such as Oracle require GUI for setting it up
  • Pre-requisites for remote
    • We need to have softwares like GNOME Desktop for providing GUI
    • We need to have some server process (vnc server process) running for user on the host to maintain Remote Desktop connection between client and the host
    • tigervnc-server is one such software which can provide capability to run separate daemon process for each user who want to connect to GUI
    • Each process for each user on host has to run on different port
    • Port should be opened in firewall
    • We need to setup VNC Viewer on our PC from which we want to connect to Remote Desktop on remote host
  • After reboot install tiger VNC server yum install -y tigervnc-server
  • Configure VNC Service for the user created (training)
    • Generic Service unit file is located under /lib/systemd/system/vncserver@.service
    • Copy this for the new user created cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
    • Replace with training in this file sed -i 's/<USER>/training/g' /etc/systemd/system/vncserver@:1.service
    • Reload the new configurations systemctl daemon-reload
    • Enable vnc server systemctl enable vncserver@:1.service
    • Add rule to firewall firewall-cmd --permanent --zone=public --add-port=5901/tcp
    • Reload firewall to add new rule firewall-cmd --reload
    • Login as training su - training
    • Setup VNC password vncserver
    • Exit from training exit
    • Reload configurations systemctl daemon-reload
    • Start VNC server for training systemctl restart vncserver@:1.service
  • Now you can connect using VNC Viewer client or chrome extension