1.进入到gitlab 的ssh命令行

root@03cbecccf5c8:/# 

2.登录到Gitlab服务器

root@03cbecccf5c8:/# gitlab-rails console production

如果执行上面的指令提示

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]"

则可能是Gitlab版本不一样,然后参数方式不一样,需要用如下方式:

root@03cbecccf5c8:/# gitlab-rails console -e production

3.查询用户

> user = User.where(username:"root").first
=> #<User id:1 @root>

4.修改密码

> user.password = "qwer1234"
=> "qwer1234"

5.保存

> 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

6.登录

账号:root
密码:qwer1234

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐