温馨提示×

如何重置ubuntu gitlab密码

小樊
58
2026-10-13 17:10:06
栏目: 智能运维

在 Ubuntu 上重置 GitLab 密码,通常有以下几种常见场景和方法:


一、重置 GitLab 用户(Web 登录)密码(最常用)

方法 1:通过 GitLab Rails 控制台重置(推荐)

  1. 进入 GitLab Rails 控制台
sudo gitlab-rails console -e production

(如果是源码安装,可能是 bundle exec rails console production)

  1. 查找用户并重置密码
user = User.where(username: 'root').first
# 或者按邮箱
# user = User.find_by(email: 'admin@example.com')

user.password = 'newpassword123'
user.password_confirmation = 'newpassword123'
user.save!
  1. 退出控制台
exit

✅ 现在可以用新密码登录 GitLab Web 页面。


二、忘记 root 密码且无法登录

上述方法同样适用,不需要原密码。

如果你是 Omnibus 安装(最常见):

sudo gitlab-ctl reconfigure
sudo gitlab-rails console -e production

三、重置 GitLab 系统用户(Linux 系统账户,非 Web)

如果你指的是 Ubuntu 系统里的 git 用户密码:

sudo passwd git

四、Docker 安装的 GitLab

如果是 Docker 容器:

docker exec -it gitlab bash
gitlab-rails console -e production

然后执行上面的 Ruby 命令。


五、验证是否生效

  • Web 登录:https://your-gitlab-domain
  • 或使用 API:
curl -X POST "https://gitlab.example.com/api/v4/session" \
--data "login=root&password=newpassword123"

如果你能说明:

  • GitLab 安装方式(Omnibus / Docker / 源码)
  • 是哪个密码(Web 用户 / Linux 用户 / CI Token)

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

0 踩