AWS EC2 Launch Jupyter Notebook/Lab Server with linux screen

Bruce Yang
2 min readJun 9, 2019

--

Part 1: Create AWS EC2 Instance

Part 2: SSH to your EC2 instance (Ubuntu)

In your terminal with keypem.pem in your current folder:

sudo ssh -i “keypem.pem” ubuntu@ec2–ip-address.region.compute.amazonaws.com

Part 3: Install Anaconda on Ubuntu

Part 4: Start a Jupyter Notebook/Jupyter Lab Server

Step 1: In the terminal of your EC2 Ubuntu environment

ipython

Step 2: In ipython

from IPython.lib import passwd#set up your password and save it somewhere
passwd()
quit()

Step 3: In the terminal

jupyter notebook --generate-configmkdir certscd certssudo openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pemcd ~/.jupyter/nano jupyter_notebook_config.py

Step 4: Copy and Paste into jupyter_notebook_config.py

c = get_config()c.IPKernelApp.pylab = 'inline'c.NotebookApp.certfile = u'/home/ubuntu/certs/mycert.pem'c.NotebookApp.ip = '*'#or try this
#c.NotebookApp.ip = ‘0.0.0.0’
c.NotebookApp.open_browser = False# Your password below will be whatever you copied earlier
c.NotebookApp.password = u'your ipython password'
c.NotebookApp.port = 8888

Step 5: In the terminal

screen -mdS jupyter_lab_serving bash -c 'jupyter lab'#kill all screens: pkill screen

So that you will keep the jupyter notebook running even if you close the terminal.

Step 6: In the web browser:

https://public-ip-address:port/

“Your connection is not private” — click advance and allow.

Enter passoword.

You should have your Jupyter lab running!!!

Tip1: If you have permission error

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

Tip 2: If you have security group problem

Just add ‘8888’ or whatever port your choose to your security group.

Tip 3: make sure use https:// not http

--

--