How to unlock a locked user from the command line

After six failed login attempts a user gets in a locked state.

To unlock a locked user:

  1. SSH into your GitLab server.

  2. Start a Ruby on Rails console:

    ## For Omnibus GitLab
    sudo gitlab-rails console production
    
    ## For installations from source
    sudo -u git -H bundle exec rails console RAILS_ENV=production
  3. Find the user to unlock. You can search by email or ID.

    user = User.find_by(email: 'admin@local.host')

    or

    user = User.where(id: 1).first
  4. Unlock the user:

    user.unlock_access!
  5. Exit the console with Ctrl+d

The user should now be able to log in.