GitLab在重置用户密码 – 找回root密码

  • A+
所属分类:Linux  随手小记
摘要

忘记密码对于这个不喜欢记密码又强迫症不喜欢用一个密码走天下的人来说和吃饭一样平凡的发生着

首先切换到git用户

su git - 

注意下面的高亮行

git@57aab1253afd:~/gitlab$ bundle exec rails console production
Loading production environment (Rails 4.2.6)
irb(main):001:0> user = User.find_by(email: 'admin@dwhd.org')
=> #<User id: 1, email: "admin@dwhd.org", encrypted_password: "$2a$10$p2Nw/sU6SQqPT8CL69.4LumT8Cw7cEIZoyG4m2SbdLt...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2016-07-09 08:22:03", last_sign_in_at: "2016-07-09 08:22:03", current_sign_in_ip: "192.168.16.1", last_sign_in_ip: "192.168.16.1", created_at: "2016-07-09 08:14:01", updated_at: "2016-07-09 08:22:03", name: "Administrator", admin: true, projects_limit: 100, skype: "", linkedin: "", twitter: "", authentication_token: "qtJhBiNuMUHaA_2UFYyZ", theme_id: 2, bio: nil, failed_attempts: 0, locked_at: nil, username: "root", can_create_group: true, can_create_team: false, state: "active", color_scheme_id: 1, notification_level: 1, password_expires_at: nil, created_by_id: nil, last_credential_check_at: nil, avatar: nil, confirmation_token: nil, confirmed_at: "2016-07-09 08:14:01", confirmation_sent_at: nil, unconfirmed_email: nil, hide_no_ssh_key: false, website_url: "", notification_email: "admin@dwhd.org", hide_no_password: false, password_automatically_set: false, location: nil, encrypted_otp_secret: nil, encrypted_otp_secret_iv: nil, encrypted_otp_secret_salt: nil, otp_required_for_login: false, otp_backup_codes: nil, public_email: "", dashboard:0, project_view: 0, consumed_timestep: nil, layout: 0, hide_project_limit: false, unlock_token: nil, otp_grace_period_started_at: nil, ldap_email: false, external: false>
irb(main):002:0> user.password = 'LookBack'
=> "LookBack"
irb(main):003:0> user.password_confirmation = 'LookBack'
=> "LookBack"
irb(main):004:0> user.save
=> true
irb(main):005:0>

GitLab在重置用户密码 - 找回root密码

下面是重置docker环境下的gitlab的用户密码

[root@DS-VM-Node58 ~]# sed -n '/- DB_/p' /data/docker-compose.yml 
    - DB_ADAPTER=mysql2
    - DB_HOST=127.0.0.1
    - DB_PORT=****
    - DB_USER=******
    - DB_PASS=************
    - DB_NAME=******
[root@DS-VM-Node58 ~]# docker exec -it gitlab_server bash         
root@DS-VM-Node58:/home/git/gitlab# mysql -u****** -p************ ****** -h127.0.0.1 -e "select id,email,encrypted_password,username from users where username ='root';"
+----+-------------------+--------------------------------------------------------------+----------+
| id | email             | encrypted_password                                           | username |
+----+-------------------+--------------------------------------------------------------+----------+
|  1 | admin@example.com | $2a$10$UPq7XEJVAxuX19q40H8CdeDAVriMVoKSlodqxhO6Vo4Wa7TH6oyKW | root     |
+----+-------------------+--------------------------------------------------------------+----------+
root@DS-VM-Node58:/home/git/gitlab# bundle exec rails console production
Loading production environment (Rails 4.2.6)
irb(main):001:0> user = User.find_by(id: '1')
=> #<User id: 1, email: "admin@example.com", encrypted_password: "$2a$10$UPq7XEJVAxuX19q40H8CdeDAVriMVoKSlodqxhO6Vo4...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 3, current_sign_in_at: "2017-03-15 12:19:22", last_sign_in_at: "2017-03-15 12:17:25", current_sign_in_ip: "172.30.0.57", last_sign_in_ip: "172.30.0.57", created_at: "2017-03-15 11:46:27", updated_at: "2017-03-15 21:07:57", name: "Administrator", admin: true, projects_limit: 100, skype: "", linkedin: "", twitter: "", authentication_token: "y--EW2jDrxezMezm6wUN", theme_id: 2, bio: nil, failed_attempts: 0, locked_at: nil, username: "root", can_create_group: true, can_create_team: false, state: "active", color_scheme_id: 1, notification_level: 1, password_expires_at: nil, created_by_id: nil, last_credential_check_at: nil, avatar: nil, confirmation_token: nil, confirmed_at: "2017-03-15 11:46:27", confirmation_sent_at: nil, unconfirmed_email: nil, hide_no_ssh_key: false, website_url: "", notification_email: "admin@example.com", hide_no_password: false, password_automatically_set: false, location: nil, encrypted_otp_secret: nil, encrypted_otp_secret_iv: nil, encrypted_otp_secret_salt: nil, otp_required_for_login: false, otp_backup_codes: nil, public_email: "", dashboard: 0, project_view: 0, consumed_timestep: nil, layout: 0, hide_project_limit: false, unlock_token: nil, otp_grace_period_started_at: nil, ldap_email: false, external: false>
irb(main):002:0> user.password = 'LookBack.dwhd.org'
=> "LookBack.dwhd.org"
irb(main):003:0> user.password_confirmation = 'LookBack.dwhd.org'
=> "LookBack.dwhd.org"
irb(main):004:0> user.save!
=> true
irb(main):005:0> #按Ctrl+D键退出
root@DS-VM-Node58:/home/git/gitlab# mysql -u****** -p************ ****** -h127.0.0.1 -e "select id,email,encrypted_password,username from users where username ='root';"
+----+-------------------+--------------------------------------------------------------+----------+
| id | email             | encrypted_password                                           | username |
+----+-------------------+--------------------------------------------------------------+----------+
|  1 | admin@example.com | $2a$10$dVahm7BERhs1eLD41h1kNe65OAM3YGLcQSUUnocWkvde6BDVjMGWe | root     |
+----+-------------------+--------------------------------------------------------------+----------+
root@DS-VM-Node58:/home/git/gitlab# exit
exit
[root@DS-VM-Node58 ~]#

参考地址:https://docs.gitlab.com/ee/security/reset_root_password.html
GitLab在重置用户密码 - 找回root密码

lookback

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: