Installing VNC and GNOME on Linux

A graphical user interface (GUI) is not available with our line of Linux dedicated servers.  The base operating system we offer, CentOS, does not come with one, and most Linux server flavors aren't packaged with a VNC or GNOME interface due to the resources they require.  However, a GUI can make managing a Linux server easier if you can VNC into a server and access it like a "regular" computer.

What is VNC?
It stands for Virtual Network Connection, and it is a graphical desktop sharing system.  It's similar to RDP on a Windows server.

Like RDP for Windows, you'll need to configure it on the server, and you'll need to have the VNC client downloaded on your computer in order to view the server.

To get started, download the VNC viewer at http://www.realvnc.com/cgi-bin/download.cgi (to get the VNC Viewer for Windows, download the "VNC Free Edition Viewer for Windows" executable).

Next, you'll need to log into your dedicated server as the root user (If this is your first time logging into your server, please read article 990)

Update YUM
First, lets update YUM so we have all the latest repositories. Type the following command.
yum update
This may take some time, depending on how outdated your repositories are, do not cancel out of this.

Install GNOME
Once the update is finished, you can install the GNOME interface. This way, you have the desktop interface when you connect to your server via VNC. Just type the following command.
yum groupinstall "GNOME Desktop Environment"
This may ask you to agree to the size of the downloaded file, just hit the "y" key.

Install VNC Service
Now we can work on installing and configuring VNC. Type the following command to install VNC. Again, it will ask you to confirm the download size of the file, just hit the "y" key for yes.
yum install vnc-server
VNC/System users
VNC will use the system users to login to the server, so for this example, we will be creating the VNC setup for your Primary Site User Admin, (for the sake of this article, we will call him "ctuser", but this is the user that you use to login to putty before you switch into the root user). Do keep in mind that we will have to switch between the root user, and the ctuser, we will be using the "su" command to do this, as explained in the putty article mentioned above.

So now you need to switch your user from root to your Primary Site User Admin.
su ctuser
Now type the following command to create the passwd file that VNC uses to authenticate the user when you login via VNC
vncpasswd
It will then ask you for your password; twice to confirm. After this is complete, su back into root with the following command.
su -
Modify the servers VNC Configuration
Now we need to edit the "vncservers" file, so VNC will have the configurations to the users that can login.
To edit this file, you will be using the nano command. So type the following (once you hit enter, you will be modifying the file)
nano /etc/sysconfig/vncservers

Now that you are editing this, do keep in mind that you need to use the arrow keys to navigate through the file. So go down to the bottom, and add the following lines, (replacing ctuser with your user).
VNCSERVERS="1:ctuser"
VNCSERVERARGS[1]="-geometry 800x600"
You can change the resolution if you wish, but do realize that the bigger the resolution, the slower it will be, due to the fact it needs to load all the graphics.

Once you have added those lines, you can exit nano by hitting "Ctrl x" on your keyboard, it will ask you if you want to save changes, hit the y key on your keyboard, then hit enter again to save the file.

Create and edit xstartup scripts
To automatically generate the xstartup scripts, you must first start VNC, then stop VNC. So type the following commands.
service vncserver start
service vncserver stop
Now you must login as the user you are creating the VNC profile for again (ctuser).
su ctuser
Now change your directory to get into the VNC directory for the user, type the following command.
cd /home/ctuser/.vnc

nano xstartup

#!/bin/sh

# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &
Add the "while true" condition statement below to assure that an xterm is always present, and uncomment the other lines below it, as instructed in the file. The result will look like this, (Changes in bold):
#!/bin/sh (-)
# Add the following line to ensure you always have an xterm available.
( while true ; do xterm ; done ) &
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &
Once this is complete, switch back into root, with the following command:
su -

Start your VNC server
Type the following to start VNC.
service vncserver start
Open your Firewall for VNC
By default, VNC has 2 ports, 5901 and 5801. The 5901 is used for the VNC viewer that you download from realvnc.com, 5801 is the java interface you can use to VNC into the server via the browser. So type the following commands as root.
iptables -I INPUT -p tcp --dport 5901 -j ACCEPT
iptables -I INPUT -p tcp --dport 5801 -j ACCEPT
Now Save the IP tables, type:
iptables-save
Testing VNC
Almost done! To test your VNC server, bring up your VNC Viewer that you downloaded, and connect to your IP with the port 5901 (for an example, I will use 123.123.123.123), so we would be connecting to 123.123.123.123:5901

This should prompt you for a password, use the password you typed for the user, and then hit enter. To test it in your browser, visit "http://123.123.123.123:5801"

Enable VNC on startup
By default, VNC won't start up on the server when it's rebooted, so to enable it on startup, type the following command.
chkconfig vncserver on
Your server is now fully configured with VNC and GNOME.

Add Feedback