How to enable user specific kernels like PY2, PY3 and R in Jupyterhub

Currently i have setup jupyterhub and added programming language kernels like Python3, R and Java.

When i login jupyterhab from admin user i m able to view all this 3 kernels(Launchers Python3, R and Java)

However, if i login from user like User1, i able get all 3 kernels. now i want only specific kernel like R for user1.

Please guide me how can i enable user specific kernels like PY3, Pyspark and R for User1, User2 and User3 respectively on Jupyterhub

Regards, Zain

This will depend on what Spawner you use. If it is a shared system as with the default or systemd spawners, to make kernels available for all users, you can install them system- or env-wide. If you want kernels to only be available for one user, you can install the kernels for just that user. Check jupyter kernelspec list to see the paths where kernels are installed. You can move them to other locations on jupyter --paths (the data directories) that are per-user.

If you want to set the default kernel whitelist on a per-user basis, you can do this in jupyter configuration:

# /etc/jupyter/jupyter_config.py
import os
jupyterhub_user = os.environ.get("JUPYTERHUB_USER")
if jupyterhub_user and jupyterhub_user in {'myname', 'othername'}:
    # only the 'ir' kernel is allowed for these users:
    c.KernelSpecManager.whitelist = {"ir","pyspark"}

The keys in that set should be the keys you see in jupyter kernelspec list.

1 Like

Hi,

These are the details i have setup my jupyterhub…

#Create a whitelist of users
c.Authenticator.whitelist = {'demo01', 'demo02', 'zain'}
c.Authenticator.admin_users = {'zain'}

jupyter-kernelspec list

Available kernels:
  ir         /root/.local/share/jupyter/kernels/ir
  pyspark    /share/apps/platform/ai/py36/3_6_9/share/jupyter/kernels/pyspark
  python3    /share/apps/platform/ai/py36/3_6_9/share/jupyter/kernels/python3

I have added this code on jupyterhub_config.py for setting user specific kernels as you suggested…

            import os
            jupyterhub_user = os.environ.get("demo01")
            if jupyterhub_user and jupyterhub_user in {'demo01', 'demo02'}:
                # only the 'ir' kernel is allowed for these users:
                c.KernelSpecManager.whitelist = {"ir"}

Still “ir” kernel not getting reflected to user - demo01
please help me out to resolve this.

Regards,
Zain