Setup Jupyter Notebook server – Centos/Rhel 7

I bought a python course from udemy because they have some great prices right now, lucky me.
But the instructor recommends his students to use jupyter notebook doing his course and i must admit that
i am impressed! jupyter notebook has it all! you can share and create
documents that contain live code, equations, visualizations and explanatory text ect ect.

He showed us “me” how to setup jupyter notebook on a localhost machine, but
within 5 minutes i was annoyed that my laptop had to host the server due
to performance and heat on my lab. So I decided to setup a jupyter notebook server
instead and it is a fairly simple process and dosn’t take more than 5-10 minutes.

Content
– Step 1. Dependencies
– Step 2. Setup & Configure Jupyter notebook

Step 1. Dependencies

We are going to need the python-pip package to install jupyter.

I tried to install jupyter with pip. Multiple times and it kept failing over and over again and I was banging my head and couldn’t figure out what the error was, until I realized that I am using CentOS 7 minimal, and was missing some packages, so if your install fails later then go back to this step and install the package(s) in this command.

Step 2. Setup & Configure Jupyter notebook

The installation of jupyter itself is fairly simple, just use the command below and you are good to go.

Jupyter is installed. But that isn’t enough, we need to configure it so we have “remote access”.
Right know it is running on http://127.0.0.0:8888 and are only assessable through the server itself, what we want to do is make it assessable from remote PC’s as well.

To do that we need to generate a configuration file with the following command.

you should see an output like this where the path for the configuration file will be defined.

So my path is /root/.jupyter/jupyter_notebook_config.py but first we will generate a hashed password. open python in the terminal with python and enter the commands below and remember to copy the hashed password

So now that we have created a password, will we open the configuration file and start the configuration of jupyter notebook.

Go to line 186, you should see something like this

and paste the hashed password in the string (a string is used in python programming and looks like “” or ”). Don’t forget to
uncomment the line (delete #). save and exit.

If you don’t have a valid certificate you should use a self-signed certificate to be able to use https://
you can generate one with the following cmd. (for further explanation read this don’t use the cmd in the article about SSL but use the one below!) The command to create a self-signed certificate :

Open the configuration file once again.

First go to Line 67 and configure it to bind on all IP’s so it is assessable from other than localhost, it should look like this (* is a wildcard there tells c.NotebookApp to listen to every IP, you could also make a list of trusted ip’s.)

Next go to line 119 and insert the path to the cert and key file, you can always move the files to another location, just remember to modify the config file as well!

and last but not least we will tell jupyter notebook that it doesn’t need to open the browser, if you have tried to open jupyter notebook on a headless system you probably have noticed the error message about the missing browser. uncomment line 177 and set it to false

That was it. You just need to open port 8888 in the firewall.
Allow port 8888 in your firewall

Restart the firewall to load the new settings

And everything should be good by now, just type jupyter notebook in the terminal to start the service and then go into the browser,
one thing you should be aware off is that we have enabled https and therefore we cannot reach the server with http you have to type https://server_ip:8888 in your browser.