Skip to content

Instantly share code, notes, and snippets.

@beechnut
Created August 23, 2022 14:58
Show Gist options
  • Save beechnut/3806c6b1ebeeed73495e64b179f17c5f to your computer and use it in GitHub Desktop.
Save beechnut/3806c6b1ebeeed73495e64b179f17c5f to your computer and use it in GitHub Desktop.
I forgot the password to my local SonarQube instance and now I'm locked out

Reset SonarQube admin password

Did you forget the admin password for your local Dockerized instance of SonarQube? Do you have a lot of scans done that you need for a vendor evaluation?

We've all been there. (Well, all of us who found this Gist maybe.)

If you're using Docker, go to your Docker dashboard and run an interactive terminal session. This will open a terminal window with a command like this:

docker exec -it {Container ID} /bin/sh

If you're not using Docker, I'm not sure how to start a terminal session. Maybe it's just your system terminal? I don't know.

Now that we're in the terminal session, next we need open an interactive shell for the H2 database, which is the development-quality database bundled with SonarQube.

java -cp lib/jdbc/h2/h2*.jar org.h2.tools.Shell

I believe the -cp option defines the classpath, which is basically telling Java to include the H2 database library. The * lets us match against anything in the directory we've specified. If the Docker image changes in the future, you may need to point to a different place for that H2 JAR file.

Next, the H2 shell gives us a few prompts and expects us to answer. The first prompt is the database URL. Enter this value:

jdbc:h2:tcp://127.0.0.1:9092/sonar

For the rest of the prompts (driver, username, and password), don't type anything and just press enter: it'll use the default values.

Next, let's make sure we're getting good database results. Let's look at the users table.

select * from users limit 1;

We should see a result like: TK.

Now that we're sure we're in the database successfully, it's time to reset the password! Run the following SQL command. This sets the admin password to "admin", and requires the admin user to reset their password during their next login. I would guess you could set reset_password=FALSE in the SQL query and you could keep the password as "admin".

update users set crypted_password='100000$t2h8AtNs1AlCHuLobDjHQTn9XppwTIx88UjqUm4s8RsfTuXQHSd/fpFexAnewwPsO6jGFQUv/24DnO55hY6Xew==', salt='k9x9eN127/3e/hf38iNiKwVfaVk=', hash_method='PBKDF2', reset_password=TRUE, user_local=TRUE where login='admin';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment