How to login as any user in Drupal site?
It is no surprise that production sites at times may work differently from dev / stage due to various factors. And in such circumstances, there is a need to login as real site user to be able to reproduce the issue. Of course it is not easy to fix a bug unless it is really reproduced by developer.
In one of my recent works, I found a simple trick using Drush to get access to real user account without distrubing his/her account credentials like login name, email, password, or similar.
The trick I used counts on drush user-login command, alias uli (which I learned from my earlier blog post's comments).
Assume sivaji (login name) is a real user in your Drupal site, and you are really in need to get access to this user account, then issue the below command,
The output of the command will be a link, which you need to open in browser to get access of mentioned user account. The sample URL could be as below,
Make sure you are opening as anoymous user. If you are in multisite environment, the above command may not work, check Using Drush to administer multisite for the same.
Check out help for more advanced usage, as the above command can work with uid and email as well.
Of course there is a flip side here! This resets the last login time :(
If this is not expected for your site's requirements, be prepared to workaround or refrain from using this trick.
Hope this helps. Happy Drupal hacking!