Skip to main content

How to recover admin account via Drush in Drupal 10

How to recover admin account via Drush in Drupal 10

Recover admin account via Drush

Drush is a command line tool to perform administrative tasks in Drupal. You can recover admin account via Drush using command line interface.

It is very common to forget the admin credential in your Drupal application. But don't worry you can recover your password using Drush (Drupal Shell).

Image
Drush uli

What is a drush

Drush is a command line tool to perform administravice task in Drupal applicaiton. You can install it in your application by running following command.

composer require drush/drush

This is development CLI tool hence you can use it via terminal.

 

How to recover admin account via Drush

Drush has a simple but powerful command that generates a one-time login link for a specific user. By default, it produces a login link for user ID 1, the Drupal application's default administrator.

drush --uri=https://bhimmu.lndo.site uli
// Output
https://bhimmu.lndo.site/en/user/reset/1/1710099457/m3ssdfdfsdfsdfsdfsdfsfggdg65nNVXUUk6Ahqk/login

The command above will create a one-time login link for the default admin user (user ID 1). You can access the URL in your browser. Once you click the link, you will be sent to a password recovery web page where you may reset your password.

Reset admin user password

drush user:password "username" "newpassword"
// if user name is bhimmu
drush user:password "bhimmu" "my_new_password"

Here are important Drush commands that you may use frequently

  1. drush user:login
  2. drush user:password
  3. drush user:create
  4. drush user:cancel
  5. drush user:role:add
  6. drush user:role:remove
  7. drush user:block
  8. drush user:unblock
  9. drush cr
  10. drush updatedb

You can get the more about any command by passing --help flag

drush uli --help

// Output
Display a one time login link for user ID 1, or another user.

Examples:
 drush user:login                           Open browser to homepage, logged in as uid=1.
 drush user:login --name=ryan node/add/blog Open browser (if configured or detected) for a one-time login link for
                                            username ryan that redirects to node/add/blog.
 drush user:login --uid=123                 Open browser and login as user with uid "123".
 drush user:login --mail=foo@bar.com        Open browser and login as user with mail "foo@bar.com".

Arguments:
 [path] Optional path to redirect to after logging in.

Options:
 --name[=NAME]                 A user name to log in as.
 --uid[=UID]                   A user ID to log in as.
 --mail[=MAIL]                 A user email to log in as.
 --browser[=BROWSER]           Open the URL in the default browser. Use --no-browser to avoid opening a browser.
                               [default: true]
 --redirect-port=REDIRECT-PORT A custom port for redirecting to (e.g., when running within a Vagrant environment)
 --no-browser                  Negate --browser option.