31 August 2015

Ubuntu: VNC vis SSH tunnel

This method uses the lightweight XFCE4 desktop.
  1. Install the vncserver and desktop:
    sudo apt-get update
    sudo apt-get install xfce4 xfce4-goodies tightvncserver
  2. Run vncserver to set a password:
    1. vncserver
    2. Kill the session:
      vncserver -kill :1
  3. Backup the config file:
    mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
  4. Create a startup file: nano ~/.vnc/xstartup
    xrdb $HOME/.Xresources
    startxfce4 &
  5. Ensure that file can run:
    sudo chmod +x ~/.vnc/xstartup
  6. Create a VNC Service file:
    sudo nano /etc/init.d/vncserver
    Paste in the following replacing "user" with a non root user:
    # common
    export USER="user"
    OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY} -localhost"
    . /lib/lsb/init-functions
    # start
    case "$1" in
    log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISP$
    su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"
    # stop
    log_action_begin_msg "Stopping vncserver for user '${USER}' on localhost:${DISP$
    su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"
    # restart
    $0 stop
    $0 start
    exit 0
  7. Make it executable:
    sudo chmod +x /etc/init.d/vncserver
  8. Update file permissions and allow any user to start X Server:
    chown -R philc. ~/.vnc && chmod +x ~/.vnc/xstartup
    sed -i 's/allowed_users.*/allowed_users=anybody/g' /etc/X11/Xwrapper.config
  9. Start the service:
    sudo service vncserver start
    chmod +x /etc/init.d/vncserver
    service vncserver start
  10. Try connecting
  11. Once its working, add service to auto start:
    sudo update-rc.d vncserver defaults

Connecting to the service

To connect to it begin an SSH session then run VNC:
  1. ssh -p [Destination Firewall port number e.g. 22] -N -L 5901: [username]@[domain name/ip] -v
  2. Using Mac's Finder/Go to Server or a Windows equivalent like Real VNC Viewer

No comments:

Post a Comment