How to reset gitlab admin password

How to reset admin password in Gitlab

Gitlab admin password can be changed easily by using gitlab-rails command. We may have chance of forgetting gitlab admin password, so if we do we actually don’ t need to reinstall gitlab just follow the simple steps to reset your gitlab admin password. This tutorial covers the ground on resetting the admin password on Gitlab.

Resetting procedure

To start the resetting procedure, Login to your gitlab server or gain ssh access for your gitlab and execute the following commands in the terminal to gain access for gitlab-rails console.

[root@git ~]# gitlab-rails console production
Loading production environment (Rails 4.2.8)
irb(main):001:0> 

irb(main):001:0> denotes that the console has changed to gitlab-rails.

Next use the below command to select the user id whom you want to reset password, in this case its root (admin) user. Here root (admin) user is the very first user so the id must me number 1.

irb(main):001:0>  u = User.where(id:1).first
Output:
=>  #< User id: 1, email: " admin@example.com" , created_at: " 2017-03-24 05:22:13" , updated_at: " 2017-03-24 06:49:44" , name: " Administrator" , admin: true, projects_limit: 100000, skype: " " , linkedin: " " , twitter: " " , authentication_token: " RhhsfEeuzhmqujAB_eqr" , bio: nil, username: " root" , can_create_group: true, can_create_team: false, state: " active" , color_scheme_id: 1, password_expires_at: nil, created_by_id: nil, last_credential_check_at: nil, avatar: nil, hide_no_ssh_key: false, website_url: " " , notification_email: " admin@example.com" , hide_no_password: false, password_automatically_set: false, location: nil, encrypted_otp_secret: nil, encrypted_otp_secret_iv: nil, encrypted_otp_secret_salt: nil, otp_required_for_login: false, otp_backup_codes: nil, public_email: " " , dashboard: 0, project_view: 2, consumed_timestep: nil, layout: 0, hide_project_limit: false, otp_grace_period_started_at: nil, ldap_email: false, external: false, incoming_email_token: " dwqslplx0nbkq252flce7376d" , organization: nil, authorized_projects_populated: true, ghost: nil> 

Next enter the new password for the user using below command.

irb(main):002:0>  u.password = ' !@#$%^& *' 
Ouput:
=>  " !@#$%^& *" 

Confirm the password by entering the following command.

irb(main):003:0>  u.password_confirmation = ' !@#$%^& *' 
Output:
=>  " !@#$%^& *" 

Save the password in the console.

irb(main):004:0>  u.save!
Output:
Enqueued ActionMailer::DeliveryJob (Job ID: f80515c9-e754-47d0-9e44-439949238b82) to Sidekiq(mailers) with arguments: " DeviseMailer" , " password_change" , " deliver_now" , gid://gitlab/User/1
=>  true

Now exit from console.

irb(main):005:0>  exit

The password has been reset. Now try to login to your gitalb account using the modified password.

Wasn' t it a simple procedure?. Now resetting an admin password in gitlab is easy with a few steps.

Tag : gitlab
FAQ
Q
How do I get started with Red Hat and Microsoft Azure?
A
The Get Started tab on the Microsoft Azure partner page describes how to enroll in the Red Hat Cloud Access program, migrate your unused subscriptions, and create and provision a Red Hat Enterprise Linux VM in Microsoft Azure.
Q
how to exit the gitlab login console in terminal?
A
you can exit the gitlab login console by following command
> exit
Q
which command to save the gitlab password?
A
use the following command to save the gitlab password
> u.save!
Q
which command to access the gitlab-rails in terminal?
A
execute the following commands in the terminal to gain access for gitlab-rails console.
# gitlab-rails console production
Q
why we need to reset the gitlab admin password?
A
Gitlab admin password can be changed easily by using gitlab-rails command. We may have chance of forgetting gitlab admin password, so if we do we actually don&rsquo t need to reinstall gitlab just follow the simple steps to reset your gitlab admin password.