{ "metadata": { "name": "ipython-notebook-server" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Remote iPython Notebooks\n", "\n", "## Overview\n", "\n", "The focus of this talk is on using an iPython Notebook instance hosted on a remote server. As we have seen, using iPython notebook locally is a fairly straight-forward process. Sometimes, however, it may be advantageous to set up an iPython notebook for use remotely, or to be accessed by multiple users. This requires installing iPython notebook on a centralized server and configuring it to accept remote connections.\n", "\n", "![image](files/images/use-cases.png)\n", " \n", "We will also briefly discuss options for hosting a network-accessable iPython notebook." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Preparing a Notebook for remote access \n", "\n", "There are several steps to creating and configuring a notebook server instance (adapted from official instructions provided at the [Official iPython Website][ipython-web]).\n", "\n", "[ipython-web]:http://ipython.org/ipython-doc/dev/interactive/htmlnotebook.html\n", " \n", " 1. Create a profile that defines the notebook server instance.\n", " 2. Create a self-signed certificate to enable encrypted communications with the server.\n", " 3. Create a password hash to restrict access to the server instance.\n", " 4. Edit the profile and specify security settings.\n", "\n", "
\n", "![image2a](files/images/creation-overview.png)\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1. Creating a profile for the server\n", "\n", "Creating a profile for the server allows you to manage multiple iPython notebook instances on the server." ] }, { "cell_type": "raw", "metadata": {}, "source": [ "$ ipython profile create nbserver " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "On a linux/unix machine, this will create the ~/.ipython/profile_nbserver directory. In this directory, amongst all the files created by ipython, will be the **ipython_notebook_config.py** file. This is the file we will be working in for the configuration steps of this process.\n", "\n", "### 2. Creating a self-signed certificate file\n", "Unless you have an institutional security certificate, you will need to create a self-signed certificate file for use with your server. This will allow secure access." ] }, { "cell_type": "raw", "metadata": {}, "source": [ "$ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Caveats regarding the use of a self-signed certificate\n", "\n", "Note that when using a self-signed certificate, your browser may complain that the sight is not necessarily valid. Because you created the certificate, it is safe to allow an exception for this server/certificate. If it is possible to instead use a valid signed certificate in place of a self-signed certificate, this is preferable.\n", "\n", "### 3. Creating a password hash\n", "\n", "In order to secure your notebook server, it is ***vital*** to set a password. This is done by defining a *password hash* in the notebook configuration file. You will generate the password hash from inside iPython." ] }, { "cell_type": "raw", "metadata": {}, "source": [ "$ ipython\n", "\n", "Python 2.7.3 | 64-bit | (default, Mar 25 2013, 15:52:02) \n", "Type \"copyright\", \"credits\" or \"license\" for more information.\n", "\n", "IPython 1.0.dev -- An enhanced Interactive Python.\n", "? -> Introduction and overview of IPython's features.\n", "%quickref -> Quick reference.\n", "help -> Python's own help system.\n", "object? -> Details about 'object', use 'object??' for extra details." ] }, { "cell_type": "code", "collapsed": false, "input": [ "from IPython.lib import passwd\n", "\n", "# Note: In practice, passwd() will prompt for a\n", "# password. This is preferable, since otherwise\n", "# your password will be saved inside your session\n", "# history.\n", "\n", "passwd(\"Test Password\")" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 1, "text": [ "'sha1:774d9926079f:e585086e10f2f00718a0d9c4ed1b652052d8d463'" ] } ], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 4. Configuring the notebook profile\n", "\n", "The notebook server is configured by editing the `ipython_notebook_config.py` file found inside the ~/.ipython/profile_nbserver directory created previously.\n", "\n", "Open `ipython_notebook_config.py` in your favorite editor and add the following:\n", "\n", " # Kernel config\n", " c.IPKernelApp.pylab = 'inline' # if you want plotting support always\n", " # Notebook config\n", " c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'\n", " c.NotebookApp.ip = '*'\n", " c.NotebookApp.open_browser = False\n", " c.NotebookApp.password = u'sha1:bcd259ccf...your hashed password here'\n", " # It's a good idea to put it on a known, fixed port\n", " c.NotebookApp.port = 9999" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Accessing the Notebook\n", "\n", "In order to make the server available, you will start it with the following command:" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "$ ipython notebook --profile=nbserver" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The Notebook server can now be accessed via browser, at https://your.host.com:9999.\n", "
\n", "![image](files/images/https-access.png)\n", "\n", " * [http://www.picloud.com/pricing/][picloud-plans]\n", " * \n", " * Accounts can be shared, but cannot share a notebook between accounts.\n", " * Getting notebooks in to, out of these services can be tricky.\n", " * You may still need to configure custom packages manually.\n", " \n", " \n", "[picloud]: http://www.picloud.com\n", "[wakari]: http://www.continuum.io/wakari\n", "[picloud-plans]: http://www.picloud.com/pricing/\n", "[wakari-plans]: https://wakari.io/plans" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Summary\n", "\n", "* Setting up a remotely-accessible iPython notebook is not difficult.\n", " * Select a host.\n", " * Create and Configureate a Notebook Server.\n", "* The choice of host is a trade-off between convienence and cost.\n", "\n" ] } ], "metadata": {} } ] }