操作步骤
Server 端
- 在建立Jupyter服务本地端口转发的前提下SSH登入服务器:
其中:ssh -L 8889:localhost:8890 username@serverip [-p serverport]
-L 8889:localhost:8890
为本地端口转发,使得本地端口8889
可以连接到远程8890
端口下的服务,8889
和8890
(在下文对应数字含义一致,分别指Jupyter的本地端口和远程端口)均可以进行自定义,只为与默认的8888
端口不产生冲突;- 其余部分均为SSH命令的正常连接要素。
- 然后在终端执行服务启动命令:
其中:jupyter notebook --no-browser \ --allow-root \ -ip=‘*’ \ --port=8890 \ ----NotebookApp.allow_remote_access=True \ --NotebookApp.token='<custom-your-token-here>'
--no-browser
使得服务器在启动Jupyter服务时不会自动打开浏览器;--allow-root
允许以root
身份运行Jupyter;ip=‘*’
为服务监听地址,允许任意ip地址连接;port=8890
为自定义远程服务监听端口;NotebookApp.allow_remote_access=True
允许远程连接;NotebookApp.token=...
自定义访问口令,也即将登陆地址变更为https://ip.port/?<token>
形式。
Client 端
本地浏览器访问远程 Jupyter Notebook:
https://localhost:8889/?<your-custom-token-here>
扩展
如果你希望以上命令作为Jupyter Notebook
的默认设置:
- 生成
Jupyter Notebook
的配置文件:
命令输出中包含配置文件的存放地址,一般为jupyter notebook --generate-config
~/.jupyter/jupyter_notebook_config.py
; - 在`jupyter_notebook_config.py``中参考我的配置文件进行修改,其中改动的配置内容几乎与上述命令选项一致;
- 修改后即可直接在远程服务器使用
开启服务,本地连接方式则与上述方法一致。jupyter notebook