Tuesday, May 18, 2010

Remote Desktop for Linux Using VNC

Here, I'm telling you a easy way to do remote desktop from Linux. You can access Linux machine through another machine with Linux Distribution or from Microsoft Windows as well.
The method used for this is VNC (Virtual Network Computing).
Before, trying anything, you need to know this. The machine that you use to access a Remote machine is called the client. And the Remote Desktop is the server. In VNC what happens is, we install a VNC server software in server side (Remote machine) and access it though a client software.
Let's get in to business. It's pretty easy. Here I'm telling doing remote desktop for a Linux machine from any environment. I did this Ubuntu 10.04 Lucid Lynx but applicable to other distros as well.
  • In Server (Remote machine), first install vnc4server package from Synaptic Package Manager. (Go to System -> Administration -> Synaptic Package Manager) Search for vnc.

  • Install the package named vnc4server. Or, in terminal,
sudo apt-get install vnc4server
  •  Then, go to client machine and install xvnc4viewer. By terminal or from Synaptic. This is accesses the server and displays the virtual desktop.
apt-get install xvnc4viewer
Now the installation is over. How to run?
  • First, create a server instance in the Remote machine you want to connect to by, entering command 'vnc4server' in terminal. Your output would look similar to below if everything went smooth.
kasun@uom:~$ vnc4server
New 'uom:1 (kasun)' desktop is uom:1
Starting applications specified in /home/kasun/.vnc/xstartup
Log file is /home/kasun/.vnc/uom:1.log
NOTE: In the first run it will ask to set a password. Give a strong password to it as anyone with it can access your server if it's turned on.
You can create any number instances as you like. They will be numbered as <host>:<id> which will be distinguised by a port number. You can know the port number by looking at the log file from ~/.vnc/<host>:<id>.log. ex. cat ~/.vnc/uom\:1.log . You need port to access the server instance. Port number is generally 5901 or nearby. And server IP address (do ifconfig)

Now go to Client.
  • Run xvnc4viewer .  It will ask for the server to connect to: give it in the format <ip>:<port> ex. 10.100.1.100:5901
  • OR, there are Microsoft Windows alternatives available such as RealVNC. Download it from here. (Filling the form is not compulsory!)
    If nothing went wrong, now a window will be opened with the remote machine desktop. Here I'm running a Red Hat Linux Instance from my Ubuntu Lucid Lynx machine. :-)

    A comment about your experience or anything is appreciated. Good luck!