Is there a rake command to reset a Redmine admin password?
Asked Answered
N

2

5

I have lost the admin password for a redmine installation, and after trying the method of clearing the salt and setting the default hash for the password password I still cannot login.

Is there a rake command to set the default password, or set a specific password?

The Redmine version is 2.4.2

Nauseous answered 4/6, 2015 at 22:27 Comment(2)
Not sure (I don't have installed Redmine now so I can't check) but I believe you can do it through rails c. You can load RAILS_ENV=production rails c then something like this: u = User.where(email: '[email protected]').first; u.password = '123123'; u.password_confirmation = '123123'; u.save!Falstaffian
Can you provide me with the exact syntax? Working with Rails on the command line is something I have no knowledge of. ThanksNauseous
F
14

I believe you can reset your (any) password from rails console. Go to the Redmine folder on server and

# start console
RAILS_ENV=production bundle exec rails c

# find your user
user = User.where(email: '[email protected]').first

# set new password
user.password = '123123'
user.password_confirmation = '123123'

# save changes
user.save!

Please note if save! returns exception then changes can not be applied. Post exception message to the question.

Falstaffian answered 5/6, 2015 at 12:38 Comment(2)
That's true and worked for me, but 'cd $REDMINE_ROOT' is needed before, for starting console successfully.Breakout
bundle exec rails c -e production is better for login in production environmentWelty
W
4

If you don't remember the admin email address, another option is to use the userid .

  1. get your admin user id.

    mysql -u redmine_user -p # login MySQL

    mysql> use redmine; # choose redmine database

    mysql> select id,login from users where login='admin'; # show admin info

Now you have your admin id (first column) it should be 1 but can be any number if you have delete and recreated your admin user.

  1. Go to the redmine folder and change the password

    su - redmine_user # go under redmine user if you have one

    cd /var/www/redmine # cd in redmine document root

    # start the console

    RAILS_ENV=production bundle exec rails c

Wait until rail env come up.

# Load your admin user, I use id = 1 here but it should be what you have found in step 1 
user = User.where(id: 1).first

# set new password
user.password = 'password'
user.password_confirmation = 'password'

# save changes
user.save!
exit

Your done !

Bye

Wive answered 3/9, 2019 at 17:7 Comment(2)
The answer at zlargon.github.io is copied from the accepted answer to this one. You response is better changed to a comment describing a general way to get a key to the required user id.Nauseous
'select * from users' returns too many columns. You'd better limit the columns returnedNauseous

© 2022 - 2025 — McMap. All rights reserved.