我了解到 Jupyter-notebook 可以配置密码而不是 token 。
两步-
$ jupyter notebook password
Enter password: ****
Verify password: ****
[NotebookPasswordApp] Wrote hashed password to /Users/you/.jupyter/jupyter_notebook_config.json
我想自动化这个过程(在 Dockerfile 中,当提示输入密码时我将无法手动输入),像这样,
echo 'password' | jupyter notebook password
当系统提示输入密码 和验证密码 时,这应该会自动将我的“密码”
输入到 shell
你能给我一个 shell 命令吗,它可以在没有用户干预的情况下自动设置密码。
最佳答案
1。使用 passwd 生成哈希功能
在控制台中手动为 your_password 生成哈希:
In [1]: from notebook.auth import passwd; passwd()
Enter password: *************
Verify password: *************
Out[1]: 'sha1:a58051cdbd5c:8ee35109f0076445b37be17d926e56bee5910bea'
或在脚本中:
$ python3 -c "from notebook.auth import passwd; print(passwd('your_password'))"
sha1:a58051cdbd5c:8ee35109f0076445b37be17d926e56bee5910bea
2。使用 NotebookApp.password param 运行 jupyter
开始时:
jupyter notebook --NotebookApp.password='sha1:a58051cdbd5c:8ee35109f0076445b37be17d926e56bee5910bea'
或通过 jupyter 配置,例如在 Dockerfile 中,如 this answer :
RUN jupyter notebook --generate-config
RUN echo "c.NotebookApp.password='sha1:a58051cdbd5c:8ee35109f0076445b37be17d926e56bee5910bea'">>/root/.jupyter/jupyter_notebook_config.py
关于linux - 从命令行自动配置 Jupyter 密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47092878/