最近工作站的驅(qū)動崩了,無法顯示圖形界面,也沒辦法teamviewer了,這時候又需要運行ipython notebook,咋辦呢,幸好搜羅到兩種方法遠(yuǎn)程訪問jupyter notebook的方法:
方法1. ssh遠(yuǎn)程使用jupyter notebook
- 在遠(yuǎn)程服務(wù)器上,啟動jupyter notebooks服務(wù):
jupyter notebook --no-browser --port=8889
- 在本地終端中啟動SSH:
ssh -N -f -L localhost:8888:localhost:8889 username@serverIP
其中: -N 告訴SSH沒有命令要被遠(yuǎn)程執(zhí)行; -f 告訴SSH在后臺執(zhí)行; -L 是指定port forwarding的配置,遠(yuǎn)端端口是8889,本地的端口號的8888。
注意:username@serverIP替換成服務(wù)器的對應(yīng)賬號。
- 最后打開瀏覽器,訪問:http://localhost:8888/
方法2. 利用jupyter notebook自帶的遠(yuǎn)程訪問功能
官方指南在此:官方指南
- 生成默認(rèn)配置文件
jupyter notebook --generate-config - 生成訪問密碼(token)
終端輸入ipython,設(shè)置你自己的jupyter訪問密碼,注意復(fù)制輸出的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中對應(yīng)行如下
c.NotebookApp.ip='*'
c.NotebookApp.password = u'sha:ce...剛才復(fù)制的那個密文'
c.NotebookApp.open_browser = False
c.NotebookApp.port =8888 #可自行指定一個端口, 訪問時使用該端口
- 在服務(wù)器上啟動
jupyter notebook
jupyter notebook - 最后打開瀏覽器,訪問:http://ip:8888/
方法3:
配置自己的config文件,如./jupyter/jupyter_notebook_config_backup.py
jupyter notebook --config ./jupyter/jupyter_notebook_config_backup.py