Launch jupyterhub-singleuser with sudo privileges

My use case for jupyterhub requires that each user be able to access low-level resources of the system, which are only accessible with high-privileges (sudo).

So basically what I am trying to do is:

c.Spawner.cmd = "sudo jupyterhub-singleuser"

Of course, this does not work as this is not interpreted as a single file. I have tried a similar approach with a bash script, but the process simply timesout.

Is there any way that I can go about this?

I really appreciate any help you can provide.

One option is to use a wrapper script, see for example

Hi @manics thanks for your response.

This is exactly what I am trying to do. However, neither source nor exec are actual commands I can execute with sudo.

I actually tried a dirty workaround with one more wrapper script, which then I would call with sudo. But that gives me an exception.

asyncio.exceptions.TimeoutError: Timeout

Not sure what is the cause.

Can you share your scripts?

Sure, but they are basically what you showed.

The script being called:

c.Spawner.cmd = "/home/root/"

The script:


source ./etc/profile.d/

# actually launch the single-user server
# - exec replaces the current process (avoids extra intermediate process)
# - $@ passed through arguments, so this script behaves the same as the default command
exec /usr/local/share/pynq-venv/bin/jupyterhub-singleuser $@

Running this works, but does not gives me the correct permissions. Doing something like:

sudo exec /usr/local/share/pynq-venv/bin/jupyterhub-singleuser $@

Does not work, as exec is not an actual command. Furthermore, if I try to launch jupyterhub-singleuser with:

sudo /usr/local/share/pynq-venv/bin/jupyterhub-singleuser

I simply get that timeout exception.