1. 在远程服务器上,启动jupyter notebooks服务:
jupyter notebook --no-browser --port=8889
2. 在本地机器的Terminal中启动SSH:
#ssh -N -f -L localhost:8888:localhost:8889 remote_user@remote_host
其中: -N 告诉SSH没有命令要被远程执行; -f 告诉SSH在后台执行; -L 是指定port forwarding的配置,远端端口是8889,本地的端口号的8888。remote_user@remote_host 用实际的远程帐户和远程地址替换。现在打开浏览器,输入地址:http://localhost:8888/,即可在浏览器远程使用jupyter notebook。
3. 在Pycharm中设置: File | Settings | Build, Execution, Deployment | Jupyter | Jupyter Servers:
选中Configured Server 网址填 http://localhost:8888/, 之后再打开ipynb文件运行,在新的弹窗中输入远程服务器上jupyter notebooks的token:
至此连接完成。