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.
drush upwd
Change *
Assign a role
You can assign a role to a user, or set of users, using user- add-role command. The alias is urol.
drush urol rolename username
Example
To add the role editor to username test1:
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:
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:
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.
drush unrol rolename username
Example
To remove the role editor to username test1:
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:
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:
drush unrol editor --uid=3,4
Create users
You can create a new user using the user-create command. The alias is ucrt.
drush ucrt
Example
To create a user with username test1:
drush ucrt test1
Add email and password
You can add an email address and password for the user at the same time:
drush ucrt
Setting passwords
You can set a password for a user using the user-password command. The alias is upwd.
drush upwd
Example
Add letmein as a password to username test1:
$ drush upwd test1 --password=letmein
Use speech marks if the password is multiple words. For example:
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.
drush uinf
Example
Display information for user with username test1:
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:
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:
drush uinf 3,4
To display information for users with username test1 and test2:
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:
$ 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
drush ublk
Example
Block the user with username test1:
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:
drush ublk 3,4,test1
Unblock a user
You can unblock a user using the user-unblock command. The alias is uublk
drush uublk
Example
Unblock the user with username test1:
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:
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).