Tuesday, October 26, 2021

[SOLVED] PermissionError: [Errno 13] Permission denied: Cannot open Jupyter on Browser despite running correctly on AWS EC2 instance

Issue

I have already set up an EC2 instance on AWS (ubuntu, eu-central-1b). Port 8888 (custom tcp rule), https 443 and ssh 22 is open on AWS (anywhere). I'm aware of the chmod 400 key.pem and jupyter_notebook_config.py topics. It is also sucessfully set up Anaconda3-5x and also Jupyter on the EC2 instance. BUT: I cannot access the Jupyter Server on my browser (Firefox and Safari). When launching jupyter notebook after logging in to the EC2 instance, i get the PermissionError: [Errno 13] Permission denied error message. In the browser, I simply get a the connection has timed out error message.

I followed pretty much every tutorial there is such as:

https://chrisalbon.com/aws/basics/run_project_jupyter_on_amazon_ec2/ or https://github.com/mGalarnyk/Installations_Mac_Ubuntu_Windows/tree/master/AWS

I tried it a couple of times now, terminated the EC2 instance and set up the whole thing again. But still, I cannot connect to the Jupyter Server via the browser.

The exact error message looks like this the moment I try to connect / enter the URL in the browser:

(base) ubuntu@ip-172-31-34-13:~$ jupyter notebook [I 15:44:20.930 NotebookApp] JupyterLab extension loaded from /home/ubuntu/anaconda3/lib/python3.7/site-packages/jupyterlab
[I 15:44:20.930 NotebookApp] JupyterLab application directory is /home/ubuntu/anaconda3/share/jupyter/lab
[I 15:44:20.934 NotebookApp] Serving notebooks from local directory: /home/ubuntu
[I 15:44:20.934 NotebookApp] The Jupyter Notebook is running at:
[I 15:44:20.934 NotebookApp] https://(ip-172-31-34-13 or 127.0.0.1):8888/
[I 15:44:20.934 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
Exception in callback BaseAsyncIOLoop._handle_events(6, 1)
handle: <Handle BaseAsyncIOLoop._handle_events(6, 1)>
Traceback (most recent call last):
  File "/home/ubuntu/anaconda3/lib/python3.7/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/tornado/platform/asyncio.py", line 122, in _handle_events
    handler_func(fileobj, events)
  File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/tornado/s**tack_context.py", line 300, in null_wrapper
    return fn(*args, **kwargs)
  File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/tornado/netutil.py", line 262, in accept_handler
    callback(connection, address)
  File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/tornado/tcpserver.py", line 263, in _handle_connection
    do_handshake_on_connect=False)
  File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/tornado/netutil.py", line 565, in ssl_wrap_socket
    context = ssl_options_to_context(ssl_options)
  File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/tornado/netutil.py", line 540, in ssl_options_to_context
    context.load_cert_chain(ssl_options['certfile'], ssl_options.get('keyfile', None))**

There's also no difference when I use the 'https://(AWS Public DNS):8888' or the 'https://(AWS IPv4 Public IP):8888'

I tried even a different Port (8889) and stuff like this.

And as an info what my notebook_config looks like:

c = get_config()

c.IPKernelApp.pylab = 'inline'
c.NotebookApp.certfile = u'/home/ubuntu/certs/mycert.pem'
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'sha1:xxxxx'
c.NotebookApp.port = 8888

Everythings's basically set up like they showed in the tutorials. I tried it even like they showed officialy on AWS: https://docs.aws.amazon.com/dlami/latest/devguide/setup-jupyter-config.html


Solution

It might be a permissions error with the cert.pem file. Assuming the directory is correct for mycert.pem as listed in your notebook_config file, from the terminal that's SSH'd into the EC2 instance, you can use the following command:

sudo chown $USER:$USER /home/ubuntu/certs/mycert.pem

Possible duplicate of this question: Trouble with Jupyter certifications



Answered By - Nick Walsh