bash Jupyter/iPython Notebook 的根访问权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41622988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 15:36:50  来源:igfitidea点击:

Root access for Jupyter/iPython Notebook

bashipythonipython-notebookjupyter-notebook

提问by user42390

I'm trying to use the bash kernel in iPython/Jupyter notebook, but I need sudo access within the notebook itself.

我正在尝试在 iPython/Jupyter notebook 中使用 bash 内核,但我需要在 notebook 中使用 sudo 访问权限。

I've tried $ sudo jupyter notebookto run the notebook as root, but that only returns:

我试图$ sudo jupyter notebook以 root 身份运行笔记本,但这只返回:

$ jupyter: 'notebook' is not a Jupyter command

So, I'm left with running $ jupyter notebook(unless there's a way to run Jupyter notebook as root).

所以,我$ jupyter notebook只能继续运行(除非有办法以 root 身份运行 Jupyter notebook)。

I also can't do su rootin the notebook itself because that requires an input and the notebook won't let me give an input.

我也不能su root在笔记本本身中做,因为这需要输入,而笔记本不允许我提供输入。

Finally, there is allegedly an --allow-rootoption for Jupyter notebook: http://jupyter-notebook.readthedocs.io/en/latest/config.html

最后,据称--allow-rootJupyter 笔记本有一个选项:http://jupyter-notebook.readthedocs.io/en/latest/config.html

However, it looks like --allow_rootis no longer an option. (I've tried modifying the config file by adding NotebookApp.allow_root=True, but that doesn't work.)

然而,它看起来--allow_root不再是一种选择。(我尝试通过添加修改配置文件NotebookApp.allow_root=True,但这不起作用。)

Any ideas guys? Maybe I'm doing something wrong?

有什么想法吗?也许我做错了什么?

回答by tiagohbalves

Add c.NotebookApp.allow_root=Truefrom the root configuration files. That you don't need ask to allow-rootevery time then you start the notebook.

c.NotebookApp.allow_root=True从根配置文件添加。您不需要allow-root每次启动笔记本时都询问。

Edit:

编辑:

Before edit the configuration file you need to run jupyter notebook --generate-configas root to make the file.

在编辑配置文件之前,您需要以jupyter notebook --generate-configroot 身份运行以制作该文件。

回答by An0n

Just login as root, then do the following command to start the notebook :

只需以 root 身份登录,然后执行以下命令来启动笔记本:

jupyter notebook --allow-root

回答by Aetos

The solution as described here. Is to use

此处描述的解决方案。是用

sudo -E env "PATH=$PATH" jupyter notebook

Basically the binary to call jupyter notebookis in the user's PATHvariable, but not for root.

基本上要调用的二进制文件jupyter notebook在用户的PATH变量中,但不是针对 root 的。

Best regards.

此致。

回答by RCFuson

I am running the neopixel library from a jupyter notebook.

我正在从 jupyter notebook 运行 neopixel 库。

The only thing that worked for me was first running the "sudo su" command to move into the root environment and then run "jupyter notebook" (--allow-root alone didn't work for me).

唯一对我有用的是首先运行“sudo su”命令进入根环境,然后运行“jupyter notebook”(单独的 --allow-root 对我不起作用)。

回答by N01

You should try running the command sudo jupyter notebook --allow-root , I'm not sure why but this works. On the server it'll ask you for a password, if you have set up a password for it just type it in the box that will be shown, otherwise, type jupyter notebook password to set up a new password

您应该尝试运行命令 sudo jupyter notebook --allow-root ,我不确定为什么,但这有效。在服务器上它会要求你输入密码,如果你已经为它设置了密码,只需在显示的框中输入它,否则,输入 jupyter notebook password 来设置新密码

回答by Luis Fernando

Generate config

生成配置

root@user# jupyter notebook --generate-config

root@user# jupyter notebook --generate-config

root/.jupyter/jupyter_notebook_config.py root@user# cd .jupyter/ root@user:/.jupyter/# gedit jupyter_notebook_config.py Add line in jupyter_notebook_config.py

root/.jupyter/jupyter_notebook_config.py root@user# cd .jupyter/ root@user:/.jupyter/# gedit jupyter_notebook_config.py 在 jupyter_notebook_config.py 添加一行

c.NotebookApp.allow_root=True

c.NotebookApp.allow_root=True