Announcement

Collapse
No announcement yet.

How to Configure FirstUseAuthenticator on JupyterHub

Collapse
X
Collapse
  •  

  • How to Configure FirstUseAuthenticator on JupyterHub


    In a lab environment, lots of new users will be using JupyterHub. The default Authenticator of JupyterHub allows only the Linux system users to log in to JupyterHub. So, if you want to create a new JupyterHub user, you will have to create a new Linux user. Creating new Linux users manually might be a lot of hassle for you. Instead, you can configure JupyterHub to use FirstUseAuthenticator. FirstUseAuthenticator as the name says, automatically creates a new user while logging in to JupyterHub for the first time. After the user is created, the same username and password can be used to log in to JupyterHub.

    In this article, I am going to show you how to install the JupyterHub FirstUseAuthenticator on the JupyterHub Python virtual environment. I am also going to show you how to configure JupyterHub to use the FirstUseAuthenticator.

    NOTE: If you don’t have JupyterHub installed on your computer, you can read one of the articles depending on the Linux distribution you’re using:
    1. How to Install the Latest Version of JupyterHub on Ubuntu 22.04 LTS/ Debian 12/Linux Mint 21
    2. How to Install the Latest Version of JupyterHub on Fedora 38+/RHEL 9/Rocky Linux 9



    Table of Contents:

    1. Creating a Group for JupyterHub Users
    2. Installing JupyterHub FirstUseAuthenticator on the JupyterHub Virtual Environment
    3. Configuring JupyterHub FirstUseAuthenticator
    4. Restarting the JupyterHub Service
    5. Verifying if JupyterHub FirstUseAuthenticator is Working
    6. Creating New JupyterHub Users using JupyterHub FirstUseAuthenticator
    7. Conclusion
    8. References



    Creating a Group for JupyterHub Users:

    I want to keep all the new JupyterHub users in a Linux group jupyterhub-users for easier management.

    You can create a new Linux group jupyterhub-users with the following command:

    $ sudo groupadd jupyterhub-users




    Installing JupyterHub FirstUseAuthenticator on the JupyterHub Virtual Environment:

    If you’ve followed my JupyterHub Installation Guide to install JupyterHub on your favorite Linux distributions (Debian-based and RPM-based), you can install the JupyterHub FirstUseAuthenticator on the JupyterHub Python virtual environment with the following command:

    $ sudo /opt/jupyterhub/bin/python3 -m pip install jupyterhub-firstuseauthenticator




    The JupyterHub FirstUseAuthenticator should be installed on the JupyterHub virtual environment.





    Configuring JupyterHub FirstUseAuthenticator:

    To configure the JupyterHub FirstUseAuthenticator, open the JupyterHub configuration file jupyterhub_config.py with the nano text editor as follows:

    $ sudo nano /opt/jupyterhub/etc/jupyterhub/jupyterhub_config.py




    Type in the following lines in the jupyterhub_config.py configuration file.

    # Configure FirstUseAuthenticator for Jupyter Hub



    from jupyterhub.auth import LocalAuthenticator



    from firstuseauthenticator import FirstUseAuthenticator



     



    LocalAuthenticator.create_system_users = True



    LocalAuthenticator.add_user_cmd = ['useradd', '--create-home', '--gid', 'jupyterhub_users' , '--shell', '/bin/bash']



    FirstUseAuthenticator.dbm_path = '/opt/jupyterhub/etc/jupyterhub/passwords.dbm'



    FirstUseAuthenticator.create_users = True



     



    class LocalNativeAuthenticator(FirstUseAuthenticator, LocalAuthenticator):



    pass



     



    c.JupyterHub.authenticator_class = LocalNativeAuthenticator




    Once you’re done, press + X followed by Y and to save the jupyterhub_config.py file.





    Restarting the JupyterHub Service:

    For the changes to take effect, restart the JupyterHub systemd service with the following command:

    $ sudo systemctl restart jupyterhub.service




    If the JupyterHub configuration file has no errors, the JupyterHub systemd service should run just fine.





    Verifying if JupyterHub FirstUseAuthenticator is Working:

    To verify whether the JupyterHub FirstUseAuthenticator is working, visit JupyterHub from your favorite web browser and try to log in as a random user with a short and easy password like 123, abc, etc.

    You should see the marked error message that the password is too short and the password should be at least 7 characters long. It means that the JupyterHub FirstUseAuthenticator is working just fine.





    Creating New JupyterHub Users using JupyterHub FirstUseAuthenticator:

    To create a new JupyterHub user using the FirstUseAuthenticator, visit the JupyterHub login page from a web browser, type in your desired login username and the password that you want to set for the new user, and click on Sign in.





    A new JupyterHub user should be created and your desired password should be set for the new user.

    Once the new user is created, the newly created user should be logged into his/her JupyterHub account.





    The next time you try to log in as the same user with a different password, you will see the error Invalid username or password. So, once a user is created using the FirstUseAuthenticator, only that user can log in with the same username and password combination. No one else can replace this user account.





    Conclusion:

    In this article, I have shown you how to install the JupyterHub FirstUseAuthenticator on the JupyterHub Python virtual environment. I have also shown you how to configure JupyterHub to use the FirstUseAuthenticator.



    References:








    More...
      Posting comments is disabled.

    Categories

    Collapse

    Article Tags

    Collapse

    There are no tags yet.

    Latest Articles

    Collapse

    • 5 Compelling Reasons to Choose Linux Over Windows
      by Kasimba



      by George Whittaker


      Introduction

      In the world of operating systems, Windows has long held the lion’s share of the market. Its user-friendly interface and wide compatibility have made it the default choice for many. However, in recent years, Linux has steadily gained traction, challenging the status quo with its unique offerings. What was once considered the domain of tech enthusiasts and developers is now...
      Yesterday, 06:52 AM
    • NGINX vs Apache; Web Server Comparison
      by Kasimba
      Overview of NGINX and Apache

      NGINX and Apache are leading web server solutions utilized for hosting websites and web applications. Apache, developed by the Apache Software Foundation, offers robust configuration options and extensibility. NGINX, created by Igor Sysoev, is known for its efficiency in handling numerous concurrent connections with low resource utilization. Both servers function not only as HTTP servers but also as reverse proxies, load balancers, and more.

      What is

      ...
      Yesterday, 03:54 AM
    • Monthly News – November 2024
      by Kasimba
      Hi everyone, I hope you are enjoying the BETA so far! This release introduces new features, tools, and artwork, so we anticipate a good number of bug reports. Every single fix helps us refine and improve the final release. Your feedback during the BETA phase is extremely important to us. Linux Mint 22.1 is our […]

      More...
      12-16-2024, 11:50 AM
    • Mastering OpenSSH for Remote Access on Debian Like a Pro
      by Kasimba



      by George Whittaker


      Introduction

      Remote access is a cornerstone of modern IT infrastructure, enabling administrators and users to manage systems, applications, and data from virtually anywhere. However, with great power comes great responsibility—ensuring that remote access remains secure is paramount. This is where OpenSSH steps in, providing robust, encrypted communication for secure remote management....
      12-13-2024, 10:31 PM
    • Unlocking the Full Potential of Linux's Most Versatile Search Tool
      by Kasimba



      by George Whittaker


      Introduction

      The grep command, short for "global regular expression print," is one of the most powerful and frequently used tools in Unix and Linux environments. From sifting through log files to finding patterns in text, grep is a Swiss Army knife for system administrators, developers, and data analysts alike. However, many users limit themselves to its basic functionality, unaware...
      12-13-2024, 09:24 PM
    • Linux Mint 22.1 “Xia” – BETA Release
      by Kasimba
      This is the BETA release for Linux Mint 22.1 “Xia”. Linux Mint 22.1 is a long term support release which will be supported until 2029. It comes with updated software and brings refinements and many new features to make your desktop even more comfortable to use. New features: This new version of Linux Mint contains […]

      More...
      12-12-2024, 09:31 AM
    Working...
    X