jupyter提供两种认证控制机制:密码保护和token保护,token保护在4.3版本开始会被默认开启,如需要使用密码保护,需要修改配置文件jupyter_notebook_config.py中的配置
c.NotebookApp.password = u'your-pass-str'
配置文件
配置文件jupyter_notebook_config.py的默认位置为:
- Windwos : C:\Users\USERNAME.jupyter\jupyter_notebook_config.py
- OS X /Users/USERNAME/.jupyter/jupyter_notebook_config.py
- Linux: /home/USERNAME/.jupyter/jupyter_notebook_config.py
如果没有配置文件,可通过命令
jupyter notebook --generate-config
生产默认配置文件。
设置密码
依据版本的不同,可以通过不同的方式设置密码
手工配置密码
5.0之前的版本,配置密码,需要进入REPL
from notebook.auth import passwd
passwd()
连续输入两遍密码后,得到可用于配置的密码串。
将密码串添加到配置文件jupyter_notebook_config.py
c.NotebookApp.password = u'sha1:xxxxxxxxxxxx,xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
自动设置密码
5.0开始提供了专用与密码设置的命令,可实现密码设置,修改
jupyter notebook password
设置的密码存储在配置文件:jupyter_notebook_config.json, 该文件优先级高于jupyter_notebook_config.py
通过表单设置密码
5.3开始的版本在第一次通过token访问notebook服务的时候,会有选项表单用于设置密码访问,可以在第一次访问的时候设置密码,禁用token保护。

本文介绍了如何在Jupyter Notebook中设置密码保护,包括手动配置密码、自动设置密码的方法,以及不同版本的配置差异。用户可以依据版本选择合适的方式,确保Jupyter的安全访问。

348

被折叠的 条评论
为什么被折叠?



