Working remotely on Jupyter Notebook

I’m just about to host the small Machine Learning workshop. I don’t want attendants to install Anaconda and use Jupyter Notebooks on their computers. I simply want to run Jupyter Notebook on my machine and give them access to it. I know that there are solutions such as Jupyter Hub, but this is too big for my needs.

The second use case is when I install Jupyter Notebook on the remote machine and I want to use it on my own. This is common when I want to leverage the possibilities of cloud computing – purchase a powerful machine and use it only for an hour or two.

As you probably noticed, when trying to connect to the Jupyter Notebook located on the remote computer, you are getting Connection Refused. This is due to the default policy: allow only local connections. Everything else will be refused. This is a good policy – in general, we don’t want someone from the Internet to access our machine and steal our notebooks or our CPU power. On the other hand, sometimes it is handy to be able to connect remotely.

Single user solution – SSH tunneling

If you want to access your remote Jupyter Notebook alone, the easiest way is to create the SSH tunnel between your computer and the remote machine. I wrote about this in more detail in the article about AutoSSH tunneling. By default, Jupyter Notebook starts on port 8888 and accepts only requests from the localhost. By creating a tunnel between your computer and remote host, you will be able to access Jupyter Notebook as it was locally.

Multiple users scenario

If you want to allow various users to access your Jupyter Notebook, you can change the configuration. First, you have to create the configuration file:

$ jupyter notebook --generate-config

Once the config is generated, you have to adjust two lines in the config file. These lines are is related to the origin of the request:

# an old line:
# c.NotebookApp.allow_origin = ''

# change it to the following:
c.NotebookApp.allow_origin = '*'

Please note that I not only placed ‘*’ at the end of the line but also removed the comment (#) at the beginning. The second is related to the IP address the notebook server will listen on:

# an old line:
# c.NotebookApp.ip = 'localhost'

# change it to the following:
c.NotebookApp.ip = '0.0.0.0'

The same situation here – I changed the value but also removed the comment. Once the changes are made, you can save the file and run your Jupyter Notebook server.

Security notice: the changes to the configuration file allows everyone to access your Jupyter Notebook server. I’m using them to provide temporary access to my workshop server but I’m not using it in the production environment or for important tasks.