{"id":5335,"date":"2020-01-09T13:44:36","date_gmt":"2020-01-09T08:14:36","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=5335"},"modified":"2020-01-09T13:49:08","modified_gmt":"2020-01-09T08:19:08","slug":"how-to-enable-the-mongo-database-authentication-method","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/how-to-enable-the-mongo-database-authentication-method\/","title":{"rendered":"How to enable the mongo Database authentication method"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">How to enable the mongo Database authentication method<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Date: 09\/01\/2020<\/h4>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/01\/mongo-image.jpeg\" alt=\"\" class=\"wp-image-5339\" width=\"587\" height=\"317\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/01\/mongo-image.jpeg 306w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/01\/mongo-image-300x162.jpeg 300w\" sizes=\"(max-width: 587px) 100vw, 587px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Introduction<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Having an authentication for a database can not be a choice. Some may find it not necessary when it confined only use the database locally. It&#8217;s incredibly important to set up authentication if you are only using it locally. In this, we will discuss setting up root user and DB specific users for Mongo DB.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Create Admin\/Root user<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">By default, mongo will have <code>mongo-root<\/code> as root user under <code>admin<\/code> database. To create new root user do <br><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">db.createUser(\n{\n    user: \"root\",\n    pwd: \"password\",\n    roles: [ \"root\" ]\n})<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To Change existing root user password<br><br><code>use admin<\/code> # to list admin users<br><code>db.changeUserPassword('mongo-root' , 'XXXXXXX');<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Sometime you may want to change the password of the root when you logged out from Mongo DB. In that case edit <code>\/etc\/mongo.conf<\/code> and set <br><code>security:<br>#     auth = true <\/code><br>             <code>notauth = true<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>or <\/code><br><code>authentication = 'enabled'  <\/code><br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Restart the DB<code><br>systemctl restart mongod<\/code><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Create DB Specific User<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">To create a DB user<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">db.createUser(\n              { user: 'dbuser', \n                pwd: 'xxxxxx', \n                roles: [ \n                        { role: 'userAdmin', db: 'dbname'}, \n                        { role: 'readWrite', db: 'dbname'},  \n                        {role: 'dbAdmin', db: 'dbname'} \n                       ]\n              });<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">you could find many different kinds of roles for Mongo DB. But I confined to create with mention essential roles<code><br><\/code><br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To access through CLI,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>monog -u dbuser  -p 'xxxxxx' 127.0.0.1\/dnname<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Great job. you know the creating users&#8217; process in Mongo DB. If you find it useful, share it within your circle.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to enable the mongo Database authentication method Date: 09\/01\/2020 Introduction Having an authentication for a database can not be [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[744,743],"class_list":["post-5335","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-authentication","tag-mongo","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-1o3","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5335","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=5335"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5335\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=5335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=5335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=5335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}