Gitlab忘记root用户密码解决办法
今天使用gitlab的时候发现管理员密码忘记,现将找回密码的过程记录。
(1)、查询gitlab用户的id号
可以进入gitlab数据库查询
# gitlab-rails dbconsole
psql (9.6.3)
Type "help" for help.
# 连接数据库
\c gitlabhq_production
You are now connected to database "gitlabhq_production" as user "gitlab".
# 查看用户root的id
select id,name,username from users where username = 'root';
id | name | username
----+---------------+----------
1 | Administrator | root
(1 row)
退出
\q
could not save history to file "/var/opt/gitlab/.psql_history": Permission denied
psql (9.6.3)
Type "help" for help.
# 连接数据库
\c gitlabhq_production
You are now connected to database "gitlabhq_production" as user "gitlab".
# 查看用户root的id
select id,name,username from users where username = 'root';
id | name | username
----+---------------+----------
1 | Administrator | root
(1 row)
退出
\q
could not save history to file "/var/opt/gitlab/.psql_history": Permission denied
也可以通过api接口查询用户的id号
比如查看gitlab的root用户id
在浏览器页面里直接访问"http://173.16.200.83:29091/api/v4/users?username=root"
(2)、忘记Gitlab的root用户密码的重置方法
重置用户密码之前,需要知道用户的id号, 可以通过上面的方法查询到用户的id号信息
# gitlab-rails console production
user = User.where(id: 1).first
user.password = 'gitlab200.83oms'
user.password_confirmation = 'gitlab200.83oms'
user.save!
quit
user = User.where(id: 1).first
user.password = 'gitlab200.83oms'
user.password_confirmation = 'gitlab200.83oms'
user.save!
quit