Set up a VNC server on Raspberry Pi

    • Install vnc-server

    apt-get install tightvncserver

    • As the user you want VNC to run as, launch the VNC server manually. This will create the config directory and files, including your password for the VNC session.

    vncserver :1

    • Create an init script to start VNC as a service at boot (i.e. /etc/scripts/vnc-server)
    #!/bin/sh
    
    # The username VNC will run as
    export USER="joeblow"
    
    # The display that VNC will use
    DISPLAY="1"
    
    # Color depth (value between 8 and 32)
    DEPTH="16"
    
    # The Desktop geometry to use.
    #GEOMETRY="x"
    GEOMETRY="1024x768"
    
    # The name that the VNC Desktop will have.
    NAME="vnc-server-1"
    
    OPTIONS="-name ${NAME} -depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"
    
    case "$1" in
      start)
        echo "Starting vncserver as user '${USER}' on :${DISPLAY}"
        su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"
        ;;
      stop)
        echo "Stoping vncserver as user '${USER}' on :${DISPLAY}"
        su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"
        ;;
      restart)
        $0 stop
        $0 start
        ;;
      *)
        echo "Usage: $0 [start|stop|restart]"
        exit 2
    esac
    
    exit 0
    
    
    • Make the script executable:

    chmod +x /etc/scripts/vnc-server

    •  Add the script to the rc.local file, above any line that reads "exit 0"

    /etc/scripts/vnc-server start

     

     

    No questions yet.