Shuan Chen

PhD Student in KAIST CBE

0%

Connect Linux server to Jupyter notebook

Commands to connect linux server to jupyter notebook on web browser for easier coding life

Install Jupyter notebook

Install jupyter notebook on the server by simply run

1
pip install jupyter

Run in background session

If you want to run it as a background session, run

1
screen -S jupyter-on-fly

and press Ctrl+a+d to detach

Password setting and conncetion

Set password

1
2
3
4
jupyter notebook --generate-config
jupyter notebook password
Enter password: ****
Verify password: ****

and you’re on the right path if it shows the following

1
[NotebookPasswordApp] Wrote hashed password to /Users/you/.jupyter/jupyter_notebook_config.json

Connect server to notebook

1
jupyter notebook --ip=[server_ip_address] --port=8888 --allow-root --no-browser

For example

1
jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root --no-browser

Connect to web browser

Use your webbrowser to connect

http://[server_ip_address]:8888/

and type the password you set at the previous step

Import virtual environment

If you wish to use any virtual environment in Jupyter notebook, first intall ipykernel

1
2
pip install --user ipykernel
python -m ipykernel install --user --name=[your-env-name]

It should print this if you do it correctly
1
Installed kernelspec [your-env-name] in ~/jupyter/kernels/[your-env-name]

You will be able to see something like this (for me I have virtual environment called “rdenv” for rdkit)

If you want to uninstall, just simply write

1
2
pip install --user ipykernel
jupyter kernelspec uninstall [your-env-name]

(Optional) connect the server from other IP address

If you want to login this notebook with any IP, find jupyter_notebook_config.py at ~/.jupyter
and change the following line (around line 204):

1
2
c.NotebookApp.allow_origin = '*' # line 48
c.NotebookApp.ip = '0.0.0.0' # line 204