Wednesday, October 12, 2011

Remote Linux Desktop With VNC


While I manage most of my Linux servers through command lines, sometimes I rather use a desktop manager like Gnome. When I need to access my desktop remotely, I mainly use VNC (or Virtual Network Computing). VNC provides remote control software which lets you see and interact with desktop applications across any network. You can install the server software on about any platform like MS Windows, Linux or Mac OS. To access the remote system, you can either use the VNC client or a web browser with java enabled.
VNC (or Virtual Network Computing) has been around for a long time now. I remember using it when I first got my first job as a programmer almost ten years ago and it already been out for sometime back then.

Installing VNC Server On Linux

For this tutorial, I will be using CentOS 5 but installing VNC Server on CentOS 4 or RHEL shouldn’t be no different. Of course we’ll take for granted that X is installed and working properly.
Installing the VNC server is pretty easy. You can do this using YUM:
# yum install vnc

Configuring VNC Server

You can configure multiple displays for different users, resolutions, etc. To do this, simply edit /etc/sysconfig/vncservers using your prefered editor. The example above shows you how to create a display for the root user:
VNCSERVERS=”2:root”
VNCSERVERARGS[2]=”-geometry 800×600 -nolisten tcp”
The first line specifies the display number and the local user for who this display will be available. Note that VNC will add 5900 to this display number as the service port. So for example, if you specify display number 2, it will be accessible on port 5902 for the VNC client. As for the HTTP client, it will add 5800 to the display number (http://myserver:5802).
The second line specifies the parameters for display #2. To get more information on VNC server arguments, see the manpages (man vncserver).
Now that you’ve created a display, you now need to set the password for the user(s) you’ve specified. You can do this using the vncpasswd command when logged on as the desired user. Simply type vncpasswd at the command prompt and you will be required to enter and confirm a password. This will store the newly created password into ~/.vnc/passwd.
You can now test the VNC server by starting it manually:
# service vncserver start
For this example, I’ve installed the VNC client from http://www.realvnc.comon MS Windows to access my Linux desktop remotely. I won’t go into details about installing the VNC client on MS Windows, it’s pretty basic. You can also get a VNC viewer for Linux over at http://www.tightvnc.com/.
Now that your VNC server is running, launch the client and enter the IP address of the remote host followed by the port number (display number + 5900).
VNC Viewer On MS Windows
This is what your remote desktop should look like:
VNC Desktop
It sucks huh? Right. Because there’s no desktop manager loaded. To make sure that X is started upon connection to the VNC server, you must edit ~/.vnc/xstartup so that the xstartup script is invoked instead of twc. On the last line of ~/.vnc/xtartup, replace twc by 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 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &
xstartup &
Now simply restart the VNC server (service vncserver restart) and try to access it remotely once again.
VNC Desktop - Gnome
Now that’s better!
All that’s left to do is to have the VNC server started at boot time. To do this, simply issue the command:
# chkconfig vncserver on
VNC server will always be listening on the ports you’ve configured through/etc/sysconfig/vncservers.

No comments:

Post a Comment