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

    • HAProxy on Ubuntu: Load Balancing and Failover for Resilient Infrastructure
      by Kasimba



      by german.suarez


      Introduction

      In today’s fast-paced digital landscape, ensuring the availability and performance of applications is paramount. Modern infrastructures require robust solutions to distribute traffic efficiently and maintain service availability even in the face of server failures. Enter HAProxy, the de facto standard for high-performance load balancing and failover.


      This article...
      Today, 03:00 PM
    • Providing a license for package sources
      by Kasimba
      Arch Linux hasn't had a license for any package sources (such as PKGBUILD files) in the past, which is potentially problematic. Providing a license will preempt that uncertainty.

      In RFC 40 we agreed to change all package sources to be licensed under the very liberal 0BSD license. This change will not limit what you can do with package sources. Check out the RFC for more on the rationale and prior discussion.

      Before we make this change, we will provide contributors with...
      11-19-2024, 09:21 AM
    • Linux Binary Analysis for Reverse Engineering and Vulnerability Discovery
      by Kasimba



      by George Whittaker


      Introduction

      In the world of cybersecurity and software development, binary analysis holds a unique place. It is the art of examining compiled programs to understand their functionality, identify vulnerabilities, or debug issues—without access to the original source code. For Linux, which dominates servers, embedded systems, and even personal computing, the skill of binary analysis is...
      11-18-2024, 07:10 PM
    • Ubuntu vs Debian: Linux Distributions Compared Deep Dive
      by Kasimba
      Debian and Ubuntu are two popular Linux distributions. In this deep dive we will guide you on the key differences between them from perspective of both corporate enterprise and personal productivity or pleasure usage. After reading this blog post you should be in a better position to decide to select Ubuntu or Debian.
      Stewardship, Licensing, Community and Cost

      Where as Debian is 100% fully committed to free software as defined by the Debian Free Software Guidelines, Ubuntu is created...
      11-17-2024, 08:30 PM
    • Debian Backup and Recovery Solutions: Safeguard Your Data with Confidence
      by Kasimba



      by George Whittaker


      Introduction

      In the digital age, data loss is a critical concern, and effective backup and recovery systems are vital for any Debian system administrator or user. Debian, known for its stability and suitability in enterprise, server, and personal computing environments, offers a multitude of tools for creating robust backup and recovery solutions. This guide will explore these solutions,...
      11-13-2024, 05:30 PM
    • Installing Development Tools on Debian: Setting Up Compilers, Libraries, and IDEs for a Robust Development Environment
      by Kasimba



      by George Whittaker


      Introduction

      Debian is one of the most trusted and stable Linux distributions, making it a top choice among developers and system administrators. Setting up a powerful development environment on Debian involves installing the right tools, compilers, libraries, and Integrated Development Environments (IDEs) that can support various programming languages and workflows. This guide provides...
      11-07-2024, 11:22 PM
    Working...
    X