jupyter-notebook远程登录

jupyter notebook是一个基于客户端-服务器架构的web应用,但是默认仅能运行在本地,可以通过配置开放远程服务器端口

本文实现单用户远程访问功能,如果要实现多用户访问,参考JupyterHub

生成配置文件

使用参数--generate-config生成配置文件jupyter_notebook_config.py,存储在~/.jupyter文件夹

1
2
$ jupyter notebook --generate-config
Writing default config to: /home/zj/.jupyter/jupyter_notebook_config.py

修改监听ip地址

修改服务器监听ip地址

1
2
## The IP address the notebook server will listen on.
#c.NotebookApp.ip = 'localhost'

默认为localhost(就是本地),允许所有ip地址访问

1
c.NotebookApp.ip = '*'

远程登录

在远程服务器修改完配置文件后,启动jupyter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ jupyter notebook
[W 11:13:25.418 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 11:13:25.423 NotebookApp] Serving notebooks from local directory: /home/zj/software/tutorial
[I 11:13:25.423 NotebookApp] 0 active kernels
[I 11:13:25.424 NotebookApp] The Jupyter Notebook is running at: http://[all ip addresses on your system]:8888/?token=e78e227ffb28ede99b5b7d576459335fd265e886d834ec32
[I 11:13:25.424 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 11:13:25.424 NotebookApp] No web browser found: could not locate runnable browser.
[C 11:13:25.424 NotebookApp]

Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8888/?token=e78e227ffb28ede99b5b7d576459335fd265e886d834ec32
[I 11:13:41.883 NotebookApp] 302 GET / (192.168.0.140) 0.94ms
[I 11:13:41.915 NotebookApp] 302 GET /tree? (192.168.0.140) 1.24ms

在本地浏览器输入远程IP:8888,就能进入页面,还需要输入token在输入日志中

密码设置

可以进行密码设置以加强安全性

相关阅读