Get One-Time Login

First you will open your terminal and navigate to the root directory of the website, then execute the drush user-login command (or its abbreviated version: drush uli). For instance here I will be using CPanel:

2024-03-12T102548

Some similar commands are:

1
2
drush uli --name=admin
drush uli --uid=1

Using One-Time Login

Once you’ve got the login url from the terminal, for instance:

1
http://default/user/reset/1/0123456789/0D_CraSDdasdaa432s2DSAJDKLJASKLD_0A/login

You will need to copy the bit after the default/ starting with /user , and paste them after the base url of your drupal website (or in another word, replace default with the base-url of your website), for instance:

1
http://www.example.com.au/user/reset/1/0123456789/0D_CraSDdasdaa432s2DSAJDKLJASKLD_0A/login

Then you should be prompted to have succssfully logged in with the corresponding user.

2024-03-12T103231

(Note: the one-time login have to be performed within 60 seconds, it cannot be reused overtime, you will be seeing something like: “Error message: You have tried to use a one-time login link that has expired. Please request a new one using the form below” when the login expires.)

Replace “default” with actual domain

If you wish to replace the default with your actual website domain, such you get an url you can directly copy and paste to login, you’ll need to declare the environmental variable DRUSH_OPTIONS_URI, for instance, if my website is www.example.com.au, I need to run:

1
2
3
> export DRUSH_OPTIONS_URI=https://www.example.com.au
> drush uli
  http://www.example.com.au/user/reset/1/0123456789/0D_CraSDdasdaa432s2DSAJDKLJASKLD_0A/login

To avoid needing to run the export command every time to assign environmental variable manually, I prefer to append the following to my server’s ~/.bashrc file (or other ~/.*rc file depending on which shell in use):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
    # .bashrc

    alias drush="~/public_html/vendor/bin/drush"
+   export DRUSH_OPTIONS_URI=https://www.example.com.au

    # User specific aliases and functions

    # Source global definitions
    if [ -f /etc/bashrc ]; then
            . /etc/bashrc
    fi

    # export PATH=$HOME/opt/bin:$HOME/bin/drush:$PATH