How to activate the admin account of Discourse using the SSH console?

I am trying to setup Discourse with one-click installer using droplet over Digital Ocean. I followed all the instructions and have correctly configured the SMTP details. But when I register for the admin account using the front-end installer, I am not able to receive the email.

I read a tutorial where it is mentioned that if the email doesn’t land in the mailbox, I can still activate the account and set the user as admin using the following commands using the console:

cd /var/discourse
sudo ./launcher enter app
rails c
user = User.find_by_email("<admin_email>")
user.admin = true
user.approved = true
user.save
EmailToken.confirm(user.email_tokens.first.token)

I am able to run the commands up to the fourth line. After running the fourth command, it finds and displays the user details. But I am not able to enter the next command. There’s this colon “:” and when I reach the end of the displayed details, “(END)” is written. I can’t type and run the further commands to activate the user.

After rails c, there’s this [1] pry (main) > thing. Please help me out on how to enter the next commands and activate the account.

The issue you’re encountering is related to the rails console environment, which uses Pry, an interactive Ruby shell. When you enter the console (rails c), it allows you to inspect objects and run commands. However, when the output is too large (like the details of the user), it uses the less pager, which lets you scroll through the content but prevents you from typing new commands directly until you exit the pager.

How to Exit the Pager and Continue Running Commands:

  1. Exit the Pager: While you’re viewing the user details and see (END), you are in the pager (likely less). To get back to the command prompt where you can type further commands, simply press the q key to quit the pager.
  2. Run Further Commands: After quitting the pager, you’ll return to the pry shell, where you can continue running your commands. Now, you should be able to enter the following to activate the user and assign admin rights:
user.admin = true
user.approved = true
user.save
EmailToken.confirm(user.email_tokens.first.token)
  1. Alternative Command Flow: If you’re stuck in the pager or it keeps happening, you can also try running the commands without having the user details printed out first. After you find the user with User.find_by_email("<admin_email>"), you could directly run the commands like this:
user = User.find_by_email("<admin_email>")
user.admin = true
user.approved = true
user.save
EmailToken.confirm(user.email_tokens.first.token)

This way, it will not output the user’s details and won’t enter the pager.

Summary of Steps:

  1. Run rails c to enter the console.
  2. Find the user with user = User.find_by_email("<admin_email>").
  3. If the pager is triggered, press q to quit the pager.
  4. After exiting the pager, you should be able to run the remaining commands:
user.admin = true
user.approved = true
user.save
EmailToken.confirm(user.email_tokens.first.token)

This should activate your user account and set them as an admin.

Let me know if you run into any other issues!