Introduction #
Forgetting the admin password for your Odoo instance can usually be resolved using Odoo’s built-in “Reset Password” feature available on the login page.
However, if you forgot the username or have not configured an SMTP server to send the password reset email, you can directly change the admin password in your PostgreSQL database using an SSH terminal.
Requirements #
- SSH Access to your Odoo server (how to: generate an SSH key and install it on your server)
- The name of your database (you will find it under your Odoo instance details in your Cloudpepper dashboard)
Step 1: Connect to your server with an SSH terminal #
We like using Termius but you can use any terminal to connect with your server. Follow this guide to connect to your server using Termius.
Step 2: Hash your new password #
For security reasons passwords are never stored as plain values in your Odoo database. We need to first create the hashed value of your new password so that your Odoo instance can read it.
Odoo uses the “pbkdf2_sha512” hashing scheme for storing passwords. While there are several online hash generators you can use, you can easily – and more securely – generate the hashed password from your SSH terminal. We will use Python on your server to create a hashed value of your password.
Open the Python interface with python3 and enter the following two lines which will output your hashed password. Change “YourNewPassword” in the second line to your desired password.
python3
>>> from passlib.context import CryptContext
>>> print(CryptContext(schemes=['pbkdf2_sha512']).hash('YourNewPassword'))
Save the hashed password for step 6 and exit the Python interface by entering ‘exit()’.
Step 3: Open your PostgreSQL interface #
Enter the following command to open the PostgreSQL interface as the postgres user.
sudo -u postgres psql
Once entered, you will see the following start prompt of the PostgreSQL interface, ready to execute SQL queries to retrieve and change information in your Odoo database.
postgres=#
Step 4: Connect with your Odoo database #
Enter the following query to connect with the database of your Odoo instance.
postgres=# \connect YOUR_DB_NAME
Replace ‘YOUR_DB_NAME‘ with the name of the database of your Odoo instance.
On the Instances page in your Cloudpepper dashboard, open the Details of the Odoo instance for which you lost your admin password. You will find the database name written under Odoo Specifics.
Step 5: Find the admin user #
If you already know the username of your admin user, you can skip this step.
If you don’t remember the admin user you can execute the following command to see the full user list in your Odoo database.
YOUR_DB_NAME=# SELECT id, login FROM res_users;
Take note of the username and enter \q to return to the interface.
Step 6: Set your new password #
Now that you are connected to your database, execute the following query to set the new password of your admin user in the user table.
Ensure to change the values “YOUR_HASHED_PASSWORD” with your hashed password starting with $pbkdf2-sha512$… and “YOUR_USERNAME” with your username.
YOUR_DB_NAME=# UPDATE res_users SET password='YOUR_HASHED_PASSWORD' WHERE login = 'YOUR_USERNAME';
For example, if your admin user is ‘admin’ and your password is ‘YourNewPassword’, you can update the password using the following SQL query:
YOUR_DB_NAME=# UPDATE res_users SET password='$pbkdf2-sha512$25000$mXMuRWgtpdT6H0Po/Z9Tag$nX/9lFjYJdo46XWw.zF20C9DOt8KCqhOnqpHTKBtqtnocw/RLJqimi9kHldLfRx7lI0XZBnOhlfip7Dcz0zqGQ' WHERE login = 'admin';
Your new password has now been set. You can now proceed to log in to your Odoo instance with your new password.