1. Gitlab查看用户id号

1)方法1:通过api接口查询

接口查询地址:http://gitlab的url/api/v4/users?username=用户名

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

# 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数据库查询

## 进入gitlab数据库
# gitlab-rails dbconsole

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


## 查找账户id,用户名,名字
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用户密码,则可以在服务器上面直接修改数据:

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

例如,重置root用户密码为root123*,root用户id为1。

# gitlab-rails console -e production

irb(main):001:0> user = User.where(id: 1).first
=> #<User id:1 @root>
irb(main):002:0> user.password = 'root123*'
=> "root123*"
irb(main):003:0> user.password_confirmation = 'root123*'
=> "root123*"
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
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐