Access remotely MacOS with Jupyter and ngrok

Posted on April 13, 2019 in datascience • 1 min read

This is a step-by-step guide to control remotely a MacOS laptop host1 from host2 using Jupyter Lab and ngrok. The two hosts may sit in different local networks behind firewalled NATs. Instructions to setup Jupyter lab in a clean Python 3.6.5 virtual environment are also included.

Steps for host1

If missing: install brew, a package manager for MacOS:

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Update the internal index and install some required packages:

$ brew update
$ brew install pyenv
$ brew install zlib
$ brew install sqlite

Install Python 3.6.5:

$ export LDFLAGS="${LDFLAGS} -L/usr/local/opt/zlib/lib"
$ export CPPFLAGS="${CPPFLAGS} -I/usr/local/opt/zlib/include"
$ export LDFLAGS="${LDFLAGS} -L/usr/local/opt/sqlite/lib"
$ export CPPFLAGS="${CPPFLAGS} -I/usr/local/opt/sqlite/include"
$ export PKG_CONFIG_PATH="${PKG_CONFIG_PATH} /usr/local/opt/zlib/lib/pkgconfig"
$ export PKG_CONFIG_PATH="${PKG_CONFIG_PATH} /usr/local/opt/sqlite/lib/pkgconfig"
$ pyenv install 3.6.5

Create a clean virtual environment named env365 with Jupyter Lab:

$ pyenv virtualenv 3.6.5 env365
$ pyenv activate env365
$ pip install jupyterlab

Start the ngrok tunnel:

  1. Create an account on https://ngrok.com and install it
  2. Open a terminal and start Jupyter Lab: $ pyenv activate env365 && jupyter lab
  3. Open another terminal and start the tunnel: $ ./ngrok http 8888
  4. Share a) the Jupyter Lab token and b) the ngrok forwarding URL

Steps on host2

From your browser, access the ngrok forwarding URL and login with the Jupyter Lab token. Et voilà!