Skip to content

Instantly share code, notes, and snippets.

@cobyism
Last active September 18, 2022 14:18
Show Gist options
  • Save cobyism/4985035 to your computer and use it in GitHub Desktop.
Save cobyism/4985035 to your computer and use it in GitHub Desktop.
How to set up a Raspberry Pi so that VNC starts on boot. Mostly from http://myraspberrypiexperience.blogspot.co.uk/p/setting-up-vnc.html

Starting VNC automatically on a Raspberry Pi

sudo apt-get install tightvncserver
vncserver :1 -geometry 1280x800 -depth 16 -pixelformat rgb565
  • Set up a password for access (optional)
sudo vi /etc/init.d/tightvncserver
  • Paste the contents of the file below (tightvncserver.sh) into this new file.
sudo chmod 755 /etc/init.d/tightvncserver
sudo update-rc.d tightvncserver defaults

Done.

### BEGIN INIT INFO
# Provides: vncserver
# Required-Start: networking
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts VNC
# Description:
### END INIT INFO
# First configure the user you want to run this under - this will generally be pi, unless you've created your own users
export USER='pi'
eval cd ~$USER
# Check the state of the command - this'll either be start or stop
case "$1" in
start)
# if it's start, then start vncserver using the details below
su $USER -c '/usr/bin/vncserver :1 -geometry 1280x800 -depth 16 -pixelformat rgb565'
echo "Starting vncserver for $USER "
;;
stop)
# if it's stop, then just kill the process
pkill Xtightvnc
echo "vncserver stopped"
;;
*)
echo "Usage: /etc/init.d/vncserver {start|stop}"
exit 1
;;
esac
exit 0
@rozanski
Copy link

The script is missing a shebang. The following line should be inserted above line 1:
#! /bin/sh

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