温馨提示×

linux gitlab如何改密

小樊
45
2026-09-04 14:27:33
栏目: 智能运维

在 Linux 上修改 GitLab 密码 常见有几种场景,下面按最常用的情况给你说明:


一、修改 GitLab Web 登录密码(知道当前密码)

  1. 登录 GitLab
  2. 右上角头像 → Preferences
  3. 左侧 Password
  4. 输入当前密码和新密码
  5. 保存即可

二、忘记密码(管理员或 root 用户重置)

方法 1:通过 GitLab Rails 控制台(最常用)

# 进入 GitLab 安装目录(Omnibus 默认)
sudo gitlab-rails console -e production

进入后执行:

user = User.find_by(username: 'root')   # 或 email
user.password = 'NewPassword123'
user.password_confirmation = 'NewPassword123'
user.save!

退出:

exit

✅ 然后用新密码登录 Web 页面


方法 2:命令行直接重置(不推荐新手)

sudo gitlab-rake "gitlab:password:reset[root]"

按提示输入新密码


三、修改 Linux 系统用户密码(非 GitLab)

如果你是说 Linux 服务器本身的用户密码

passwd
# 或
sudo passwd gitlab

四、修改 Git 远程仓库密码(凭证缓存)

如果你是指 git pull/push 提示密码错误

git config --global credential.helper cache

或修改远程地址:

git remote set-url origin https://用户名:密码@gitlab.com/xxx.git

五、Docker 安装的 GitLab

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

后续操作和上面一样


如果你能说明是:

  • GitLab Web 密码
  • Linux 系统密码
  • Git 客户端密码

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

0