Can't login to a new installation after restoring backup

I had this installation
forum.example.com
I had my admin account admin@forum.example.com with my password and 2FA

Eventually I decided to migrate that to a new domain
community.newexample.com

Before I did that, I created a backup of forum.example.com

Today I decided that I wanted to create a new community at example.com
Installed everything, created the new admin account (admin@example.com), etc.
Logged in.
Went to the backups section and uploaded the backup I created for forum.example.com

It logged me out.
When I tried to log in using the new credentials (admin@example.com), it wouldn’t let me, because I’m guessing that it’s now trying to use the credentials from the first installation (admin@forum.example.com)

The issue is also that I no longer have the 2FA for forum.example.com, but it’s asking for that as well.

What can I do now?

UPDATE: I was able to do it by following ChatGPT’s instructions:

:white_check_mark: Step 1: SSH into your server

ssh your-user@your-server

:white_check_mark: Step 2: Enter the Discourse app container

cd /var/discourse
./launcher enter app

:white_check_mark: Step 3: Create or reset the admin user’s password

This step ensures you can log in with a known password.

rake admin:create
  • When prompted, enter the email address of the admin from the backup (e.g. admin@forum.example.com).
  • Enter a new password.
  • Type Y when asked to grant admin privileges (even if the user already is an admin — it won’t hurt).

:white_check_mark: Step 4: Open the Rails console

rails c

:white_check_mark: Step 5: Find the user by email

Replace the email with the one you’re resetting:

user = User.find_by_email("admin@forum.example.com")

You should see some output showing the user object.


:white_check_mark: Step 6: Disable 2FA for that user

user.user_second_factors.destroy_all

This deletes all 2FA keys associated with that user — without affecting anyone else.


:white_check_mark: Step 7: Exit the console and container

exit

:white_check_mark: Step 8: Log in via the web

Go to your Discourse site in the browser and log in with:

  • Email: admin@forum.example.com
  • Password: the one you set in Step 3
  • 2FA: will no longer be required
1 Like