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=80\u0026d=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

 

-----------------------------------------------------------書山有路勤為徑,學海無涯苦作舟------------------------------------------------------------- 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM