首先是要 安裝 Anaconda
。
預設情況下,安裝好 Anaconda 後打開 jupyter notebook, 通路本地
localhost:8888
即可。但是如果要通路另一台機器,比如遠端伺服器上的 notebook, 即預設是不支援 172.104.105.119:8888
這樣的通路,需要額外配置。
設定 jupyter notebook 可遠端通路的官方指南在
這裡 ,在遠端伺服器上執行以下操作:1. 生成一個 notebook 配置檔案
預設情況下,配置檔案
~/.jupyter/jupyter_notebook_config.py
并不存在,需要自行建立。使用下列指令生成配置檔案:
jupyter notebook --generate-config
- 1
如果是 root 使用者執行上面的指令,會發生一個問題:
Running as root it not recommended. Use --allow-root to bypass.
提示資訊很明顯,root 使用者執行時需要加上
--allow-root
選項。
jupyter notebook --generate-config --allow-config
執行成功後,會出現下面的資訊:
Writing default config to: /root/.jupyter/jupyter_notebook_config.py
2. 生成密碼
自動生成
從 jupyter notebook 5.0 版本開始,提供了一個指令來設定密碼:
jupyter notebook password
,生成的密碼存儲在
jupyter_notebook_config.json
$ jupyter notebook password
Enter password: ****
Verify password: ****
[NotebookPasswordApp] Wrote hashed password to /Users/you/.jupyter/jupyter_notebook_config.json
手動生成
除了使用提供的指令,也可以通過手動安裝,我是使用的手動安裝,因為
jupyter notebook password
出來一堆内容,沒耐心看。打開 ipython 執行下面内容:
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed
這一串就是要在
jupyter_notebook_config.py
添加的密碼。
c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
3. 修改配置檔案
在
jupyter_notebook_config.py
中找到下面的行,取消注釋并修改。
c.NotebookApp.ip='*'
c.NotebookApp.password = u'sha:ce...剛才複制的那個密文'
c.NotebookApp.open_browser = False
c.NotebookApp.port =8888 #可自行指定一個端口, 通路時使用該端口
以上設定完以後就可以在伺服器上啟動 jupyter notebook,
jupyter notebook
, root 使用者使用
jupyter notebook --allow-root
。打開
IP:指定的端口
, 輸入密碼就可以通路了。
需要注意的是不能在隐藏目錄 (以 . 開頭的目錄)下啟動 jupyter notebook, 否則無法正常通路檔案。

參考:
[1]
http://jupyter-notebook.readthedocs.io/en/latest/public_server.html#notebook-server-security