由于实验室的服务器没有图形界面,所以需要在本地电脑上通过浏览器访问服务器上的Jupyter程序。记录下远程访问Jupyter的方法。
其实非常简单,可以分为这样几步:
- 在服务器上安装了Jupyter
- 生成jupyter的密码:
jupyter notebook password
密码加密后的值可以在
/home/{username}/.jupyter/jupyter_notebook_config.json
看到,复制下来,在第4步将它加入jupyter的配置文件里。
4. 在/home/{username}/.jupyter/jupyter_notebook_config.py配置文件里加上几行配置信息
c.NotebookApp.allow_remote_access = True
# Set ip to '*' to bind on all interfaces (ips) for the public server
c.NotebookApp.ip = '*'
c.NotebookApp.password = u'{jupyter的密码加密后的值}'
c.NotebookApp.open_browser = False
# It is a good idea to set a known, fixed port for server access
c.NotebookApp.port = {服务器运行jupyter的端口号}
- 在服务器上运行命令jupyter notebook或jupyter lab
- 在本地电脑上运行命令
ssh -N -f -L {绑定的本地端口号}:localhost:{服务器运行jupyter的端口号} {服务器用户名}@{服务器ip} -p {ssh端口号} -i {ssh公钥文件地址} - 在本地浏览器打开http://l