今天尝试用 pycharm 远程连接服务器的 jupyter,在网上看到了一个非常 awesome 的办法,在这分享一下。
服务器启动 jupyter
我这里直接允许 root 了,可以按需求删掉–allow-root
jupyter notebook --allow-root --no-browser
本地使用 SSH 连接
ssh -N -f -L localhost:8888:localhost:8888 root@serverIP
-N 告诉 SSH 没有命令要被远程执行;
-f 告诉 SSH 在后台执行;
-L 是指定 port forwarding 的配置,前一个是本地的端口,后一个是服务器的端口。
username@serverIP 替换成服务器的对应账号。
配置 pycharm
首先把Python Interpreter
配置好,如果没配置过,也可以在这里看教程 。
然后配置 jupyter server,在Configured Server
处填 https://localhost:8888 ,即可,

测试
可以在 pycharm 享受补全,还能使用服务器的 jupyter 了。

总结
这个方法的好处是使用了 ssh,可以把服务器的 jupyter 连接到本地,比起设置jupyter_notebook_config.py
方便而且更安全。