How to Reset the MongoDB Root Password on ubuntu 18.04/20.04 LTS - TechBeginner

Welcome to TechBeginner.in, Tech Beginner provides technical blog for Online Linux Tutorials, Ubuntu Tutorials, Redhat Tutorials and CentOS 7, Configuration of server like Web Server, Application server, Database server, Window server, networking, html, css, java script, php, wordpress, opencart, magento, joomla and etc.

How to Reset the MongoDB Root Password on ubuntu 18.04/20.04 LTS

Share This


 

Working as MongoDB administration, Sometimes we need to reset and change the user's password.

 

MongoDB Installation - https://www.techbeginner.in/2020/03/how-to-install-mongodb-on-ubutnu-1604.html

 

 

In this post, We will reset the root password of MongoDB on ubuntu 18.04/20.04 LTS

 

Step 1: Disable Authentication

 

You need to disable authentication and also enable  auth by pass by using the given following command.

sudo vim /etc/mongod.conf

Paste the given configuration in security section.

security:
    authorization: disabled
setParameter:
    enableLocalhostAuthBypass: true

 

Save and exit from the text editor.

 

Step 2: Login MongoDB Shell

 

You need to login mongoDB shell to update the root's password by executing below command.

mongo

 

Step 3: Choose Database

 

Here you need to choose the MongoDB database by using the given command.

use admin


Step 4: Update the Password

 

Here you need to execute the given command to update the root user password, Make sure you need to update your own new password in your real scenario. 

db.updateUser("root", {pwd: "new_password_here"}) 

 

Step 5: Enable Authentication in MongoDB 

 

You need to enable again mongoDB authentication using MogoDB main config file /etc/mongod.conf Use the following command for the same.

security:
    authorization: enabled
setParameter:
    enableLocalhostAuthBypass: false

 

Step 6: Restart the MongoDB Service

 

To get new changes you need to restart the mongoDB service by execution the following command.

sudo systemctl restart mongod


Conclusion

 
We have successfully reset pr update the mongoDB root account password on ubuntu machine, Still you have any issue leave a comment.


 

 

1 comment: