Gitlab忘记root密码怎么办
文章发布较早,内容可能过时,阅读注意甄别。
如果忘记了 root 密码,或者接手了一个不知道密码的 Gitlab,可以通过重置密码进行恢复。
登录到 Gitlab 服务器,执行如下命令:
gitlab-rails console production
1
如果此时有报错:
Traceback (most recent call last):
8: from bin/rails:4:in `<main>'
7: from bin/rails:4:in `require'
6: from /opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/railties-6.0.2/lib/rails/commands.rb:18:in `<top (required)>'
5: from /opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/railties-6.0.2/lib/rails/command.rb:46:in `invoke'
4: from /opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/railties-6.0.2/lib/rails/command/base.rb:69:in `perform'
3: from /opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
2: from /opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
1: from /opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
/opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/railties-6.0.2/lib/rails/commands/console/console_command.rb:95:in `perform': wrong number of arguments (given 1, expected 0) (ArgumentError)
9: from bin/rails:4:in `<main>'
8: from bin/rails:4:in `require'
7: from /opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/railties-6.0.2/lib/rails/commands.rb:18:in `<top (required)>'
6: from /opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/railties-6.0.2/lib/rails/command.rb:46:in `invoke'
5: from /opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/railties-6.0.2/lib/rails/command/base.rb:69:in `perform'
4: from /opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
3: from /opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
2: from /opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/command.rb:20:in `run'
1: from /opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/command.rb:34:in `rescue in run'
/opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/base.rb:506:in `handle_argument_error': ERROR: "rails console" was called with arguments ["production"] (Thor::InvocationError)
Usage: "rails console [options]"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
则可能是 Gitlab 版本不一样,然后参数方式不一样,需要用如下方式:
gitlab-rails console -e production
1
接着查询一下用户:
> user = User.where(username:"root").first
=> #<User id:1 @root>
1
2
2
然后修改密码:
> user.password = "test"
=> "11111111"
1
2
2
然后保存:
> user.save!
Enqueued ActionMailer::DeliveryJob (Job ID: 1f015e02-34bc-4b26-8e37-3101937b7ce1) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", #<GlobalID:0x00007fa6b83b1378 @uri=#<URI::GID gid://gitlab/User/1>>
=> true
1
2
3
2
3
保存之后,可以使用如上密码 test 进行登陆,登陆之后,记得更改密码!
上次更新: 2024/07/04, 22:40:37
- 01
- 敬告本站拷贝者,立即停止侵权行为10-29