-
Notifications
You must be signed in to change notification settings - Fork 2
/
how_to_jupyter_on_a_cluster
48 lines (39 loc) · 3.44 KB
/
how_to_jupyter_on_a_cluster
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
How to set up Jupyter Server on a Remote Computer via Port Forwarding thought a Gate Server?
In this example we have: PC <-> gate.rzg.mpg.de / cluster login <-> hydra / cluster on which jupyter notebook shall run
## First: NO security version: ##
1. How to start a Jupyter server on hydra.
a. Login to hydra cluster via gate, e.g.
>> ssh gate.rzg.mpg.de
>> ssh hydra08i
b. Then start a screen session in which the server can stay alive, even if the connection is closed. Checkout screen commands first, if you are not familiar with screen: screen –S, screen –list, screen –r, Strg+A – d, Strg+A – c, Strg+A – space
>> screen –S jupyter
>> jupyter notebook --no-browser --port=9876 --ip='*'
You might want to bind the command above, and some other like the ssh tunnel to an alias!!
2. Create a SSH Tunnel, which let you access the jupyter notebook directly via a port on your pc.
a. >> ssh -L 9876:hydra08i.rzg.mpg.de:9876 [email protected]
This will bind to you localhost:9876 port a connection via ssh (so this small patch is secure) to the port 9876 on hydra08i computer. It herein bypasses the gate.rzg.mpg.de node, aka tunnels.
3. Connect to your jupyter notebook via a suiting browser
a. Open firefox and type in: localhost:9876, or something similar, like http://127.0.0.1:9876
b. You should now see your jupyter notebook
BEWARE: This is not a completely secure connection and all data streams, e.g. passwords, might be transported in clear text! Also, till now EVERYBODY (with login rights to hydra) has access to your notebook and all rights of your account by hijacking your notebook!!! So let us fix that in step 4 and 5.
## Second: Good security version: ##
4. Activate password protection to your notebook.
a. Login again to your cluster login note, e.g. hydra08i, and start ipython, then
>> from IPython.lib import passwd; passwd()
Type your password twice and store the resulting sha1 key for the next step
b. Exit ipython and go to ~/.jupyter and call
>> jupyter notebook --generate-config
In this config file add your sha1 key in the line that says:
c.NotebookApp.password = u''"
Uncomment that line to activate it! If you connect again as above (1-3), you will be asked for your password. But this might be transmitted in clear text at least part of your connection!
5. To not transmit any data (i.e. passwords) in clear text, i.e. cleartext on the way to your local port, we shall create a certificate file, that allows us to activate https:// instead of http:// from above.
a. Go to you ~/.jupyter directory on your cluster, e.g. hydra08i, and produce a certificate:
>> openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mykey.key -out mycert.pem
b. Tell the next time you start your jupyter notebook server that he shall use your certificate via:
>> jupyter notebook --certfile=mycert.pem --keyfile mykey.key --port=6789 --ip="*" --no-browser
## Things are not as supposed? You want to know more? ##
i) Not working..
Have you installed anaconda? Try >> module load anaconda/3
ii) I see a strange directory when connecting to my notebook.. Check if you notebook server is running from your home directory, you might accidentally started jupyter in your ~/.jupyter directory!
iii) If you are tired of passwords, try and set a static access tokes for your notebook server: http://jupyter-notebook.readthedocs.io/en/latest/security.html
iv) If nothing helps or to learn more: check out https://jupyter-notebook.readthedocs.io/en/latest/public_server.html