Try   HackMD

gitlab重設root password

tags: gitlab

2022/05/19
因最新版的gitlab安裝完成後,第一次連線並不會出現重設root密碼的UI畫面,導致無法登入。而網路教學有提到如何取得initial_root_password,但實際操作上又遇到initial_root_password檔案不存在的問題。好不容易找到workaround的方法,趕緊來記錄一下。

使用環境

  • synology DS920+, DSM 7.0
  • gitlab installed by docker
  • SSH連線關係:
    PC/NB
    NAS
    docker
    gitlab

參考資料

1. Synology Gitlab: Reset root password (or from another user) (西班牙文,需要翻譯機XD)
2. 如何重置 Docker 里的 gitlab root 用户密码
3. docker gitlab 初始密码查看_cirea的博客-CSDN博客_docker gitlab 密码

實際步驟操作

step 1. 使用ssh連線至NAS by PuTTY

預設port為22,若NAS設定有修改,請記得確認

step 2. 取得superuser權限

sudo su

step 3. 取得docker container ID & Name

docker ps

畫面示意圖

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

step 4. 進入docker container的console

docker exec -it <container ID or names> bash

(option) 取得initial_root_password (我這次操作時,檔案不存在)

grep 'password:' /etc/gitlab/initial_root_password

若此步驟可行,到此就已取得root password可直接登入gitlab,就不需後續步驟了

step 5. 在container的console內,啟動ruby gem console

gitlab-rails console -e production

step 6. 重設root密碼

Loading production environment (Rails 4.2.10) irb(main):001:0> user=User.where(id:1).first => #<User id:1 @root> irb(main):003:0> user.password='9aa9871ouf906' => "9aa9871ouf906" irb(main):004:0> user.password_confirmation='9aa9871ouf906' => "9aa9871ouf906" irb(main):005:0> user.save! Enqueued ActionMailer::DeliveryJob (Job ID: 55d5938a-8506-49cc-be8c-6afd666c4efe) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", gid://gitlab/User/1 => true irb(main):006:0>

line 2:根據user ID取得user資料,通常root的user ID為1
(可確認一下line 3是否顯示root為使用者名稱)
line 4:設定新的密碼
line 6:重覆輸入新的密碼作確認
line 8:儲存user設定