zoukankan      html  css  js  c++  java
  • Gitlab忘记root用户密码解决办法

    一、Gitlab忘记root用户密码,重置用户密码和查看用户ID号方法 

    1、Gitlab查看用户id号的方法
    1)方法1:通过api接口查询
    接口查询地址:http://gitlab的url/api/v4/users?username=用户名

    比如查看gitlab的root用户id
    在浏览器页面里直接访问"http://172.16.60.237/api/v4/users?username=root"
    或者
    在linux终端命令行里直接通过curl命令进行访问

    [root@localhost ~]# curl http://172.16.60.237/api/v4/users?username=root
    [{"id":1,"name":"Administrator","username":"root","state":"active","avatar_url":"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80u0026d=identicon","web_url":"http://gitlab.example.com/root"}]
    

    2)方法2:进入gitlab数据库查询  

    [root@localhost ~]# gitlab-rails dbconsole
    psql (10.9)
    Type "help" for help.
     
    gitlabhq_production=> l
                                                 List of databases
            Name         |    Owner    | Encoding |   Collate   |    Ctype    |        Access privileges
    ---------------------+-------------+----------+-------------+-------------+---------------------------------
     gitlabhq_production | gitlab      | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
     postgres            | gitlab-psql | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
     template0           | gitlab-psql | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/"gitlab-psql"               +
                         |             |          |             |             | "gitlab-psql"=CTc/"gitlab-psql"
     template1           | gitlab-psql | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/"gitlab-psql"               +
                         |             |          |             |             | "gitlab-psql"=CTc/"gitlab-psql"
    (4 rows)
     
    ## 连接数据库
    gitlabhq_production=> c gitlabhq_production
    You are now connected to database "gitlabhq_production" as user "gitlab".
    gitlabhq_production=> select id,name,username from users;
     id |     name      | username
    ----+---------------+----------
      1 | Administrator | root
    (1 row)
    ## 查找账户id
    gitlabhq_production=> select id from users where username = 'root';
     id
    ----
      1
    (1 row)
     
    ==============================================================================================
    

    2、忘记Gitlab的root用户密码的重置方法

    如果忘记了Gitlab的root用户密码,则可以在服务器上面直接修改数据:

    [root@localhost ~]# gitlab-rails console production      #然后以此执行下面命令(需要提前查询用户的id号)
    ...> user = User.where(id: 1).first
    ...> user.password = 'secret_pass'
    ...> user.password_confirmation = 'secret_pass'
    ...> user.save!
    

    例如重置root用户密码为root@123,root用户id为1  

    [root@localhost ~]# gitlab-rails console production
    DEPRECATION WARNING: Passing the environment's name as a regular argument is deprecated and will be removed in the next Rails version. Please, use the -eoption instead. (called from require at bin/rails:4)
    --------------------------------------------------------------------------------
     GitLab:       12.2.0 (1c1d47c5974)
     GitLab Shell: 9.3.0
     PostgreSQL:   10.9
    --------------------------------------------------------------------------------
    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 = 'root@123'
    => "root@123"
    irb(main):003:0> user.password_confirmation = 'root@123'
    => "root@123"
    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", #<GlobalID:0x00007fae7e55bcc8 @uri=#<URI::GID gid://gitlab/User/1>>
    => true
    irb(main):005:0> quit
    

    -----------------------------------------------------------书山有路勤为径,学海无涯苦作舟------------------------------------------------------------- 

  • 相关阅读:
    easyui学习笔记3—在展开行内的增删改操作
    easyui学习笔记2—在行内进行表格的增删改操作
    4星|《贫穷的本质》:小额贷款对穷人帮助有限,助推政策也许是更好的
    科技类好书12本
    咨询公司等专业服务公司的权力结构:3星|《哈佛商业评论》第4期
    投资、投机、经济周期相关20本书,其中好书8本半
    3星|《进化:中国互联网生存法则》:点评十年来互联网公开大事
    黑洞有毛 or 黑洞无毛:4星|《环球科学》2019年03月号
    3星|《给产品经理讲技术》:APP开发技术介绍,没有技术背景的话恐怕只能看懂书中的比喻和结论
    2星|《为什么我们总是在逃避》:尝试用精神分析理论解释常见负面情绪
  • 原文地址:https://www.cnblogs.com/easonscx/p/12608486.html
Copyright © 2011-2022 走看看