Solved

Scripted configuration of TightVNC with Start on boot

Posted on 2016-11-08
7
32 Views
Last Modified: 2016-11-14
Hi,

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
0
Comment
Question by:aideb
  • 3
  • 3
7 Comments
 
LVL 9

Accepted Solution

by:
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.
https://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html
0
 
LVL 2

Author Comment

by:aideb
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
### BEGIN INIT INFO
# Provides:          vncserver
# Required-Start:    networking
# Default-Start:     3 4 5
# Default-Stop:      0 6
### END INIT INFO

PATH="$PATH:/usr/X11R6/bin/"

# The Username:Group that will run VNC
export USER="labuser"
#${RUNAS}

# The display that VNC will use
DISPLAY="1"

# Color depth (between 8 and 32)
DEPTH="16"

# The Desktop geometry to use.
#GEOMETRY="<WIDTH>x<HEIGHT>"
#GEOMETRY="800x600"
GEOMETRY="1024x768"
#GEOMETRY="1280x1024"

# The name that the VNC Desktop will have.
NAME="my-vnc-server"

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

. /lib/lsb/init-functions

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

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

restart)
$0 stop
$0 start
;;
esac

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?

Cheers
0
 
LVL 9

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...
1
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 2

Author Comment

by:aideb
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
0
 
LVL 9

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...
0
 
LVL 27

Assisted Solution

by:serialband
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.
1
 
LVL 2

Author Closing Comment

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
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…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now