Create Admin Account from Console


(Arpit Jalan) #1

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

Access Console

Connect to your Droplet via SSH, or use Putty on Windows:

ssh root@192.168.1.1

Replace 192.168.1.1 with the IP address of your Droplet.

Switch to your Discourse folder:

cd /var/discourse

Enter the container:

./launcher enter app

Create New Account with Admin Privileges

Run this command from console:

rake admin:create

You will be asked for Email, Password and Confirm Password.

After providing required information a new account will be created with random username.

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!.

Reset Password for Existing Account

Run this command from console:

rake admin:create

You will be asked for Email, enter the email of an 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 enter to continue.

Provide the new password and confirm password.

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

Grant Admin Privileges to 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!.


SOLVED: Unable to Grant Admin or Grant Moderator to existing users
Did localhost Discourse change drastically?
How to install Discourse on windows
Troubleshooting email on a new Discourse install
Changing administrator
Can't get email to work, have some issues getting started
Just installed Discourse on AWS
Continue Discourse Installation
Cannot access /admin
User should be able to login without verification
Change Email Domain from Subdomain to Root?
Getting Stucked during bootstrap
Continue Discourse Installation
Require mail confirmation to grant admin privileges
Beginner's Guide to Creating Discourse Plugins - Part 1
Create Account from Console but account not activated
How do I create admin rights for a new community? I've just set one up
Generating mailing logs for console to check installation?
What is included in the backup under Admin?
Dummy user to create initial content
Troubleshooting email on a new Discourse install
Beginners Guide to Install Discourse on Ubuntu for Development
Installtion on aws New Cloud Server but not Working
Discourse as Your First Rails App
How to access the discourse database?
Update discourse hostname
#7

Hey, mind updating this how-to? executing rake admin:create spits out an error about that database discourse_developement (or so) doesnt exist.


(Renis) #8

Have you renamed the database?

use: RAILS_DB='your_db_name' ; #default discourse

#9

Rake doesn’t seem to recognize use: RAILS_DB='your_db_name'. Where do I have to write that to?


(Renis) #10

Once you are inside the container, execute the following command:

 rake admin:create RAILS_DB=discourse 

a prompt will come up asking, email, password and if you want to add admin privileges or not…

:wink:


How to get admin access when using the Vagrant install?
(Alessio Fattorini) #14

@techAPJ you saved my life with this :slight_smile: thank you very much!


(Brian Mc Gonagill) #15

When I try this, I get a bit of an error as well, but it says the following.

Do you want to grant Admin privileges to this account? (Y/n)  
rake aborted!
ActiveRecord::RecordInvalid: Validation failed: Name must be at least 6 characters

Any help is greatly appreciated.


(Jeff Atwood) #16

There is the issue, right there.


(Brian Mc Gonagill) #17

Thanks @codinghorror. I saw that message, but I don’t know what name it refers to. I am following the instructions in this guide and entering the email address of the members I wish to make admins.

I am only prompted for email addresses (which are much more than 6 characters). I then select ‘n’ for changing their pasword, and press Enter as instructed here.


(Brian Mc Gonagill) #18

Nevermind, found the answer here SOLVED: Unable to Grant Admin or Grant Moderator to existing users


(Ken) #19

This is not working for me, I am having email issues and was hoping this would allow my admin user to log in and possibly get access to more useful debugging info. Currently, I am locked out due to not receiving activation mails.

I have a multi-site setup. I do:

./launcher enter app
rake admin:create RAILS_DB=my_site_db
Email:  me@mydomain.com
User with this email already exists! Do you want to reset the password for this email? (Y/n)  y
Password:  
Repeat password:  

Ensuring account is active!

Account updated successfully!
Do you want to grant Admin privileges to this account? (Y/n)  y

Your account now has Admin privileges!

But when I try to log in, I am denied with

 You can't log in yet. We previously sent an activation email to you at me@mydomain.com. Please follow the instructions in that email to activate your account. Click here to send the activation email again.

Is this the correct way to activate a user when activation mail is not sending? Is this the correct way to activate a user for a specific site in a multisite setup?

Thanks!


(Sam Saffron) #20

Are you running multisite ? what is the deal with RAILS_DB=my_site_db ?


(Ken) #21

Yes, multisite - I am using RAILS_DB=my_site_db to point to the site-specific database, as suggested by renis above (possibly not correct, but I also did the same without this option, with the same results). Possibly relevant, the database is not in a container, but running on my host - discourse seems to connect to it without issue.

Basically I am stuck unable to log in and not receiving email - I was planning a separate, detailed post about the email problem, but was just hoping to be able to log in an perhaps get more debugging information (will the web UI give me access to anything not in the production logs in /var/www/discourse/logs in the container?)

Anyway, thanks, any help or advice is appreciated.


(Sam Saffron) #22

You have an ordering issue, rails db is before rake


(Ken) #23

I thought that looked odd - but just tried

RAILS_DB=my_site_db rake admin:create

and got the same results.

Poking around in the database, the active flag for my user on this site database was set to false - setting it to true in psql did not fix the issue, but led me to look around at other databases, where I noticed that my user exists in the ‘primary’ (id 1) site’s database (presumably from a previous admin:create attempt), and is active there. I wasn’t planning to use that site immediately, and was concentrating on one of several other sites I have set up in multisite.yaml.

Logging in to that primary site works for my user without an activation email, and the dashboard there tells me that SideKiq is not running, which probably explains a lot of other things.

Conclusion: There are many moving parts.

Thanks again for your time.


(Ian White) #25

Hi kennric,

I’m attempting a similar setup to you. I have a multisite setup, but can’t seem to select the 2nd site for running the rake tasks.

Did you ever figure this out?


(Ian White) #26

I figured out what I was doing wrong. You need to specify the database config key (in multisite.yml) rather than the database name. For example, if your multisite.yml is:

forum2:
  database: f2_discourse
  ...

then the command to add an admin is:

RAILS_DB=forum2 rake admin:create

(John Kennedy) #27

Thank you very much!
:grin:


(xXAlphaManXx) #28

It is good that i was able to create one from the above commands, but how can i exit the app? i mean, how can i go back to the root of my system. Is there any commands like ./laucher exit app ?


(cpradio) #29

No, just type exit and hit enter.