啟用 jupyter notebook
jupyter notebook --ip='*'
加上 --ip='*' 讓 localhost 以外的機器也能存取 notebook
這樣的做法 預設是沒有權限上的管理 也就是 任何人只要知道 notebook 的網址 就能使用它
- 設定密碼
- 設定 ssl
- Running a notebook server
- http://jupyter-notebook.readthedocs.io/en/latest/public_server.html
設定密碼
我們編輯 jupyter_notebook_config.py 設定密碼
在 jupyter_notebook_config.py 內 紀錄的不是密碼的明碼 而是 hash 過後的值
在 python shell 可以產生 密碼的 hash 值
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
如果你沒有 jupyter_notebook_config.py 先輸入指令產生
jupyter notebook --generate-config
有了這個檔案後 (預設的位置是 ~/.jupyter/jupyter_notebook_config.py )
在檔案內 加上 密碼的 hash 即可 如下
c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
設定 ssl
在啟用密碼後 接著便是搭配 ssl 這樣做 hash 過後的密碼被傳送時才會被加密
在啟用 jupyter notebook 的指令 多加上設定 ssl 憑證的選項
jupyter notebook --certfile=mycert.pem --keyfile mykey.key
產生憑證 ( A self-signed certificate )
$ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mykey.key -out mycert.pem
jupyter_notebook_config.py 設定 ssl, 設定密碼
- 每次啟動 都要記得輸入
- --certfile=mycert.pem --keyfile mykey.key 有些麻煩
我們可以在 jupyter_notebook_config.py 設定
# Set options for certfile, ip, password, and toggle off
# browser auto-opening
c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'
c.NotebookApp.keyfile = u'/absolute/path/to/your/certificate/mykey.key'
# Set ip to '*' to bind on all interfaces (ips) for the public server
c.NotebookApp.ip = '*'
c.NotebookApp.password = u'sha1:bcd259ccf...<your hashed password here>'
c.NotebookApp.open_browser = False
# It is a good idea to set a known, fixed port for server access
c.NotebookApp.port = 9999
之後只要輸入
jupyter notebook
Reference
Running a notebook server
http://jupyter-notebook.readthedocs.io/en/latest/public_server.html
http://jupyter-notebook.readthedocs.io/en/4.x/public_server.html