GitLab服务器忘记root密码处理方式

GitLab服务器忘记root密码处理方式

1. Gitlab查看用户id号

1. 通过api接口查询

接口查询地址:http://gitlab的url/api/v4/users?username=用户名

  1. 浏览器中访问:http://192.168.31.240:9090/api/v4/users?username=root
[{"id":1,"username":"root","name":"Administrator","state":"active","avatar_url":"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon","web_url":"http://192.168.31.240:9090/root"}]
  1. 可看到root用户的id为1

2. 在Linux终端里直接通过curl命令查询

[root@localhost ~]# curl http://192.168.3.240:9090/api/v4/users?username=root

2. 进入GitLab数据库中查询并修改root密码

# 1 切换到git用户 
[root@localhost ~]$ su - git
# 2.进入控交互控制台,注意:14.x版本必须加上 -e,否则会出现错误
[git@localhost ~]$ gitlab-rails console -e production

# 注意:14.x之前版本可以不加 -e,如:gitlab-rails console production
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux]
 GitLab:       14.6.0 (3bc07a0be9c) FOSS
 GitLab Shell: 13.22.1
 PostgreSQL:   12.7
--------------------------------------------------------------------------------
Loading production environment (Rails 6.1.4.1)
# 1.查询用户
## 1.1根据用户名查询
irb(main):001:0> user = User.where(username: "root").first
## 1.2.根据id查询
irb(main):001:0> user = User.where(id: 1).first
=> #
# 2.设置root用户的新密码
irb(main):002:0> user.password = 'root@123'
=> "root@123"
# 3.确认密码
irb(main):003:0> user.password_confirmation = 'root@123'
=> "root@123"
# 4.保存设置
irb(main):004:0> user.save!
Enqueued ActionMailer::DeliveryJob (Job ID: e562694d-2a1b-4bad-843b-d8567ac51077) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", #>
=> true
# 5.退出
irb(main):005:0> quit

你可能感兴趣的:(gitlab,服务器,运维)