22

I'm running my Gitlab with Docker and I forgot my Gitlab root password. How to change it ?

hannes ach
  • 16,247
  • 7
  • 61
  • 84

3 Answers3

42

I found a way to make it work. First connect to your Gitlab with command line

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
hannes ach
  • 16,247
  • 7
  • 61
  • 84
  • 6
    I was not able to login after using this method to update root password. After login the container's terminal, instead of using this method, I update the root password by using the command `gitlab-rake "gitlab:password:reset[root]"`. ([reference](https://docs.gitlab.com/ee/security/reset_user_password.html#rake-task)). – panc Sep 05 '21 at 03:33
  • This proposed solution here worked for me. Remember that gitlab requires both letters and digits in the password. When you do `user.save` you should get a `true`. Ps. ❤️ rails Ds – Brainmaniac Aug 15 '23 at 12:28
38

The new-ish hotness to change Gitlab's "root" account's password is this:

gitlab-rake "gitlab:password:reset[root]"

And if you're running Gitlab inside a Docker container, then use this from the host (you may have to "sudo" this depending on your situation):

docker exec -it gitlab gitlab-rake "gitlab:password:reset[root]"

This assumes that you named your Gitlab container "gitlab". And be patient; don't be surprised if it takes more than a few seconds before the "Enter password:" prompt shows up.

Granger
  • 3,639
  • 4
  • 36
  • 34
  • 3
    This worked perfectly for me, so thanks for sharing! You were right about being patient, took ~40 seconds to show the prompt in my local dev – David Farrell Dec 21 '21 at 19:47
  • Worked perfectly! It is so annoying that is this not easily found in the official documentation. – marc.guenther Mar 09 '22 at 18:09
  • The prompt appeared and it said after I confirmed password: Password successfully updated for user with username root. But I still can't login into web portal. Did already 3 times with different passwords. Each time same result. I used docker image: gitlab/gitlab-ee:14.10.2-ee.0 – user1325696 Jul 13 '22 at 10:08
  • In my case problem can not be solved after I have taken docker volume moved to another machine using `cp -a gitlab /media/flshdrive/gitlab` nd then from flash to another machine. I use same docker image, but Ubuntu on new 22.04 instead of 18.04 and Docker is newer. – user1325696 Jul 13 '22 at 22:05
  • It didn't work for me on mbp M1 arm: : MADV_DONTNEED does not work (memset will be used instead) : (This is the expected behaviour if you are running under QEMU) – nach Nov 27 '22 at 00:51
  • Thanks a lot ! This worked for me as of August 5th 2023. I recommend to write your container id instead of "gitlab" after exec -it (seems basic knowledge but it can be confusing) – Brice Joosten Aug 05 '23 at 15:38
1

I leave a tutorial updated to the new version. In my case it is for a Gitlab installation on a Synology.

Translate (Spanish -> English ) https://translate.google.com/translate?sl=es&tl=en&u=https://www.vicolinker.net/synology-gitlab-reset-root-password/

Original (Spanish) https://www.vicolinker.net/synology-gitlab-reset-root-password/

victorelec14
  • 178
  • 12