If you have installed self-managed GitLab CE instance in your server and you forgot the root password, you can reset it via command line.
This tutorial explains how to reset GitLab CE root password in Linux. Commands have been tested on Ubuntu 20.04 LTS.
Reset root password
gitlab-rake command which allows to perform various tasks such as backup and restore GitLab instance, clean up unneeded items, check data integrity, and other. This command also can be used to reset user password by using username.
By default, username of administrator account is
root. You can run the following command to reset the root password:
sudo gitlab-rake 'gitlab:password:reset[root]'
Command will ask to enter a password and a password confirmation. If everything is good, command will print message that password successfully updated for user with username root.
Reset password when username was changed
For security reasons, the username of administrator account can be changed. If the username was changed from
root to something else and you forgot it, you can use Rails console to find it.
Run the following command to start a Rails console:
sudo gitlab-rails console
In most cases, the first user is the default administrator account and user ID is
1. In the Rails console run the following statement to find username by user ID:
user = User.find(1)
In our case, the following line was printed:
=> #<User id:1 @master>
As we can see, a username is
quit to exit Rails console:
Now run the following command to reset the password of administrator account:
sudo gitlab-rake 'gitlab:password:reset[master]'