Create an admin account from the console

:bookmark: This guide provides instructions for creating an admin account or granting admin privileges using the console in a self-hosted Discourse installation.

:person_raising_hand: Required user level: System Administrator
:warning: Console access required

So you want to create/grant Admin privileges or reset user password from console? Great, let’s get started!

This guide will cover the following:

  • Accessing the console
  • Creating a new account with admin privileges
  • Resetting an existing password
  • Granting admin privileges to an existing account
  • Multisite configuration instructions

Accessing the console

Connect to your Discourse server using SSH, or use Putty if you’re on Windows:

ssh root@your.server.ip

Replace your.server.ip with the actual IP address of your server.

Switch to your Discourse directory:

cd /var/discourse

Enter the Docker container:

./launcher enter app

Creating a new account with admin privileges

Inside the console, run the following command:

rake admin:create

You will be prompted for:

  • Email
  • Password
  • Confirm Password

A new account will be created with a username based on the email address. When asked if you want to grant admin privileges, press Enter to confirm.

If successful, you’ll see: “Your account now has Admin privileges!”

Instructions for multisite

If you have a multisite configuration you’ll run:

RAILS_DB=my_site_db rake admin:create 

Resetting the password for an existing account

To reset a password, execute the same command:

rake admin:create

Enter the email of the existing account. If the user exists, you will be asked if you want to reset the password. Press Enter to proceed. Provide and confirm the new password.

If it worked, you’ll see Account updated successfully!.

Granting admin privileges to an existing account

Run this command from console:

rake admin:create

You will be asked for Email, enter the email of existing account.

Now you will be asked: User with this email already exists! Do you want to reset the password for this email? (Y/n). Press n then enter.

Now you will be asked: Do you want to grant Admin privileges to this account? (Y/n). Press enter to continue.

If it worked, you’ll see Your account now has Admin privileges!.

Multisite configuration instructions

For multisite setups, prepend the commands with RAILS_DB=multisite_name, where multisite_name corresponds to the top line of your multisite configuration:

Example configuration:

mysite:
  adapter: postgresql
  database: database2
  password: secret
  pool: 25
  host: data
  host_names:
    - mysite.example.com

Command:

RAILS_DB=mysite rake admin:create

Last edited by @SaraDev 2024-11-15T00:04:38Z

Check documentPerform check on document:
58 Likes