debian-mirror-gitlab/doc/security/reset_user_password.md
2021-02-22 17:27:13 +05:30

2.5 KiB

stage group info type
Manage Access To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments howto

How to reset user password

To reset the password of a user, first log into your server with root privileges.

Start a Ruby on Rails console with this command:

gitlab-rails console -e production

Wait until the console has loaded.

Find the user

There are multiple ways to find your user. You can search by email or user ID number.

user = User.where(id: 7).first

or

user = User.find_by(email: 'user@example.com')

Reset the password

Now you can change your password:

user.password = 'secret_pass'
user.password_confirmation = 'secret_pass'

It's important that you change both password and password_confirmation to make it work.

When using this method instead of the Users API, GitLab sends an email to the user stating that the user changed their password.

If the password was changed by an administrator, execute the following command to notify the user by email:

user.send_only_admin_changed_your_password_notification!

Don't forget to save the changes.

user.save!

Exit the console, and then try to sign in with your new password.

NOTE: You can also reset passwords by using the Users API.

Reset your root password

The previously described steps can also be used to reset the root password. First, identify the root user, with an id of 1. To do so, run the following command:

user = User.where(id: 1).first

After finding the user, follow the steps mentioned in the Reset the password section to reset the password of the root user.