Skip to content

Instantly share code, notes, and snippets.

@daz
Last active December 7, 2023 18:05
Show Gist options
  • Save daz/6f37658d440e45af561693817e893fc5 to your computer and use it in GitHub Desktop.
Save daz/6f37658d440e45af561693817e893fc5 to your computer and use it in GitHub Desktop.
Script to install VNC server and run at boot
# Setup VNC server
sudo apt-get remove -y tightvncserver
sudo apt-get install -y tightvncserver
mkdir -p "$HOME/.vnc"
vncpasswd -f <<< $PASSWORD > "$HOME/.vnc/passwd"
# VNC at startup
sudo tee /etc/init.d/tightvnc > /dev/null <<EOF
#!/bin/sh
### BEGIN INIT INFO
# Provides: tightvncserver
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start vnc server
# Description:
### END INIT INFO
. /lib/lsb/init-functions
USER=$USER
HOME=$HOME
export USER HOME
# Carry out specific functions when asked to by the system
case "\$1" in
start)
su - \${USER} -c "/usr/bin/vncserver :1 -geometry 1280x800 -depth 16 -pixelformat rgb565"
echo "Starting VNC server"
;;
stop)
su - \${USER} -c "/usr/bin/vncserver -kill :1"
echo "VNC Server has been stopped"
;;
*)
echo "Usage: /etc/init.d/tightvnc {start|stop}"
exit 1
;;
esac
EOF
sudo chmod 0755 /etc/init.d/tightvnc
sudo update-rc.d tightvnc defaults
sudo service tightvnc stop
sudo service tightvnc start
@qzm
Copy link

qzm commented Apr 22, 2019

line 3 : sudo apt-get install -y tightvncserver

@LorenzoFasolino
Copy link

vncserver doesn't start, and still require a password when I try to start it manually.

@wjohnso28
Copy link

Hello when i run sudo vncserver start its asking for password and in my vps I'm unable to neter input so any script who automatically put password and run vncserver?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment