Search code examples
pythonjupyter-notebookapache2reverse-proxylinode

How to run jupyter notebook on Ubuntu using linode server?


I tried running jupyter notebook in a Linode server, but when I ran the jupyter nootbook and then went on to my browser to open it there I got a "Apache2 Ubuntu Default Page". Below are the steps I took to get to this point.

From: https://www.linode.com/docs/getting-started/#create-a-linode

1.Created Linode (UBUNTU 20.04)
2.Removed previous ssh key
3.Logged in with new ssh key
4.Install software updates

From: https://www.linode.com/docs/applications/big-data/install-a-jupyter-notebook-server-on-a-linode-behind-an-apache-reverse-proxy/#before-you-begin

1.Download and install anaconda
2.Create certificates
3.Configure Jupyter
4.Configure apache reverse proxy
5.Run Jupiter notebook

There was a step in the getting started guide about "Update your system's hosts file" but I don't know what should I do in that step after doing: vim /etc/hosts from root account so I just: ESC :wq! from it.

I also tried following this link but this one didn't even open anything: https://janakiev.com/blog/jupyter-notebook-server/ I also tried another to follow another article (don't have link) where I enabled remote access in the jupyter configuration step but no use.

I have tried downloading anaconda like this:

wget https://repo.anaconda.com/archive/Anaconda3-2020.07-Linux-x86_64.sh
bash ~/Anaconda3-2020.07-Linux-x86_64.sh

and tried changing certificates with this:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mykey.key -out mycert.pem

I tried a few combinations with the URL but only one worked:

  1. only the IP address > this opened the page in the picture
  2. https://ipaddress/ > didn't work
  3. https://ipaddress/jupyter > didn't work
  4. https://ipaddress:8888/jupyter/ > didn't work
  5. ipaddress:8888/jupyter/ > didn't work

Please help me run the notebook.

Screenshot here


Solution

  • I got it to work by following this article here: I only created a root password in server setup. I do not know ways around this. replace your_server_ip with your linode ip.

    https://www.digitalocean.com/community/tutorials/how-to-install-run-connect-to-jupyter-notebook-on-remote-server

    So basically first we setup our Linode server. You can directly log in to the server as root by

    $ ssh root@your_server_ip
    

    Then we add user with sudo priveleges

    # adduser user
    

    You will be asked some information. Just give a password and leave the rest as default if you want. then

    # usermod -aG sudo user
    

    Then we setup our firewall. If you skip then you will 100% encounter some error.

    # ufw allow OpenSSH
    

    and then allow ssh by

    # ufw enable
    

    Then open a new terminal and log into the user account by

    $ ssh user@your_server_ip
    

    Now we update our workspace

    $ sudo apt update
    $ sudo apt -y upgrade
    

    You should have python by default. You can check it by python3 -V Next we install pip and some other packages. You may try to skip this step.

    $ sudo apt install -y python3-pip
    $ sudo apt install build-essential libssl-dev libffi-dev python3-dev
    

    I did not have a need to set up a virtual environment but you may choose to do so if you require. Now we install jupyter notebook

    $ python3 -m pip install jupyter
    

    And its still not done yet!!! Then log out of the server by using

    $ exit
    

    Now we connect to the jupyter notebook application with ssh tunneling.

    $ ssh -L 8000:localhost:8888 user@your_server_ip
    

    Here 8888 is Jupyter Notebook’s default port. Feel free to change 8000 though. If there are no errors from this command, it will log you into your remote server. Then run the Jupyter Notebook application

    $ jupyter notebook
    

    To connect to Jupyter Notebook, use your favorite web browser to navigate to the local port on the local host: http://localhost:8000 Use the token generated on the terminal to log into jupyter. And Voila!!

    Edit: Thank you David for the advice.