Configuring VNC to auto-start
How to auto start VNC server in Red Hat Linux after system reboot?
My testing environment is a machine running on Red Hat Enterprise Linux 4 Update 4, with the bundled VNC Server (i.e. vnc-server-4.0-8.1). Also assume that a Linux user account called “walker” needs the VNC server to start up automatically when Linux boots up.
- The Linux user account that needs VNC server to automatically start up after system reboot, must have a VNC password. To create a new (or reset a forgotten) VNC password, just login or su (switch user) with that Linux user account and execute this simple command:
Enter a password when prompted, which is used for VNC authentication.
- A hidden directory named .vnc is created in the user home directory by the vncpasswd command (if it’s not current exists). Execute
ls -la $HOME/.vnccommand to check if there is a file called xstartup. If this file is not exists, bring up VNC server with another simple command:
If you get this similar message “A VNC server is already running as :1″, meaning that there is another instance of VNC server running with the same display number. To resolve this, just try to replace the :1 with :2, :3, etc. Alternatively, you may execute this netstat command with root user privilege:
[root@walkernews ~]# netstat -tulpan | grep vnc
tcp 0 0 0.0.0.0:5801 0.0.0.0:* LISTEN 3402/Xvnc
tcp 0 0 0.0.0.0:5802 0.0.0.0:* LISTEN 8447/Xvnc
tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN 3402/Xvnc
tcp 0 0 0.0.0.0:5902 0.0.0.0:* LISTEN 8447/Xvnc
tcp 0 0 0.0.0.0:6001 0.0.0.0:* LISTEN 3402/Xvnc
tcp 0 0 0.0.0.0:6002 0.0.0.0:* LISTEN 8447/Xvnc
The netstat output shows that there are two VNC servers running with display number 1 and 2. So, for the 3rd VNC server to start, the command should be
- Edit $HOME/.vnc/xstartup file with your favourite editor, to un-comment these two lines in order to get the “normal” Linux Desktop view:
- Switch user to root account (i.e.
su - root), edit /etc/sysconfig/vncservers with your favourite editor, append the display number and Linux user account information to the VNCSERVERS (an array variable). This configuration file defines who can start up VNC server with what display number via the VNCSERVERS array (that’s read by Linux start up scripts /etc/init.d/vncserver). For example,
VNCSERVERS="1:root 2:tester 3:walker"
That means there are three Linux user accounts (root, tester, and walker) will start up VNC server with display number 1, 2, and 3 respecitively, as Linux boots up.
Note: Don’t simply add more than one VNCSERVERS array in /etc/sysconfig/vncserver configuration file. Otherwise, only the last VNCSERVERS array will be used.
- Make sure VNC server (the daemon or server process) is set to auto run upon system boots up to your runlevel. For example,
[root@walkernews ~]# chkconfig ––list | grep vnc
vncserver 0:off 1:off 2:off 3:off 4:off 5:on 6:off
The ––list option of chkconfig shows VNC server is set to auto run in Linux runlevel 5 (the default multi-user runlevel with Linux Desktop console). To configure VNC server to auto run when Linux boots into runlevel 5, use the ––level with on option switch:
chkconfig --level 5 vncserver on
Ok, that’s all you need. You should have the VNC server automatically running when Red Hat Linux boots up at runlevel 5. Although the guide might looks lengthy to you, but works involve shouldn’t take you more than 3 minutes after you get used with Linux!