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

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

$ 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).

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

Finally, there is allegedly an --allow-root option for Jupyter notebook:

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

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

2

8 Answers

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

jupyter notebook --allow-root 

The solution as described here. Is to use

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

Basically the binary to call jupyter notebook is in the user's PATH variable, but not for root.

Best regards.

1

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

Edit:

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

2

I am running the neopixel library from a jupyter notebook.

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).

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

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

c.NotebookApp.allow_root=True

1

When I need to execute command as root in my notebook, I use the -A flag, that allows to access an helper program used to read the user's password when no terminal is available. You need to modify the sudo.conf file before to declare the helper program. On a Debian Buster, I personnaly added:

Path askpass: /usr/libexec/seahorse/ssh-askpass

See the main page of sudo.conf for more information.

In case anyone is still looking for an answer, this is what worked for me:

sudo ~/.local/bin/jupyter-notebook --allow-root 

Switching user using su didn't work because I didn't have jupyter installed on root. Using just --allow-root by itself also didn't work for me. This allows you to run sudo with jupyter notebook without running into the issue of "notebook" not being a valid command. Because I am using a linux terminal, jupyter-notebook is installed at ~/.local/bin/jupyter-notebook. See After installing with pip, "jupyter: command not found" for more information about where jupyter may be installed.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy