How to change or reset a forgotten password?

How to change or reset a forgotten password?

Hue is the web interface that improves the Apache Hadoop user experience. It’s a Django driven application and manages users accordingly. In this tutorial, we’ll be exploring the different options available for altering passwords in Hue using the default authentication backend (AllowFirstUserBackend).

User Interface

Users can change their passwords via the “<User Name>” -> “Edit Profile” found in the top-right corner of Hue.image

If a user cannot remember their password, the Hue administrator can change it for them via the user manager.image

If the Hue administrator loses their password, then a more technical approach must be taken.

Programmatic

When a Hue administrator loses their password, a more programmatic approach is required to secure the administrator again. Hue comes with a wrapper around the python interpreter called the “shell” command. It loads all the libraries required to work with Hue at a programmatic level. To start the Hue shell, type the following command from the Hue installation root.

If using CM, export this variable in order to point to the correct database:

HUE_CONF_DIR=/var/run/cloudera-scm-agent/process/-hue-HUE_SERVER-id
echo $HUE_CONF_DIR
export HUE_CONF_DIR

Where <id> is the most recent ID in that process directory for hue-HUE_SERVER.

A quick way to get the correct directory is to use this script:

export HUE_CONF_DIR="/var/run/cloudera-scm-agent/process/`ls -alrt /var/run/cloudera-scm-agent/process | grep HUE | tail -1 | awk '{print $9}'`"

Then:

cd /usr/lib/hue (or /opt/cloudera/parcels/CDH-XXXXX/share/hue if using parcels and CM)
build/env/bin/hue shell

The following is a small script, that can be executed within the Hue shell, to change the password for a user named “example”:

from django.contrib.auth.models import User
user = User.objects.get(username='example')
user.set_password('some password')
user.save()

The script can also be invoked in the shell by using input redirection (assuming the script is in a file named script.py):

build/env/bin/hue shell < script.py

How to make a certain user a Hue admin

build/env/bin/hue  shell

Then set these properties to true:

from django.contrib.auth.models import User

a = User.objects.get(username='hdfs')
a.is_staff = True
a.is_superuser = True
a.set_password('my_secret')
a.save()

How to change or reset a forgotten password?

Go on the Hue machine, then in the Hue home directory and either type:

To change the password of the currently logged in Unix user:

build/env/bin/hue  changepassword

If you don’t remember the admin username, create a new Hue admin (you will then also be able to login and could change the password of another user in Hue):

build/env/bin/hue  createsuperuser

 

Summary

We hope this helps you manage your password and assists administrators when they’ve lost their own passwords. In a future blog post, we will detail other ways to authenticate with Hue.

Have any suggestions? Feel free to tell us what you think through hue-user or at @gethue.

13 Comments

  1. Charles 4 years ago

    Great article thanks, Django is awesome!

  2. Prashant 4 years ago

    I am a new administrator for a Hadoop server. Older admin had set up hue and had given some username and password. I am not in contact with old admin. Please suggest how can I find out the username that the old admin set up as hue admin account.

  3. hadoop-admin 3 years ago

    Hi ,

    iam looking to get back the admin username/password for the hue.
    I have followed the above instructions to create new super user and restarted hive.

    But still not able to login into HUE UI with new user credentials .
    ################################
    [[email protected] hue]# build/env/bin/hue createsuperuser
    Username (Leave blank to use ‘root’): hueadmin
    Error: That username is already taken.
    Username (Leave blank to use ‘root’): admin
    E-mail address: [email protected]
    Password:
    Password (again):
    Superuser created successfully.
    [[email protected] hue]# /etc/init.d/hue stop
    Shutting down hue: [ OK ]
    [[email protected] hue]# /etc/init.d/hue start
    Starting hue:
    ################################

    is there any way we can get the existing admin username and password??

    Thanks For the help in advance

    Thanks
    Hadoop-admin

    • Hue Team 3 years ago

      Are you using Cloudera Manager? (normally not according to the commands)
      Is the env variable HUE_CONF_DIR pointing to the good hue config dir?

      You also don’t need to restart Hue.

  4. Y 3 years ago

    I am trying to automate the process and would like to be able to pass in the username and password as arguments for the python script.
    When I try to run the command below I get the following error message

    build/env/bin/hue shell < script.py testuser testpw
    CommandError: Command doesn't accept any arguments

    I think the shell is taking these as arguments instead of the python script. I've tested my python script separately and it works with arguments.
    Is there any way to be able to pass in values to automate this process?

    Thanks

  5. Hermy 3 years ago

    Hello Hue Team,

    I have a question. How do I change the name of an already crated desktop app in hue? I created an app long time ago and we now have to rename it. I hope you can help is.

    Thanks.

    • Hue Team 3 years ago

      It’s probably easier to register a new app with the new name and port the code over.

  6. Tomislav 5 months ago

    Hi,

    when I run:
    from django.contrib.auth.models import User

    a = User.objects.get(username=’hdfs’)
    a.is_staff = True
    a.is_superuser = True
    a.set_password(‘my_secret’)
    a.save()

    I get error:
    File “/usr/share/hue/build/env/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/db/backends/sqlite3/base.py”, line 452, in execute
    return Database.Cursor.execute(self, query, params)
    OperationalError: attempt to write a readonly database

    How can I modify DB to write in it?

    Thanks.

  7. Sivaji GV 4 months ago

    Hi,
    I configured two LDAP servers for user login. It is working fine. I see a drop down list on logon screen to select LDAP server.
    However now I can’t login with hue ‘admin’ userid and password. Reason what I observed is admin user is also trying to get authenticated at LDAP server and failing

    Any way to specify that admin user should authenticate at only Hue DB rather than at LDAP ? In the drop down there is no option to authenticate at local.

Leave a reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.