linux - 从命令行自动配置 Jupyter 密码

标签 linux bash shell ubuntu command-line

我了解到 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/

相关文章:

linux - 如何跟踪写入同一日志文件的多个线程

linux - 使用 Eclipse 从 Portaudio 编译 paex_record_file.c 时未定义对 `PaUtil_GetRingBufferReadAvailable' 的引用

python - UTF-8 和 os.listdir()

linux - 多线程ping脚本

linux - Bash-检查目录中存在什么类型的文件

linux - 如何将shell变量传递给shell脚本中的awk命令

linux - 我可以在 Linux 中混合文本和二进制文件吗?

linux - 如何在 shell 行中捕获选项卡按钮?

c++ - 这个实例中#define 的 Action 是什么?

bash - 如何在最小的 shell 中递归搜索目录(没有 grep、find 等)?