在 Debian 上重置 GitLab(通常是 GitLab CE)的密码,最常用、最可靠的方法是通过 GitLab Rails 控制台。下面按步骤来(以 Omnibus GitLab 为例,官方最常见安装方式)。
dpkg -l | grep gitlab
或
gitlab-ctl status
如果 gitlab-ctl 存在,说明是 Omnibus 安装,可直接用下面方法。
sudo gitlab-rails console
如果提示时间较长,属于正常现象。
user = User.find_by_username('root')
或按邮箱:
user = User.find_by_email('admin@example.com')
确认用户:
user
user.password = 'NewStrongPassword123'
user.password_confirmation = 'NewStrongPassword123'
user.save!
成功后你会看到:
=> true
exit
现在就可以用新密码登录 GitLab 了。
你也可以用同样的方式重置其他用户:
user = User.find_by_username('username')
docker exec -it gitlab gitlab-rails console
其余步骤一样。
GitLab 通常要求:
如果用户是 LDAP / SSO 登录,则:
user = User.find_by_username('root')
user.locked_at = nil
user.unlock_access!
user.save!
sudo gitlab-ctl status
如果你愿意,可以告诉我:
gitlab-rake gitlab:env:info)我可以给你更精确的方案。