Skip to content

Instantly share code, notes, and snippets.

@andrewpmiller
Last active August 29, 2015 14:12
Show Gist options
  • Save andrewpmiller/9ebe3f49e89a2f27b21f to your computer and use it in GitHub Desktop.
Save andrewpmiller/9ebe3f49e89a2f27b21f to your computer and use it in GitHub Desktop.
Set up VNC on a Raspberry Pi
  • Install TightVNC Server

    sudo apt-get install tightvncserver

  • Run TightVNC Server

    tightvncserver

    Note: By default this will set up a VNC session on display 1 (i.e. port 5901)

    • Set password
  • Kill the VNC session

    vncserver -kill :1

  • Set VNC to automatically launch at boot

    • Log in as root

      sudo su

    • Create a script: /etc/init.d/vncserver

     #!/bin/sh
     ### BEGIN INIT INFO
     # Provides:          VNC
     # Required-Start:    $local_fs
     # Required-Stop:
     # Default-Start:     2 3 4 5
     # Default-Stop:      0 1 6
     # Short-Description: Start or stop the VNC server
     ### END INIT INFO
    
     PATH=/sbin:/usr/sbin:/bin:/usr/bin 
    
     eval cd ~pi
    
     case "$1" in
       start)
             su pi -c "/usr/bin/vncserver :0 -geometry 1024x728 -depth 24"
             echo "Started VNC server."
             ;;
       stop)
             su pi -c "/usr/bin/vncserver -kill :1"
             echo "Stopped VNC server."
             ;;
       *)
             echo "Usage: vncserver [start|stop]" >&2
             exit 3
             ;;
     esac
      
     :
    
    • Make vncserver executable

      chmod 755 vncserver

    • Enable dependency-based boot sequencing

      update-rc.d vncserver defaults

    • Reboot Pi

      sudo reboot

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