Introduction
Virtual Network Computing (VNC) allows administrators to remotely access and manage a graphical desktop environment on a Linux server. In some environments, it may be necessary for the VNC server to start automatically whenever the server is rebooted.
On Ubuntu 14.04, this can be configured by creating a startup script and calling the script from the /etc/rc.local file. This ensures that the VNC server is started automatically during the system boot process.
In this blog, we will explain how to create a startup script for VNC Server, configure it to run during system startup, and verify that the VNC server is accessible after rebooting the server.
Prerequisites
Before configuring VNC Server to start automatically, make sure you have:
- An Ubuntu 14.04 server.
- Root or sudo access to the server.
- VNC Server installed and configured.
- SSH access to the server.
- A VNC client installed on the system from which you want to connect.
- The VNC display number configured for the server.
In this example, the VNC server will run on display :1.
Implementation
Step 1: Create the VNC Startup Script
Create a script named startvnc.sh under the /root directory:
vi /root/startvnc.sh
Add the following content:
#!/bin/bash USER=root HOME=/root export USER HOME cd /root /usr/bin/vncserver :1
This script sets the required user and home directory environment variables and starts the VNC server on display :1.
Step 2: Make the Script Executable
After creating the script, assign execute permission:
chmod +x /root/startvnc.sh
You can verify the permission using:
ls -l /root/startvnc.sh
Step 3: Configure rc.local
Ubuntu 14.04 is used /etc/rc.local to execute commands during the system startup process.
Open the file:
vi /etc/rc.local
Locate the following line:
exit 0
Add the VNC startup command above exit 0:
# Start VNC Server /root/startvnc.sh exit 0
The final /etc/rc.local configuration should look similar to:
#!/bin/sh -e # Start VNC Server /root/startvnc.sh exit 0
Step 4: Reboot the Server
Once the configuration is complete, reboot the server:
reboot
After the server has restarted, the startup script should automatically launch the VNC server.
Step 5: Verify the VNC Server
You can verify that the VNC server is running by connecting from a VNC client.
For display :1, use:
SERVER_IP:1
Alternatively, the VNC display :1 commonly corresponds to the TCP port 5901.
If the connection is successful, the VNC desktop should be accessible without manually starting the VNC server after every reboot.
Architecture Diagram
The startup process can be represented as follows:

Conclusion
Configuring the VNC server to start automatically at boot can eliminate the need to manually start the service after every server reboot.
On Ubuntu 14.04, this can be achieved by:
- Creating
/root/startvnc.sh. - Adding the VNC startup command to the script.
- Making the script executable.
- Calling the script from
/etc/rc.local. - Rebooting the server and verifying the VNC connection.
Once configured, the VNC server will automatically start during the boot process and can be accessed through a VNC client using the configured display number.
Note: Ubuntu 14.04 is an obsolete operating system release. The
/etc/rc.localapproach described here is specifically relevant to older Ubuntu versions. For newer Ubuntu releases,systemdservice configuration is generally preferred.
FAQ
1. What is a VNC server?
VNC (Virtual Network Computing) is a remote desktop technology that allows users to access and interact with a graphical desktop environment on a remote server.
2. Why configure VNC Server to start at boot?
Without an automatic startup configuration, the VNC server may need to be started manually after every server reboot. Configuring it at boot ensures that the VNC service starts automatically.
3. Where should the VNC startup script be created?
In this example, the script is created at:
/root/startvnc.sh
4. How do I make the script executable?
Run:
chmod +x /root/startvnc.sh
5. Where should the startup command be added?
Add the following command to /etc/rc.local, above exit 0:
/root/startvnc.sh
Related Articles
Talk to our experts
Looking for the right technology solution for your business? Our team of experts can help you with development, cloud, DevOps, design, and a wide range of other technology needs. Get in touch with our team here.