强制重置Gitlab的root密码

首先进入Gitlab的docker容器的命令行

sudo docker exec -it gitlab-gitlab-ce-1 /bin/bash

切换到git用户

root@gitlab-gitlab-ce-1:/etc# su - git

查看当前文件

$ pwd
/var/opt/gitlab
$ ls
alertmanager  bootstrapped  gitaly     gitlab-exporter	gitlab-rails  gitlab-workhorse	nginx		   postgresql  public_attributes.json  trusted-certs-directory-hash
backups       git-data	    gitlab-ci  gitlab-kas	gitlab-shell  logrotate		postgres-exporter  prometheus  redis

打开Gitlab的console控制台

$ gitlab-rails console
--------------------------------------------------------------------------------
 Ruby:         ruby 3.0.6p216 (2023-03-30 revision 23a532679b) [x86_64-linux]
 GitLab:       16.4.1 (e6801ed8d44) FOSS
 GitLab Shell: 14.28.0
 PostgreSQL:   13.11
------------------------------------------------------------[ booted in 71.02s ]
Loading production environment (Rails 7.0.6)

修改密码

irb(main):001:0> user = User.where(id:1).first
=> #<User id:1 @root>
irb(main):002:0> user.password='aebf5932-6263-4be6-804e-7502aabab813'
=> "aebf5932-6263-4be6-804e-7502aabab813"
irb(main):003:0> user.save!
=> true

参考文献

https://blog.51cto.com/heyong/5149400

Share

You may also like...

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注