Run Jupyter Notebook on a server

29/05/2018

This short tutorial shows how to run Jupyter on a remote server and control it using the browser of your local machine.

The setting is extremely useful: it allows to exploit the power of a cloud computing service (e.g. Google Cloud, Amazon AWS, or DigitalOcean) or your company's server, with the same comfort of a local Jupyter environment.

In this way, code can be written on the editor with no lags due to the remote connection and commands will be sent to the server for execution, which will respond with the output.

Jupyter Server

Step 1 - Generate a Password

Generate a secure password to be used to connect to the remote notebook server. To do so, open an interactive ipython session (by using the command ipython on the terminal of your local machine or server - if you are on windows, use the powershell), run the following command and type in your favorite password

>> from notebook.auth import passwd
>> passwd()

the script will encrypt your password and return the corresponding hash. Copy this weird string, we are going to paste it in the notebook configuration in the next step.


Step 2 - Configuration File

On the server machine, find the configuration file jupyter_notebook_config.py (use jupyter --config-dir on the terminal or powershell to locate the folder) and put the generated PASSWORD in the file, inside quotes preceded by a u

c = get_config()
c.NotebookApp.password = u'PASSWORD'

Use the find command on your text editor to make sure that no other line defines a different password.


Step 3 - Listen from any IP

Add these lines at the end of the file:

# The IP address the notebook server will listen on.
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False

This will allow connections from any ip address.


Step 4 - Set the Port

Finally, add the following line to the config file:

# The port the notebook server will listen on
c.NotebookApp.port = 9999

Optionally, you may also want to change the root folder of Jupyter:

c.NotebookApp.notebook_dir = '/the/path/to/your/favorite/folder/‘


Step 5 - Done!

Save and reboot. You can start the jupyter server by typing 'jupyter notebook' on the terminal or PowerShell.

You can now access the remote Jupyter by pointing your local browser to the IP address of your server, followed by the port you chose: http : // 123 . 456 . 789 . 123 : 9999.




Author: Andrea Barbon


Back