Scripted configuration of TightVNC with Start on boot

Posted on 2016-11-08
Last Modified: 2016-11-14

I'm trying to develop a script that I can work into an unattended build that will configure TightVNC on Kali linux (based on Debian) and then ensure that it runs on boot

Here is what I have currently in my bash script (

# Configure VNC Password
umask 0077                                        # use safe default permissions
mkdir -p "$HOME/.vnc"                             # create config directory
chmod go-rwx "$HOME/.vnc"                         # enforce safe permissions
vncpasswd -f <<<"remotecl" >"$HOME/.vnc/passwd"  # generate and write a password

# Start VNC 
/usr/bin/tightvncserver -geometry 1500x700 -depth 16

Open in new window

This is setting the password and starting the VNC server however when the machine is restarted, the service does not start back up

Can someone help me with this please
Question by:aideb
  • 3
  • 3
LVL 10

Accepted Solution

Scott Silva earned 450 total points
ID: 41879604
I'm not fully vetted on Debian, but you will need to get a startup script or at least a link into the init process...
I assume it is using System V init...   This might help.

Author Comment

ID: 41879628
Thanks Scott,

That has moved me along nicely - I used the info in your link and discovered another post

I did

sudo nano /etc/initd/vncserver

and populated this with

#!/bin/sh -e
# Provides:          vncserver
# Required-Start:    networking
# Default-Start:     3 4 5
# Default-Stop:      0 6


# The Username:Group that will run VNC
export USER="labuser"

# The display that VNC will use

# Color depth (between 8 and 32)

# The Desktop geometry to use.

# The name that the VNC Desktop will have.

OPTIONS="-name ${NAME} -depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"

. /lib/lsb/init-functions

case "$1" in
log_action_begin_msg "Starting vncserver for user '${USER}' on   localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/tightvncserver ${OPTIONS}"

log_action_begin_msg "Stoping vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/tightvncserver -kill :${DISPLAY}"

$0 stop
$0 start

exit 0

Open in new window

I can now start the service with

/etc/initd/vncserver start

and stop with

/etc/initd/vncserver stop

How can I get the start command to execute on boot?

LVL 10

Assisted Solution

by:Scott Silva
Scott Silva earned 450 total points
ID: 41879632
You need a link to that script in /etc/rcx.d  where x is the run level you are starting in... Usually 3 for a headless server, and 5 for a graphical desktop... The link is named with an "S" and a number corresponding with what order it should start... Higher numbers start later... This is so you can make sure dependent services start earlier...  You also technically should have a shortcut in /etc/rc0.d starting with a "K" so the process can be shutdown in an orderly manner...
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.


Author Comment

ID: 41879649
Great - Thanks Scott

I ran this

sudo ln -s /etc/initd/vncserver /etc/rc5.d/S08vncserver
sudo ln -s /etc/initd/vncserver /etc/rc0.d/K01vncserver

and it started on boot!

How am I best automating this so that I can add it all to my
LVL 10

Assisted Solution

by:Scott Silva
Scott Silva earned 450 total points
ID: 41879722
You would just have to add all the steps you did into your script... You could either copy a script in from a server, or use whatever you feel comfortable to echo the lines into the scripts, or maybe sed...  I would just make a tar file with all the shortcuts in it and untar it relative to where everything goes...
LVL 28

Assisted Solution

serialband earned 50 total points
ID: 41880877
You should be able to do the following on debian based systems that use Sys V init:
update-rc.d vncserver defaults

To remove it
update-rc.d vncserver defaults

They should be a little less error prone than manually linking them in the directories.

Author Closing Comment

ID: 41886167
Thanks for all your assistance to resolve this!

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
wifi not working on Raspberry Pi 3? 2 56
Access_log 17 121
Set robocopy to exclude "System Volume Information" folder 3 56
windows 7 starter missing password 21 77
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question