I have forgot GitLab root password for my team GitLab Instance, but i can access server, Here is a my recap step
Prerequisites:
- You must access to GitLab Instance, For my case- I can access s via Portainer
- You must know the associated username, user ID, or email address.
Step:
- Access to GitLab Instance - Connect to Git Lab
# Linux sudo gitlab-rails console # docker docker exec -it <container-id> gitlab-rails console # Portainer Stack > GitLab Container > Console
- Find the user
# By Username user = User.find_by_username 'exampleroot' # By User Id user = User.find(123) # By Email user = User.find_by(email: '[email protected]')
- Reset the password by setting a value for
user.passwordanduser.password_confirmation.
new_password = 'mynewpassword' user.password = new_password user.password_confirmation = new_password user.password_automatically_set = false
If you want to set random password change line
new_password = 'P@3sw0rd'withnew_password = ::User.random_password
- Optional. Notify the user that an administrator changed their password
user.send_only_admin_changed_your_password_notification!
- Save changes
user.save!
- Check Error - If you found
Validation failed: Password must not contain commonly used combinations of words and letters (ActiveRecord::RecordInvalid)- update a password that match policy.
--------------------------------------------------------------------------------
Ruby: ruby 3.3.11 (2026-03-26 revision 1f2d15125a) [x86_64-linux]
GitLab: 19.0.1 (35d349e97ce) FOSS
GitLab Shell: 14.51.0
PostgreSQL: 17.8
------------------------------------------------------------[ booted in 34.71s ]
Loading production environment (Rails 7.2.3)
gitlab(prod)>
gitlab(prod)> user = User.find_by_username 'root'
=> #<User id:1 @root>
gitlab(prod)> new_password = 'mynewpassword'
=> "examplepassword"
gitlab(prod)> user.password = new_password
gitlab(prod)> user.password_confirmation = new_password
gitlab(prod)> user.password_automatically_set = false
gitlab(prod)> user.send_only_admin_changed_your_password_notification!
gitlab(prod)> user.save!
gitlab(prod)> exit
activerecord (7.2.3) lib/active_record/validations.rb:87:in `raise_validation_error': Validation failed: Password must not contain commonly used combinations of words and letters (ActiveRecord::RecordInvalid)
from activerecord (7.2.3) lib/active_record/validations.rb:54:in `save!'
from activerecord (7.2.3) lib/active_record/transactions.rb:366:in `block in save!'
from activerecord (7.2.3) lib/active_record/transactions.rb:418:in `block (2 levels) in with_transaction_returning_status'
from activerecord (7.2.3) lib/active_record/connection_adapters/abstract/transaction.rb:616:in `block in within_new_transaction'
from activesupport (7.2.3) lib/active_support/concurrency/null_lock.rb:9:in `synchronize'
from activerecord (7.2.3) lib/active_record/connection_adapters/abstract/transaction.rb:613:in `within_new_transaction'
from activerecord (7.2.3) lib/active_record/connection_adapters/abstract/database_statements.rb:361:in `transaction'
from lib/gitlab/database/load_balancing/connection_proxy.rb:127:in `public_send'
from lib/gitlab/database/load_balancing/connection_proxy.rb:127:in `block in write_using_load_balancer'
from lib/gitlab/database/load_balancing/load_balancer.rb:141:in `block in read_write'
from lib/gitlab/database/load_balancing/load_balancer.rb:257:in `retry_with_backoff'
from lib/gitlab/database/load_balancing/load_balancer.rb:131:in `read_write'
from lib/gitlab/database/load_balancing/connection_proxy.rb:126:in `write_using_load_balancer'
from lib/gitlab/database/load_balancing/connection_proxy.rb:78:in `transaction'
from activerecord (7.2.3) lib/active_record/transactions.rb:414:in `block in with_transaction_returning_status'
from lib/gitlab/database/load_balancing/setup.rb:73:in `block in setup_connection_proxy'
... 34 levels...
gitlab(prod)>
gitlab(prod)> user = User.find_by_username 'root' => #<User id:1 @root> gitlab(prod)> new_password = 'P@3sw0rd' => "P@3sw0rd" gitlab(prod)> user.password = new_password => "P@3sw0rd" gitlab(prod)> user.password_confirmation = new_password gitlab(prod)> => "P@3sw0rd" gitlab(prod)> user.password_automatically_set = false gitlab(prod)> => false gitlab(prod)> user.send_only_admin_changed_your_password_notification! gitlab(prod)> => true gitlab(prod)> user.save! gitlab(prod)> => true gitlab(prod)>
- Test Login



