56

I run ipython 0.12.1 on Ubuntu 12.04. You can run it in browser using notebook interface by running:

ipython notebook --pylab

Configuration files can be found in ~/.config/ipython/profile_default/. It seems that connection parameters for every kernel is placed in ~/.config/ipython/profile_default/security/kernel-4e424cf4-ba44-441a-824c-c6bce727e585.json. Here is the content of this file (new files are created as you start new kernels):

{
  "stdin_port": 54204, 
  "ip": "127.0.0.1", 
  "hb_port": 58090, 
  "key": "2a105dd9-26c5-40c6-901f-a72254d59876", 
  "shell_port": 52155, 
  "iopub_port": 42228
}

It's rather self-explanatory but how can I set a server that would have a permanent configuration, so I can use notebook interface from other computers in the LAN?

enedene
  • 3,525
  • 6
  • 34
  • 41
  • Do you want to use the *notebook* from other computers on the LAN, or use the kernels directly (e.g. open a QtConsole to share the kernel of an existing notebook, etc.)? The answer is different. – minrk May 10 '12 at 18:18
  • @minrk I want run the server to which I can connect with browser from another computer in the LAN and have notebook interface, as if I run the command ipython notebook --pylab locally, but in this case I'd have to write an address of another computer in the lan, for example http://myserver:8888 instead of http://127.0.0.1:8888 – enedene May 10 '12 at 18:23
  • In that case, the kernel connection files are not relevant to you (they are how the notebook server talks to the kernels). Answer coming... – minrk May 10 '12 at 21:02

2 Answers2

114

If you are using an old version of the notebook, the following could still apply. For new versions see the other answers below.


Relevant section of the IPython docs

The Notebook server listens on localhost by default. If you want it to be visible to all machines on your LAN, simply instruct it to listen on all interfaces:

ipython notebook --ip='*'

Or a specific IP visible to other machines:

ipython notebook --ip=192.168.0.123

Depending on your environment, it is probably a good idea to enable HTTPS and a password when listening on external interfaces.

If you plan on serving publicly a lot, then it's a also good idea to create an IPython profile (e.g. ipython profile create nbserver) and edit the config accordingly, so all you need to do is:

ipython notebook --profile nbserver

To load all your ip/port/ssl/password settings.

mit
  • 11,083
  • 11
  • 50
  • 74
minrk
  • 37,545
  • 9
  • 92
  • 87
  • And you can disable password request with `--NotebookApp.token=''` (possibly unsafe): https://stackoverflow.com/questions/41159797/how-to-disable-password-request-for-a-jupyter-notebook-session/47509274#47509274 – Ciro Santilli OurBigBook.com Nov 27 '17 at 10:59
21

The accepted answer/information is for an old version. How to enable remote access to your new jupyter notebook? I got you covered

First, generate a config file if you don't have it already:

jupyter notebook --generate-config

Notice the output of this command as it would tell you where the jupyter_notebook_config.py file was generated. Or if you already have it, it will ask you if you would like to overwrite it with the default config. Edit the following line:

## The IP address the notebook server will listen on.
c.NotebookApp.ip = '0.0.0.0' # Any ip

For added security, type in a python/IPython shell:

from notebook.auth import passwd; passwd()

You will be asked to input and confirm a password string. Copy the contents of the string, which should be of the form type:salt:hashed-password. Find and edit the lines as follows:

## Hashed password to use for web authentication.
#  
#  To generate, type in a python/IPython shell:
#  
#    from notebook.auth import passwd; passwd()
#  
#  The string should be of the form type:salt:hashed-password.
c.NotebookApp.password = 'type:salt:the-hashed-password-you-have-generated'

## Forces users to use a password for the Notebook server. This is useful in a
#  multi user environment, for instance when everybody in the LAN can access each
#  other's machine through ssh.
#  
#  In such a case, server the notebook server on localhost is not secure since
#  any user can connect to the notebook server via ssh.
c.NotebookApp.password_required = True

## Set the Access-Control-Allow-Origin header
#  
#  Use '*' to allow any origin to access your server.
#  
#  Takes precedence over allow_origin_pat.
c.NotebookApp.allow_origin = '*'

(Re)start your jupyter notebook, voila!

cenk
  • 1,389
  • 14
  • 27
  • As per [this answer](https://stackoverflow.com/a/43500232/588437), I needed `c.NotebookApp.allow_origin = '*'` as well. – ijoseph May 08 '18 at 20:42
  • 1
    @ijoseph thank you for your contribution, added allow_origin to the answer! – cenk May 09 '18 at 19:00