2021-01-24

用root账号执行
gitlab-rails console -e production

   
   
  • 1

2021-01-24

  • 找到root用户

    user = User.where(id: 1).first
    
        
        
    • 1

    或者

    user = User.find_by(email: 'admin@example.com')
    
        
        
    • 1
  • 修改密码

    user.password = 'secret_pass'
    user.password_confirmation = 'secret_pass'
    
        
        
    • 1
    • 2
  • 保存

    user.save!
    
        
        
    • 1
  • 操作样例

    [root@localhost ~]# gitlab-rails console -e production
    --------------------------------------------------------------------------------
    GitLab:       12.4.2 (393a5bdafa2)
    GitLab Shell: 10.2.0
    PostgreSQL:   10.9
    --------------------------------------------------------------------------------
    user = User.where(id: 1).first
    Loading production environment (Rails 5.2.3)
    irb(main):001:0> user = User.where(id: 1).first
    => #<User id:1 @root>
    irb(main):002:0> user.password='12345678'
    => "12345678"
    irb(main):003:0> user.password_confirmation='12345678'
    => "12345678"
    irb(main):004:0> user.save!
    Enqueued ActionMailer::DeliveryJob (Job ID: b4e0a054-5fea-487d-9b84-cef6c02d9f8f) to Sidekiq(mailers) with arguments: 	"DeviseMailer", "password_change", "deliver_now", #<GlobalID:0x00007f6ec7477a60 @uri=#<URI::GID gid://gitlab/User/1>>
    => true
    irb(main):005:0> 
    irb(main):005:0> exit
    [root@localhost ~]# 
    
        
        
    上一篇:计算机入门笔记


    下一篇:爬虫学习打卡第四天——requests实战