TruCol / Self-host-GitLab-CI-for-GitHub

Installs your own GitLab CI and runs it on all your GitHub repos, in a single command.
GNU Affero General Public License v3.0
4 stars 3 forks source link

Write script to reset GitLab Root pw inside docker #7

Open a-t-0 opened 3 years ago

a-t-0 commented 3 years ago

Why: Sometimes a user may forgot a GitLab password without wanting to make and restore a complete backup of the server in a fresh GitLab server installation.

      <p><a rel="nofollow" href="https://stackoverflow.com/questions/55747402/docker-gitlab-change-forgotten-root-password">https://stackoverflow.com/questions/55747402/docker-gitlab-change-forgotten-root-password</a></p>

search for your Docker CONTAINER_ID

docker ps -all

eg

enter image description here

docker exec -it d0bbe0e1e3db bash <-- with your CONTAINER_ID

$ gitlab-rails console -e production

enter image description here

user = User.where(id: 1).first
user.password = 'your secret'
user.password_confirmation = 'your secret'
user.save
exit
a-t-0 commented 3 years ago
      <p>After you type the <code>gitlab-rails..</code> command, you wait until you see the <code>:0&gt;</code> and then you start typing, and enter for each line. It will also give some output inbetween, like:</p>
root@127:/# gitlab-rails console -e production
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
 GitLab:       13.12.3 (757327a59bc) FOSS
 GitLab Shell: 13.18.0
 PostgreSQL:   12.6
--------------------------------------------------------------------------------
Loading production environment (Rails 6.0.3.6)
irb(main):001:0> user = User.where(id: 1).first
=> #<User id:1 @root>

irb(main):002:0> user.password = 'yoursecret'
=> "yoursecret"

irb(main):003:0> user.password_confirmation = 'yoursecret'
=> "yoursecret"

irb(main):004:0> user.save
Enqueued ActionMailer::MailDeliveryJob (Job ID: somelongkey to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", {:args=>[#<GlobalID:someothershorterkey @uri=#<URI::GID gid://gitlab/User/1>>]}
=> true

irb(main):005:0> exit

root@127:/#