Resetting password is one of the most common requests virtually in any system. In GitLab, user password can be updated by visiting the
/admin/users page. But if you forgot the password for the root user or the admin user. You need another method to reset it.
The goal is to simplify the process of resetting GitLab user password by using CLI, so next time when encountering the same problem again, it will be quick and easy.
Step by step procedure to reset the root password is already provided by this GitLab documentation. By converting it into a Bash shell script and placing it in user’s home
bin directory as an executable
~/bin/gitlab-password-reset file, we will have created a simple command to be run repeatedly:
We could simply run the long
docker command instead of shell script. But since we’re dealing with password, it’s a good practice to avoid placing sensitive information on command line history log.
No trailing spaces are allowed on the password field, by the way.
Another solution is turning the Ruby evaluation into a script and save into somewhere like
/srv/gitlab/config directory. Then, we can just run:
Because we are using Docker to run GitLab, and the following directories are mapped from the host to the guest:
Therefore, when executing the Ruby script, it’s
/etc/gitlab instead of
/srv/gitlab. However, you will need to figure out how to get the email and password into the script. That’s for you to answer.