# Unable to login to Jupyterhub Server

**URL:** <https://discourse.jupyter.org/t/unable-to-login-to-jupyterhub-server/30461>\
**Category:** JupyterHub\
**Created:** [November 27, 2024, 10:20am UTC](https://discourse.jupyter.org/t/unable-to-login-to-jupyterhub-server/30461 "2024-11-27T10:20:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mrunal\_Chipre](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/mrunal_chipre/32/16102_2.png) [@Mrunal\_Chipre](https://discourse.jupyter.org/u/Mrunal_Chipre)\
**Post date:** [November 27, 2024, 10:20am UTC](https://discourse.jupyter.org/t/unable-to-login-to-jupyterhub-server/30461/1 "2024-11-27T10:20:49Z")

</div>

I have setup Jupyterhub in my AWS server, I am able to access server and visit login page. But after adding allowed users and admin\_user to config file when i try to login it says Incorrect Username or password.

Is there any solution to fix this?

Note: Server is setup without Docker / kubernetes.

---

<div class="post-metadata">

**Author:** ![tharun](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/tharun/32/16009_2.png) [@tharun](https://discourse.jupyter.org/u/tharun)\
**Post date:** [November 27, 2024, 7:35pm UTC](https://discourse.jupyter.org/t/unable-to-login-to-jupyterhub-server/30461/2 "2024-11-27T19:35:02Z")

</div>

Did you restart the service after config is updated?

---

<div class="post-metadata">

**Author:** ![Mrunal\_Chipre](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/mrunal_chipre/32/16102_2.png) [@Mrunal\_Chipre](https://discourse.jupyter.org/u/Mrunal_Chipre)\
**Post date:** [November 28, 2024, 11:52am UTC](https://discourse.jupyter.org/t/unable-to-login-to-jupyterhub-server/30461/4 "2024-11-28T11:52:37Z")

</div>

I was able to login but after login i get 500 server error, the server is not starting automatically.

please refer below spawner class  
Note: this is public accessible not restricted for system users

class CustomSpawner(LocalProcessSpawner):  
def get\_env(self):  
# Get the environment from the parent class  
env = super().get\_env()

```
    # Define base notebook directory and user notebook directory
    base_notebook_dir = #my notebook directory path 
    username = self.user.name
    user_notebook_dir = os.path.join(base_notebook_dir, username)

    # Ensure user's directory exists or create it
    if not os.path.exists(user_notebook_dir):
        os.makedirs(user_notebook_dir)

        # Copy files from the admin's directory to the user's directory
        admin_notebook_dir = os.path.join(base_notebook_dir, 'testuser') # Update with admin user name
        if os.path.exists(admin_notebook_dir):
            for item in os.listdir(admin_notebook_dir):
                s = os.path.join(admin_notebook_dir, item)
                d = os.path.join(user_notebook_dir, item)
                if os.path.isfile(s):
                    shutil.copy2(s, d)
                elif os.path.isdir(s):
                    shutil.copytree(s, d)

    # Set environment variables for each user manually (without relying on system users)
    env['HOME'] = user_notebook_dir
    env['USER'] = username
    env['LOGNAME'] = username
    env['PWD'] = user_notebook_dir

    return env

def start(self):
    # Ensure that the user's directory is set up correctly before starting
    self.notebook_dir = os.path.join('/Notebooks', self.user.name)
    if not os.path.exists(self.notebook_dir):
        os.makedirs(self.notebook_dir)

    # Automatically start the server without waiting for explicit action
    self.ready = True # Mark the server as ready immediately
    self._spawned = True # Indicate that the server is spawned

    # Call the parent class start method
    return super().start()

```

# Spawner configuration

c.JupyterHub.spawner\_class = CustomSpawner  
c.Spawner.notebook\_dir = ‘/Notebooks’ # Path for user notebooks  
c.Spawner.default\_url = ‘/lab’ # Launch JupyterLab interface by default

---

<div class="post-metadata">

**Author:** ![Mrunal\_Chipre](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/mrunal_chipre/32/16102_2.png) [@Mrunal\_Chipre](https://discourse.jupyter.org/u/Mrunal_Chipre)\
**Post date:** [November 28, 2024, 11:56am UTC](https://discourse.jupyter.org/t/unable-to-login-to-jupyterhub-server/30461/5 "2024-11-28T11:56:20Z")

</div>

I was able to login but after login i get 500 server error, the server is not starting automatically.

please refer below spawner class  
Note: this is public accessible not restricted for system users

class CustomSpawner(LocalProcessSpawner):  
def get\_env(self):  
# Get the environment from the parent class  
env = super().get\_env()

```
    # Define base notebook directory and user notebook directory
    base_notebook_dir = #my notebook directory path 
    username = self.user.name
    user_notebook_dir = os.path.join(base_notebook_dir, username)

    # Ensure user's directory exists or create it
    if not os.path.exists(user_notebook_dir):
        os.makedirs(user_notebook_dir)

        # Copy files from the admin's directory to the user's directory
        admin_notebook_dir = os.path.join(base_notebook_dir, 'testuser') # Update with admin user name
        if os.path.exists(admin_notebook_dir):
            for item in os.listdir(admin_notebook_dir):
                s = os.path.join(admin_notebook_dir, item)
                d = os.path.join(user_notebook_dir, item)
                if os.path.isfile(s):
                    shutil.copy2(s, d)
                elif os.path.isdir(s):
                    shutil.copytree(s, d)

    # Set environment variables for each user manually (without relying on system users)
    env['HOME'] = user_notebook_dir
    env['USER'] = username
    env['LOGNAME'] = username
    env['PWD'] = user_notebook_dir

    return env

def start(self):
    # Ensure that the user's directory is set up correctly before starting
    self.notebook_dir = os.path.join('/Notebooks', self.user.name)
    if not os.path.exists(self.notebook_dir):
        os.makedirs(self.notebook_dir)

    # Automatically start the server without waiting for explicit action
    self.ready = True # Mark the server as ready immediately
    self._spawned = True # Indicate that the server is spawned

    # Call the parent class start method
    return super().start()

```

# Spawner configuration

c.JupyterHub.spawner\_class = CustomSpawner  
c.Spawner.notebook\_dir = ‘/Notebooks’ # Path for user notebooks  
c.Spawner.default\_url = ‘/lab’ # Launch JupyterLab interface by default

Login was successful with some minor change
