Managing users with Drush

Learn more

Master Drupal Development: Get the book to scale the learning curve faster

Start learning Drupal 8 development today: Get the free 7 lesson course

Dealing with user accounts is an essential part of Drupal development. You’ll find yourself needing to:

  • Change the password for a user
  • Change the password for the admin account on your local site so you can login as admin
  • Block a user to prevent them from logging in
  • Create new user accounts
  • Add a role to a user account so you can test permissions

You can do all of this in the Drupal admin interface, but it takes time. Fortunately, Drush has a rich set of commands to help you save time while performing these necessarily user related chores. And who doesn’t want to save time?

Jump straight to the cheatsheet, or read on for a more detailed list of commands.

Changing passwords for an existing user

You can change the password for an existing user using the user-password command. The alias is upwd.

  1. drush upwd <username> —password=<new password>

Change to the actual username and to the desired password.

Assign a role

You can assign a role to a user, or set of users, using user- add-role command. The alias is urol.

  1. drush urol rolename username

Example

To add the role editor to username test1:

  1. drush urol editor test1

You can also use the user ID or email address instead of the username. For example, to add editor role to user with uid of 3:

  1. drush urol editor 3

Multiple user accounts

You can add a role to multiple user accounts at the same time. To do that, you need to use either the --name,--mail or --uid option.

For example, to add the editor role to users with ids 3 and 4, use:

  1. drush urol editor --uid=3,4

Remove a role

You can remove a role from a user, or set of users, using the user-remove-role command. The alias is unrol.

  1. drush unrol rolename username

Example

To remove the role editor to username test1:

  1. drush unrol editor test1

You can also use the user ID or email address instead of the username. For example, to add editor role to user with uid of 3:

  1. drush unrol editor 3

Multiple user accounts

You can remove a role from multiple user accounts at the same time. To do that, you need to use either the --name,--mail or --uid option.

For example, to remove the editor role to users with ids 3 and 4, use:

  1. drush unrol editor --uid=3,4

Create users

You can create a new user using the user-create command. The alias is ucrt.

  1. drush ucrt <username>

Example

To create a user with username test1:

  1. drush ucrt test1

Add email and password

You can add an email address and password for the user at the same time:

  1. drush ucrt <username> --mail=<email address> -- password=<password>

Setting passwords

You can set a password for a user using the user-password command. The alias is upwd.

  1. drush upwd <username> --password=<password>

Example

Add letmein as a password to username test1:

  1. $ drush upwd test1 --password=letmein

Use speech marks if the password is multiple words. For example:

  1. drush upwd test1 --password=”this is a really long password”

Display information about a user

You can display information about a user using the user-information command. The alias is uinf.

  1. drush uinf <username>

Example

Display information for user with username test1:

  1. drush uinf test1

You can use the user email address or uid if you prefer. For example, to display information for user with uid 3:

  1. drush uinf 3

Multiple users

You can display information for multiple users. Simply add multiple usernames, uids or email addresses, separated with a space. For example, to display information about users with uids 3 and 4:

  1. drush uinf 3,4

To display information for users with username test1 and test2:

  1. drush uinf test1,test2

You can mix them as well. For example, to display information about user with uid 2 and also user with name of test3:

  1. $ drush uinf 2,test3


Note: there is no space between each user identifier.

Block a user

You can block a user using the user-block command. This will prevent the user from logging in. The alias is ublk

  1. drush ublk <username>

Example

Block the user with username test1:

  1. drush ublk test1

Multiple users

You can block multiple users at the same time. Simply add multiple usernames, uids or email addresses, separated with a space. For example, to block users with uids 3 and 4 and username test1:

  1. drush ublk 3,4,test1

Unblock a user

You can unblock a user using the user-unblock command. The alias is uublk

  1. drush uublk <username>

Example

Unblock the user with username test1:

  1. drush uublk test1

Multiple users

You can unblock multiple users at the same time. Simply add multiple usernames, uids or email addresses, separated with a space. For example, to unblock users with uids 3 and 4 and username test1:

  1. drush unblk 3,4,test1

Checkout the cheatsheet

I’ve created an online cheatsheet for easy access to the Drush user commands mentioned above - check it out here

There is the full Drush cheatsheet available (see the box below).

Get your free Drush Cheatsheet

Drush is awesome - and every awesome thing requires a cheatsheet!

Get your Drush cheatsheet

Comments

Hi Blair,
Thank you for publishing a great content. Could I translate to Japanese and provide to Japanese people in my blog?
http://blog.mizoshiri.com/

Cheers,
Ayumi

Blair Wadman's picture

Hi Ayumi, Thanks for asking, yes that is fine. I'd appreciate it if you could provide attribution.

Add new comment