How to install VNC on Linux ( GUI for your Linux VPS )

How to install VNC on Linux ( GUI for your Linux VPS )

 

VNC stands for Virtual network computing. It is a graphical desktop sharing system that allows you to control one computer remotely from another. VNC allows you to use your keyboard and mouse to interact with a graphical desktop environment on a remote server. In this documentation, we can discuss about how to install and configure VNC on your server.

 

Installation and Configuration

To install VNC on your server, please login to your server as root user and do the following steps.

1) Install the XFCE package.

$ yum install update all

$ yum install xfce4 xfce4-goodies tightvncserver

2) Next, you need to setup a password for your VNC server, You can use the following command to generate a password for your VNC server.

$ vncserver

Now the vncserver completes the installation of VNC by creating default configuration file ‘xstartup’

3) By default VNC will use the port 5901. This port is called a display port and is referred  by VNC as :1. First we need to stop the VNC server that is running on the port 5901. Use the following command for this.

$ vncserver -kill :1

4) Next take a backup of the xstartup file before we begin the configuration process.

$ mv ~/.vnc/xstartup ~/.vnc/xstartup.bak

5) Then open a new xstartup file using your favourite text editor. Here I am using the my favourite text editor ‘vi’.

$ vi ~/.vnc/xstartup

6) Add the following commands to the xstartup file and it will be automatically performed whenever you start your VNC server.

#!/bin/bash

xrdb $HOME/.Xresources

startxfce4 &

7) Grant execute privilege to the xstartup file then only VNC server will able to use this new xstartup file. To grant execute privileges to this file, use the following command.

$ chmod +x ~/.vnc/xstartup

8) To create a VNC service, open a new service file using the following command.

$ vi /etc/init.d/vncserver

Add the following data to the file

#!/bin/bash

PATH=”$PATH:/usr/bin/”

export USER=”user”

DISPLAY=”1″

DEPTH=”16″

GEOMETRY=”1024×768″

OPTIONS=”-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY} -localhost”

. /lib/lsb/init-functions

Please be note to replace user with the root user that you have set up.

To configure the start command to VNC, add the following block to the service file.

case “$1” in

start)

log_action_begin_msg “Starting vncserver for user ‘${USER}’ on localhost:${DISPLAY}”

su ${USER} -c “/usr/bin/vncserver ${OPTIONS}”

;;

To configure the stop command to VNC, add the following block to the service file.

stop)

log_action_begin_msg “Stopping vncserver for user ‘${USER}’ on localhost:${DISPLAY}”

su ${USER} -c “/usr/bin/vncserver -kill :${DISPLAY}”

;;

To configure the restart command to VNC, add the following block to the service file.

restart)

$0 stop

$0 start

;;

esac

exit 0

Once all the mentioned blocks are added to the service file, you can save and close that file.

9) To grant execute permission to the service script, Use the below given command.

$ chmod +x /etc/init.d/vncserver

10) start the VNC service.

$ service vncserver start

Now you can connect your VNC server by using the following command

$ ssh -L 5901:127.0.0.1:5901 -N -f -l user server_ip_address

Please make sure you replace the user and server_ip_address with the username and IP you used to connect to your server via SSH

 

If you need any further help please do reach our support department.