温馨提示×

centos gitlab怎么找回密码

小樊
35
2026-09-06 00:29:26
栏目: 智能运维

CentOS 上运行的 GitLab 如果忘记了登录密码,可以通过以下几种方式找回或重置(前提是你能登录服务器)。


一、通过 GitLab 命令行重置(最常用 ✅)

1. 进入服务器并切换到 GitLab 环境

sudo gitlab-rails console -e production

如果是老版本可能是:

sudo gitlab-rake rails console

等待出现 irb(main):001:0> 提示符。


2. 查找用户

user = User.where(username: 'root').first
# 或按邮箱
user = User.find_by(email: 'admin@example.com')

3. 修改密码

user.password = 'NewPassword123'
user.password_confirmation = 'NewPassword123'
user.save!

✅ 看到 => true 表示成功。


4. 退出

exit

然后尝试用新密码登录 GitLab。


二、通过邮箱找回(前提:邮件服务正常)

如果你 配置过 SMTP

  1. 打开 GitLab 登录页
  2. 点击 “Forgot your password?”
  3. 输入注册邮箱
  4. 查收重置邮件

三、重置 root 密码(root 用户专用)

如果是 root 密码忘记,方法同上,但用户名是:

User.where(username: 'root').first

四、常见问题

1. 登录后提示密码错误?

  • 确认没有开启 LDAP / OAuth
  • 确认不是 SSO 登录

2. GitLab 启动失败?

sudo gitlab-ctl status
sudo gitlab-ctl restart

3. 忘记了 root 邮箱?

User.where(username: 'root').first.email

五、安全建议

  • 修改密码后退出多余 session
  • 配置 SMTP,避免以后无法找回
  • 使用强密码 + 定期备份 /var/opt/gitlab

如果你能告诉我:

  • GitLab 版本
  • 是否是 CE / EE
  • 是否是 Docker 部署

我可以给你更精确的操作步骤。

0