0% found this document useful (0 votes)
31 views12 pages

Server Setup For Jupyter Notebook

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views12 pages

Server Setup For Jupyter Notebook

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Server Setup For Jupyter Notebook

How EC2 Instance Is Created ? :


You can follow this Url https://chrisalbon.com/aws/basics/run_project_jupyter_on_amazon_ec2/

After Ec2 instance is created we get “pem” file and ssh command:

Example:
ssh -i "roopa.pem" [email protected]

Download Pem file and store in local directory


Open Terminal:
To quickly open a Terminal window at any time, press Ctrl+Alt+T
(Or)
click the “Show Applications” button at the bottom-left corner of your screen, on the “dash” bar.

Type “Terminal” and press Enter to find and launch the Terminal shortcut and click on Terminal.
You can get the terminal window like this

● If you pem file in Desktop → backend → roopa.pem


In Terminal you should navigate to the folder which contains the pem file using “cd ” command.

Press Enter to navigate to that folder , you can see like this

● You can see files list in specific folder by command “ ls ”


Connect Remote Server using ssh
Now we have to copy “ ssh ” command and paste it on terminal
ssh -i "roopa.pem" [email protected]

Command for copy in terminal → Ctrl+Shift+c


Command for paste in terminal → Ctrl+Shift+v

Press Enter
If you get error like this in your terminal like this:

Use command chmod 400 roopa.pem


Then run the command ssh again we can get like this
Set Jupyter Security On Server:

1. Create jupyter config file by running this command in terminal in home directory
Automatically a folder will be created in home directory with name ~/.jupyter/

2. Create a hashed password for jupyter notebook by following commands:


i) open ipython terminal by command - ipython
ii) import password fromIPython.lib by command - from IPython.lib import passwd
iii) call password function - passwd()
iv) Enter password: [Create password and press enter]
v) Verify password: [Press enter]
vi) you get password : 'sha1:98ff0e580111:12798c72623a6eecd54b51c006b1050f0ac1a62d'
vii) type exit from ipython : exit

3. Create certificates for https:


i) Create new directory: mkdir certs
ii) move into that directory : cd certs
iii)Run this command to create certificate : openssl req -x509 -nodes -days 365 -newkey
rsa:2048 -keyout mykey.key -out mycert.pem

After running this command answer basic questions and press enter:
Now we can see two files in certs folder by using “ ls ” command → mycert.pem , mykey.key

4. Configure jupyter:

To configure jupyter notebooks we have to include certificates files in jupyter config file
by following commands :
1. First move into jupyter directory - cd ~/.jupyter/
2. To edit jupyter config file use -
vi jupyter_notebook_config.py (or) vim
jupyter_notebook_config.py
Now we can see an attention msg:

● Please type “E” and press Enter , you can see jupyter_notebook_config.py file content.
● To insert something in file please press “i” in keyboard

Insert this at the beginning or end of the file:

c = get_config()

# Kernel config

c.IPKernelApp.pylab = 'inline' # if you want plotting support always in your


notebook

# Notebook config

c.NotebookApp.certfile = u'/home/ubuntu/certs/mycert.pem' #location of your


certificate file

c.NotebookApp.keyfile = u'/home/ubuntu/certs/mykey.key' #location of your


certificate file

c.NotebookApp.ip = '0.0.0.0'

c.NotebookApp.open_browser = False #so that the ipython notebook does not


opens up a browser by default

c.NotebookApp.password =
u'sha1:98ff0e580111:12798c72623a6eecd54b51c006b1050f0ac1a62d' #the encrypted
password we generated above
# Set the port to 8888, the port we set up in the AWS EC2 set-up

c.NotebookApp.port = 8888

Remember to replace sha1:98ff0e580111:12798c72623a6eecd54b51c006b1050f0ac1a62d with your


password!

● To save the file press “Esc” and then type :wq then press “Enter”

Create new session by “tmux”:


Tmux is a Linux application that allows multitasking in a terminal window. It stands for Terminal
Multiplexing, and is based around sessions. Users can start a process, switch to a new one, detach from a
running process, and reattach to a running process.

(OR)

tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach
them (they keep running in the background) and reattach them to a different terminal.

You can refer this document to understand tmux and to learn some commands:
https://phoenixnap.com/kb/tmux-tutorial-install-commands

● First we need to install tmux : sudo apt-get install tmux


● Once installation is complete, To start a new named session, type the following command:

tmux new -s session_name

Instead of session_name, type the name you want assigned to the session.

● Your screen will change and display a status bar at the bottom. In the lower-left, you’ll see the

name and number for the window: session_n0:bash*

● In the lower-right, the date and time are displayed. Just beside the date and time, you’ll see the

logged-in user and host: username@host-server

For example i named my session as “jupyter_session”

Now we can see our terminal attached to new session we created


Start Jupyter notebook :
Move to that directories where jupyter notebook exists and run the command
jupyter notebook
(OR) We can start jupyter notebook at particular port

jupyter notebook --port=8888

Now you can see your jupyter server started with https:
Accessing Jupyter Notebook In Browsers
ssh -i "roopa.pem" [email protected]

● You find ip address in ssh command, Here it is highlighted in blue color: 52.39.239.66
● Port : The port with which jupyter notebook opened , You can find port number in above image
which underline with yellow line : 8888

Finally the link will be “ip address:port” → https://52.39.239.66:8888

● You can access jupyter notebook in chrome by the link https://52.39.239.66:8888

Note: You can’t access the jupyter notebook by http link because we encrypted the jupyter server with the
certificates.

When you access the https link in chrome, jupyter notebook login page will be opened:
Enter Password which you set before:

Now you can see Jupyter Notebook Home page:


● While Cloning your code to the server , do not forget to create requirements.txt

$ pip freeze > requirements.txt

● To install requirements on server:

$ pip install -r requirements.txt

You might also like