GICT knowledge base
How to install VNC on Linux ( GUI for your Linux VPS )
Published
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.
Related guides
How to Restrict an SSH Key to One Command
Restrict an SSH key to one command with authorized_keys options. Protect the command and check that unwanted shell and forwarding access are denied.
Linux and CommandsSelf-Hosted Video Processing With FFmpeg: A Practical Guide
Learn how to self-host video processing on a VPS using FFmpeg, with practical commands for conversion, compression, thumbnails, and automated workflows.
Linux and CommandsHow to use nohup: Commands in Linux That Survive Terminal Closes
Keep commands running after you close the terminal. nohup examples with wget, Python, rsync, and Docker on any VPS.
Linux and CommandsHow to Fix “Too Many Open Files” Error on Linux Servers
Learn how to fix the "Too Many Open Files" error on Linux servers by understanding file descriptors, adjusting limits, and diagnosing leaks effectively.
