最近工作站的驅動崩了,無法顯示圖形界面,也沒辦法teamviewer了,這時候又需要運行ipython notebook,咋辦呢,幸好搜羅到兩種方法遠程訪問jupyter notebook的方法:
方法1. ssh遠程使用jupyter notebook
- 在遠程服務器上,啟動jupyter notebooks服務:
jupyter notebook --no-browser --port=8889
- 在本地終端中啟動SSH:
ssh -N -f -L localhost:8888:localhost:8889 username@serverIP
其中: -N 告訴SSH沒有命令要被遠程執(zhí)行; -f 告訴SSH在后臺執(zhí)行; -L 是指定port forwarding的配置,遠端端口是8889,本地的端口號的8888。
注意:username@serverIP替換成服務器的對應賬號。
- 最后打開瀏覽器,訪問:http://localhost:8888/
方法2. 利用jupyter notebook自帶的遠程訪問功能
官方指南在此:官方指南
- 生成默認配置文件
jupyter notebook --generate-config
- 生成訪問密碼(token)
終端輸入ipython
,設置你自己的jupyter訪問密碼,注意復制輸出的sha1:xxxxxxxx
密碼串
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:xxxxxxxxxxxxxxxxx'
- 修改
./jupyter/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
- 最后打開瀏覽器,訪問:http://ip:8888/
方法3:
配置自己的config文件,如./jupyter/jupyter_notebook_config_backup.py
jupyter notebook --config ./jupyter/jupyter_notebook_config_backup.py