如何禁用Jupyter笔记本会话的密码请求?

时间:2016-12-15 08:43:44

标签: python ipython jupyter-notebook python-3.5 jupyter

我使用以下命令多年来一直在推出Jupyter Notebook:

jupyter-notebook --port=7000 --no-browser --no-mathjax

当我尝试在浏览器上打开jupyter时,它会向我询问密码,即使我之前从未设置过任何密码。 重要的是要注意,如果我将端口设置为不同于7000 (eg., the default 8888)的值,则接口将打开而没有问题

我在本地运行jupyter,并在以下设置中运行:

Python 3.5.2

安装了以下模块:

jupyter (1.0.0), jupyter-client (4.4.0), jupyter-console (5.0.0), jupyter-core (4.2.1), ipykernel (4.5.2), ipython (5.1.0), ipython-genutils (0.1.0), nbconvert (4.3.0), nbformat (4.2.0), notebook (4.3.0)

注意:我没有jupyter配置文件

以下是服务器的一些输出行:

[I 19:16:24.358 NotebookApp] Serving notebooks from local directory: /Users/my_user_name
[I 19:16:24.358 NotebookApp] 0 active kernels
[I 19:16:24.358 NotebookApp] The Jupyter Notebook is running at: http://localhost:7000/?token=aa0dab6e2d85766f3e2e4f0f6633e4473db56a56c94cac76
[I 19:16:24.358 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

在尝试在浏览器上打开它(使用端口7000)后,下面是消息

[I 19:21:56.848 NotebookApp] 302 GET /tree (::1) 8.46ms
[D 19:21:56.857 NotebookApp] Using contents: services/contents
[D 19:21:56.919 NotebookApp] Path base/images/favicon.ico served from /usr/local/lib/python3.5/site-packages/notebook/static/base/images/favicon.ico
[D 19:21:56.920 NotebookApp] Path components/jquery-ui/themes/smoothness/jquery-ui.min.css served from /usr/local/lib/python3.5/site-packages/notebook/static/components/jquery-ui/themes/smoothness/jquery-ui.min.css
[D 19:21:56.922 NotebookApp] Path components/jquery-typeahead/dist/jquery.typeahead.min.css served from /usr/local/lib/python3.5/site-packages/notebook/static/components/jquery-typeahead/dist/jquery.typeahead.min.css
[D 19:21:56.923 NotebookApp] Path style/style.min.css served from /usr/local/lib/python3.5/site-packages/notebook/static/style/style.min.css
[D 19:21:56.925 NotebookApp] Path auth/css/override.css served from /usr/local/lib/python3.5/site-packages/notebook/static/auth/css/override.css
[D 19:21:56.926 NotebookApp] Path components/es6-promise/promise.min.js served from /usr/local/lib/python3.5/site-packages/notebook/static/components/es6-promise/promise.min.js
[D 19:21:56.926 NotebookApp] Path components/requirejs/require.js served from /usr/local/lib/python3.5/site-packages/notebook/static/components/requirejs/require.js
[D 19:21:56.933 NotebookApp] Path base/images/logo.png served from /usr/local/lib/python3.5/site-packages/notebook/static/base/images/logo.png
[D 19:21:56.934 NotebookApp] 200 GET /login?next=%2Ftree (::1) 80.86ms
[D 19:21:57.001 NotebookApp] Path custom.css served from /usr/local/lib/python3.5/site-packages/notebook/static/custom/custom.css
[D 19:21:57.003 NotebookApp] 304 GET /custom/custom.css (::1) 3.11ms
[D 19:21:57.341 NotebookApp] Path auth/js/main.min.js served from /usr/local/lib/python3.5/site-packages/notebook/static/auth/js/main.min.js
[D 19:21:57.344 NotebookApp] 200 GET /static/auth/js/main.min.js?v=20161219191623 (::1) 3.57ms

此时有一个来自jupyter的页面,要求我插入一个我从未设置过的密码。

解决!

随着笔记本电脑模块(4.3.1)的最新更新,问题已经解决。

启动jupyter笔记本后,系统会提示用户在第一次连接时将URL粘贴到浏览器中:

Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
    http://localhost:7000/?token=32be0f5ee74cfe521187bc479855ce8b9fbab9e8021701c9

这解决了这个问题!

9 个答案:

答案 0 :(得分:18)

您可以使用以下命令完全删除密码:

go build -ldflags "-X config.Version=1.0.0" -o $(MY_BIN) $(MY_SRC)

没有jupyter notebook --ip='*' --NotebookApp.token='' --NotebookApp.password='' ,当从远程计算机连接到本地时,只需使用:

--NotebookApp.password=''

出于安全原因,它仍然要求输入密码,因为具有访问权限的用户可以在服务器计算机上运行任意Python代码!

在Jupyter 4.4.x上测试过。

答案 1 :(得分:6)

Notebook 4.3.0默认启用了登录安全性。要在密码字段中输入的令牌在启动期间打印在notebok服务器的输出中(或者可以直接包含在URL中)

The Jupyter Notebook is running at: http://0.0.0.0:8888/?token=f3e7fa23fb7e347ad05914368b625416b7a95a674dc078f7

有关详情,请参阅http://jupyter-notebook.readthedocs.io/en/latest/security.html#server-security,包括停用该功能。

但是,这并不能解释为什么在一个端口上运行而不在另一个端口上运行时获得密码提示

答案 2 :(得分:3)

您可以首先使用以下命令创建一个jupyter配置文件:

cd〜/ .jupyter

jupyter笔记本--generate-config 然后在创建的配置文件中将c.NotebookApp.token参数设置为空字符串

c.NotebookApp.token =''

如评论中所述,设置为空字符串会完全禁用身份验证,这是不推荐的。

答案 3 :(得分:2)

自上次更新jupyter-notebook软件包以来,我的机器出现了同样的问题。安装版本后

jupyter-notebook-4.3.0-1-any.pkg.tar.xz
它提示我输入我从未设置过的密码。 降级

jupyter-notebook-4.2.3-1-any.pkg.tar.xz

帮助我保持系统的生产环境。当然,只是一个快速补丁

我也想知道密码的设置位置,因为我的.jupyter - 文件夹中没有明确的配置文件。用

设置我自己的
password_required=False

没有任何区别。

答案 4 :(得分:2)

如果您尝试从docker开始运行而没有密码,请像下面这样使用CMD

CMD ["jupyter", "notebook", "--no-browser","--NotebookApp.token=''","--NotebookApp.password=''"]

答案 5 :(得分:2)

我通过在命令行上运行jupyter_notebook_config.json来替换jupyter notebook password中的密码来解决令牌认证的问题:

(base) C:\WINDOWS\system32>jupyter notebook list
http://localhost:8888/ :: C:\Users\320089053
http://localhost:8889/ :: C:\Users\320089053

(base) C:\WINDOWS\system32>jupyter notebook list
Enter password:
Verify password:
[NotebookPasswordApp] Wrote hashed password to C:\Users\320089053\.jupyter\jupyter_notebook_config.json

答案 6 :(得分:1)

如何通过禁用jupyter Notebook密码和令牌来避免“无效凭据”

首先打开 Anaconda提示

  1. 输入命令 jupyter notebook --generate-config

enter image description here

  1. 从jupyter目录中,编辑 jupyter_notebook_config.py

对以下命令进行了更改

 c.NotebookApp.token = ''
 c.NotebookApp.password = u''
 c.NotebookApp.open_browser = True
 c.NotebookApp.ip = 'localhost'

现在从anaconda导航器中启动jupyter笔记本电脑肯定可以解决问题。

答案 7 :(得分:0)

对我来说,上述解决方案不适用于Docker。

以下解决方案在Linux上就像一个魅力:

详细信息:

  • 使用的图片:tensorflow/tensorflow:latest-py3-jupyter
  • 我配置的
  • 密码:'password'
  • 以用户(不是root)身份运行Jupyter

使用您预定义的密码在Docker中启动Jupyter的步骤:

  1. export JUPYTER_TOKEN='password'
  2. docker run -it --rm -p 8888:8888 -u $(id -u ${USER}):$(id -g ${USER}) -e JUPYTER_TOKEN=$JUPYTER_TOKEN -v /home/<user>/jupyter:/tf/ tensorflow/tensorflow:latest-py3-jupyter
  3. 打开http://localhost:8888并使用“密码”作为密码
  4. 在ypur浏览器中保存密码

对我来说,这是摆脱烦人的令牌身份验证的最简单方法。

答案 8 :(得分:0)

这个答案只是为了总结其他人所说的话,并在其他答案中讨论的令牌事情上给我两分钱。

发生在 OP 上的是 Jupyter 实例的密码被设置在他的环境中——某处——。 (他直接或间接设置,都没有关系;就我而言,我很漂亮,我故意设置它然后忘记了。)情况是无法使用 jupyter notebook 实例,因为密码未知/丢失/忘记了。

有两种方法可以永久执行此操作:

  1. 使用 Jupyter cli 更改密码:

    $ jupyter notebook password
    
    <块引用>

    我试图在这里设置一个密码,但显然 Jupyter 不允许这样做,如果你不填写它,就会为你生成一些东西。

  2. 编辑您的 Jupyter 配置1。特别是,我希望 Jupyter 停止要求密码/令牌:

    • 我将 jupyter_notebook_config.json 中的 NotebookApp-token 值替换为 字符串:
      $ cat ~/.jupyter/jupyter_notebook_config.json
      {
        "NotebookApp": {
          "token": ""
        }
      }
      
      

就是这样。现在,每当出现 jupyter notebook 的新实例时,您都应该被要求输入密码或令牌。