Lost Admin rights on your Moodle Site – Assign admin role to other user

While upgrading the Moodle LMS to a new version or testing a new plugin on your site, there  may be chances when you might have accidentally lost access to your admin account. And you couldn’t reset it without any means like the forget password option also not working. In this post we will see how you can assign admin role to any user in your Moodle.

While testing an authentication plugin on my development Moodle, I was also stuck up with no login for my admin account. Luckily, I have another test user with a student role, so by using the tip mentioned below, I was able to upgrade the student account as an admin and later recovered my main admin account.

However, in order to use this handy tip, you need to make sure that you know the ID of the new user whom you want to elevate as site admin.In case you don’t know the ID of the user, then you can find it out from the Moodle database in table mdl_user (where mdl is your database prefix).

Lost Admin rights on your Moodle Site – Assign admin role to other user
Add this line in config.php file

Once you are having the ID, then follow the steps below:

  • Navigate to Config.php file of your Moodle site (it is located in the root directory of your Moodle site)
  • Now, open the file in a text editor like Notepad etc.
  • Add the following line in your config.php file where 2 is the original admin user established when first installing, and [yourotheradminid] the ID number of the other user you setup as admin levels –
$CFG->siteadmins='2,[yourotheradminid]';
  • Save your config.php file and login with your student credentials. You will see the admin privileges.

What are the other handy tips you have to share with the Moodle community? Please let us know in the comments section below.

For regular updates about Moodle, eLearning and edtech industry, please visit us regularly at https://lmsdaily.com. You can also like us on Facebook or follow us on Twitter, or Subscribe our YouTube Channel.

Related articles

Are you still paying thousands for Interactive eLearning Software in 2026? And why you shouldn’t…

There are still many instructional designers, elearning content creators...

Moodle Plugins directory now read only – Moodle Marketplace releasing on July 20th

Moodle Plugins directory which has been the backbone of...

Join MoodleMoot Global 2025 in Edinburgh UK from 16-18 September 2025

MoodleMoot Global 2025 will take place from in Edinburgh...

Join MoodleMoot Australia 2024 on 26-27 November 2024 in Melbourne

MoodleMoot Australia 2024 will take place on 26-27 November...

Case Studies