Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Scripted configuration of TightVNC with Start on boot

Posted on 2016-11-08
Medium Priority
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 (deploy.sh)

# 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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 11

Accepted Solution

Scott Silva earned 1800 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 11

Assisted Solution

by:Scott Silva
Scott Silva earned 1800 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...
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!


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 deploy.sh
LVL 11

Assisted Solution

by:Scott Silva
Scott Silva earned 1800 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 30

Assisted Solution

serialband earned 200 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

618 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