Solved

Scripted configuration of TightVNC with Start on boot

Posted on 2016-11-08
7
74 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 10

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 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...
1
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

730 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