Howto-Linux vncserver
By Erik Rodriguez
This article is a howto for running vncserver on Linux. These examples are specific to Red Hat Enterprise Linux, but shoshould work on any type of Linux system.
What is vncserver?
VNC stands for virtual network computing. it was originally developed by at&t as a way to administer machines without using the console. if you have used Windows Terminal Services (RDP), VNC will seem very familiar.
Why use vncserver?
In Linux, everything can be done from a shell. However, there may be a time when you need to access the machine as if you were at the console.
Getting started
You will need several things to get started:
- Root privledges
- VNC client software (TightVNC, you can download it here .)
- A good password!
As I mentioned above, this example is done with RHEL, which comes standard with vncserver installed. To start the vncserver simply invoke the following commands:
[root@roswell etc]# service vncserver startStarting VNC server: [ OK ][root@roswell etc]# [root@roswell etc]# vncpasswdPassword: Verify: [root@roswell etc]#[root@roswell etc]# vncserverNew 'roswell:1 (root)' desktop is roswell:1Starting applications specified in /root/.vnc/xstartupLog file is /root/.vnc/roswell:1.log[root@roswell etc]#
So what did we do there? First, we started the vncserver service. it may or may not have already been running on your system. next we set a password to access the VNC desktop. when you set the password, you will not see any characters on the screen, and you must enter the password twice. you will only need to do this the very first time you run vncserver. the password will be saved in the Linux filesystem, and you can change it at any time by invokingVncpasswdCommand again. Last, to activate the VNC desktop, we simply invokedVncserverCommand. Notice the output; the desktop is named "Roswell: 1" which can also be replaced via the machines IP address.
Connecting
Assuming you already installed TightVNC or another VNC client, enter the desktop Name:
You can replace the server name with an IP address if you are logging in from outside your lan. Remember, if you are using NAT port 5900 must be forwarded to your vncserver.
Upon successful connection, you will be prompted for a password. You will then see a terminal screen that will allow you to execute commands:
Vncserver in runlevel 5 (KDE or GNOME)
If you are new to Linux, running VNC server with a terminal isn't going to do you much good. you might want to have a menu-driven GUI like windows. no problem. follow these steps:
First, we are going to assume that vncserver is running under the root user, as shown with the example above. for this example, I will be editing my vncserver to enter gnome. you can specify a KDE Desktop if you have KDE installed on your server. make sure you are in the root directory.
[root@roswell ~]# ls -a. cacti-0.8.6c.tar.gz .gnome2_private .lftp queue.dat temp.. client.cfg .gnupg machinedependent.dat .recently-used Templates.config FAHlog-Prev.txt .gstreamer-0.8 .metacity .rhn-applet.cache .themes.cshrc FAHlog.txt .gtkrc .mozilla .rhn-applet.conf .thumbnails.bash_history Desktop .fonts.cache-1 .gtkrc-1.2-gnome2 .rnd .Trash.bash_logout .dmrc .gconf .ICEauthority .mysql_history scripts.bash_profile .eggcups .gconfd .icons .nautilus .sh_history.viminfo .bashrc .bashdevl .esd_auth .gnome php-4.11.ssh .vnc cacti-0.8.6c .gnome2 install.log[root@roswell ~]# cd .vnc[root@roswell .vnc]# lspasswd roswell:1.pid roswell:2.pid roswell:3.pid roswell:4.pid roswell:5.pid roswell.area51.lan:1.pidroswell:1.log roswell:2.log roswell:3.log roswell:4.log roswell:5.log roswell.area51.lan:1.log roswell.area51.lan:2.logxstartup[root@roswell .vnc]# vi xstartup
Using VI (Vim) to edit the xstartup file, make sure your file matches this one:
#!/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/.Xresourcesxsetroot -solid greyvncconfig -iconic &xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &startx &
Notice that the last line is "startx &" as this command will launch gnome upon login via vncserver. if you are using a KDE Desktop, the line "startkde &" shoshould Replace the last line.
Logging in, you will be presented with a gnome or KDE Desktop.
Shown above is a GNOME desktop on Red Hat Enterprise Linux 4.