Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions

  




 

 

How to remotely display and control a Linux desktop from a Windows or Linux system using VNC


It is relatively straightforward to display and access a Linux desktop from a system anywhere else on a network or the internet by using Virtual Network Computing (VNC). This can be achieved regardless of whether, for example, that system is running Linux, Windows or Mac OS X.. The even more impressive thing about this is that it can be set up for free with only a little time and knowledge.

There are three key areas to establish a VNC connection to a desktop environment (such as KDE or GNOME) on your Linux system:

1. A VNC server installed and running on your Linux system.

2. A VNC viewer client installed on the system on which you want to display your Linux desktop.

3. A secure shell (ssh) connection between the two systems.

In this VNC How To Guide we will take you step by step through the process and have you driving the Linux desktop home or office Linux system while you sit drinking coffee infront of a Windows laptop in your local WiFi-enabled Starbucks.

Obtaining a VNC Server and Client

There are a number of ways to get VNC - some free and some not so free. First check that VNC is not already installed on your Linux system. Most recent releases of Linux such as Redhat Linux and Fedora Core will come with VNC rpms on the installation CDs.

If you do not already have VNC then we recommend TightVNC which can be obtained for free from:

          http://www.tightvnc.com/download.html

Once you have VNC installed you will need to specify a password to protect access to the VNC server. To do this run:

       vncpasswd

and enter a suitable password.

Starting and Stopping the VNC Server

The next thing you need to learn how to do is start and stop the VNC server. Start the VNC Server with the following command:

          vncserver

Assuming no problems are encountered vncserver will output a message that looks something like:

    New 'myhost:1 (src)' desktop is myhost:1

    Creating default startup script /home/neil/.vnc/xstartup
    Starting applications specified in /home/neil/.vnc/xstartup
    Log file is /home/neil/.vnc/myhost:1.log

The key information here is that vncserver has started up an X server as display :1 on system "myhost" and that it has created a sub-directory called .vnc in the home directory of the user that started the server containing a startup script called xstartup. In addition it has also created a log file that can be reviewed to diagnose any problems should the server have failed to start.

To stop the VNC server simpy run the following command:

    vncserver -kill :1

where the :1 matches the display that was indicated when vncsever started up. This will display something along the lines of:

    Killing Xvnc process ID 15609

A useful point to note here is that process being killed in called Xvnc. Xvnc is the the actual VNC server process. The vncserver command we ran to launch the VNC server is actually a shell script that sets up the environment prior to launching the Xvnc process.

Configuring the Desktop Environment to be Launched by VNC

The next step is to configure what gets started up when the VNC server is launched. As outlined previously the first time a user starts vncserver the .vnc directory is created in their home directory. Change directory to $HOME/.vnc and load the xstartup file into an editor. It should appear as follows:

#!/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 &

These commands perform some basic tasks such as setting the background of the X window, launching an X terminal window and finally launching the twm window manager. The twm window manager is a very good lightweight window manager. Another good lightweight manager is the Motif Window Manager (mwm). Those familiar with the Common Desktop Environment (CDE) on Solaris, HP and IBM systems may want to change to the "twm &" to "mwm &" in the xstartup script.

Another option is to launch the GNOME or KDE desktop environments. To launch the GNOME desktop environment change the twm line in xstartup to:

    gnome-session &

Similarly to launch the KDE desptop environment change the line to:

    startkde &

Feel free to add other commands to the xstartup script. For example if you would like your favorite mail tool or development IDE to launch automatically then xstartup is the place to do it.

Installing the VNC Viewer Client

Having selected the desktop environment you would like to use the next step is to install the client side VNC viewer. On Linux and Unix systems the viewer is called vncviewer. Check to see if you already have VNC installed on the client system. If it is not already installed or you are running on Windows we once again recommend that you download TightVNC from:

    http://www.tightvnc.com/download.html

Establishing a Secure Shell connection between the two systems

For security reasons it is recommended that the VNC communication take place through an encrypted secure tunnel connection. On Linux or Unix this can be achieved using the ssh command. On Windows we recommend that you use PuTTY which is freely available from:

      http://www.putty.nl/download.html

By default the VNC server will communicate on port 59xx where xx represents the display number. If vncserver announces that it is running as display :1 then the port being used is 5901. If it tells you it is display :2 then port 5902 is being used and so on.

Supposing you have the VNC running on display :1 on a system called myhost then you would need to establish an ssh connection as follows:

Linux:

    ssh -L 5901:localhost:5901 myhost

Windows using PuTTY:

1. Start PuTTY, enter the hostname or IP address of the system running VNC server. In our example this is "myhost"

2. Set the "SSH" toggle.

3. Select the "Tunnels" option from beneath SSH in the "Category" list and enter the following information:

Source port: 5901
Destination: myhost:5901

4. Save the profile you have entered by selecting "Session" from the Category list, entering name in the "Saved Sessions" text field and press "Save"

5. Press the "Open" button to establish the secure connection.

In both the case of Linux and Windows you will be prompted for a password for the user under which you are logging in.

Launching the VNC Viewer Client

Assuming all went smoothly with the VNC server installation and that you have established a secure shell connection using the appropriate port (in our example 5901) you can now launch the VNC viewer client. On Linux or UNIX this is done as follows:

    vncviewer localhost:1

On Window using TightVNC simply launch the TightVNC viewer and enter localhost:1 into the Connection details dialog and press "OK".

In both cases you will prompted for a password. This is the password that you specified when you ran vncpasswd earlier. After short delay you should see a large window appear dispalaying your Linux desktop and you can work with it as if you were sitting in front of your console.

 
 
  © Copyright 2005-2010 Linuxtopia. All Rights Reserved.