Learning by doing.

Remote IPython Notebook Setup

Aug 8, 2016 • Python • Tags: Python IPython


As mentioned in another post, I have a Ubuntu server sitting at home. How can I access it remotely and use it as a IPython Notebook server for my study? Below are some prerequisites:

  • Full permission of the router at home.
  • The router supports DDNS and port forwarding.
  • Good internet connection.

With the conditions above, we can setup a remote IPython Notebook server by two main steps:

  1. Enable the SSH access of the server.
  2. Setup the IPython Notebook service.

Enable the SSH access of the server.

  1. Reserve a static IP address for your server in the router.
  2. Setup DDNS in the router with a DDNS service provider, e.g., NoIP.
  3. Add a custom service with the reserved IP and port 22 for SSH.

Now, the server can be accessed publicly from anywhere, with the DDNS domain, as below

$ ssh <username>@<domain>:22

Setup the IPython Notebook service.

Now that one can SSH the server, let’s setup the IPython Notebook service. Before moving on, make sure that Jupyter Notebook has been installed for your Python.

To install jupyter:

$ conda install jupyter


$ jupyter notebook --generate-config

which will generate in ~/.jupyter.

Then generate certfile and key as (cited, see reference):

$ cd ~/.jupyter
$ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mykey.key -out mycert.pem

Launch Python and run the following lines (cited, see reference):

In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'

After that, edit the as following (cited, see reference):

c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
# Set options for certfile, ip, password, and toggle off browser auto-opening
c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'
c.NotebookApp.keyfile = u'/absolute/path/to/your/certificate/mykey.key'
# Set ip to '*' to bind on all interfaces (ips) for the public server
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False

# It is a good idea to set a known, fixed port for server access
c.NotebookApp.port = 9999

On your server, launch the notebook by:

$ jupyter notebook

On your local machine, make an SSH tunnel as

$ ssh -N -f -L <server-port>:localhost:<local-port> <username>@<DDNS domain>

Then we can access the remote IPython Notebook via the browser by the address localhost:<local-port> with the password we set previously.


Tags: Python IPython