I want to set up user name & password authentication for my MongoDB instance, so that any remote access will ask for the user name & password. I tried the tutorial from the MongoDB site and did following: Show
After that, I exited and ran mongo again. And I don't need password to access it. Even if I connect to the database remotely, I am not prompted for user name & password. UPDATE Here is the solution I ended up using
The username & password will work the same way for
asked Feb 2, 2011 at 23:35
murvinlaimurvinlai 47.2k51 gold badges126 silver badges174 bronze badges 6 You need to start From the MongoDB Site:
MongoDB Authentication
answered Feb 2, 2011 at 23:54
2
Wow so many complicated/confusing answers here. This is as of v3.4. Short answer.
Long answer: Read this if you want to properly understand.It's really simple. I'll dumb the following down https://docs.mongodb.com/manual/tutorial/enable-authentication/ If you want to learn more about what the roles actually do read more here: https://docs.mongodb.com/manual/reference/built-in-roles/
Or if you want to create an admin which is admin over any database:
You are now authenticated as a
More on roles: https://docs.mongodb.com/manual/reference/built-in-roles/ If you wish to make additional users which aren't user administrators and which are just normal users continue reading below.
Last but not least due to users not reading the commands I posted correctly regarding the answered Mar 21, 2017 at 14:25
basickarlbasickarl 33.5k57 gold badges198 silver badges312 bronze badges 9 First, un-comment the line that starts with Then, restart mongodb :
CoderUni 4,8015 gold badges23 silver badges53 bronze badges answered Nov 4, 2013 at 13:38
5 This answer is for Mongo 3.2.1 Reference Terminal 1:
Terminal 2:
if you want to add without roles (optional):
to check if authenticated or not:
it should give you:
else :
JohnAllen 6,9119 gold badges40 silver badges62 bronze badges answered Jan 24, 2016 at 4:31
SdemblaSdembla 1,54912 silver badges13 bronze badges 2 Here is a javascript code to add users.
Camilo Martin 36.3k20 gold badges109 silver badges153 bronze badges answered Nov 20, 2012 at 10:43
BharadvajBharadvaj 2813 silver badges3 bronze badges 4 You could change Before
After
Then answered Oct 2, 2019 at 18:30
First run mongoDB on terminal using
now run mongo shell use following commands
Re-start the MongoDB instance with access control.
Now authenticate yourself from the command line using
I read it from https://docs.mongodb.com/manual/tutorial/enable-authentication/
WAF 9853 gold badges14 silver badges31 bronze badges answered Dec 7, 2016 at 11:06
3 This is what I did on Ubuntu 18.04:
answered Apr 24, 2019 at 22:32
JinminJinmin 1851 gold badge2 silver badges10 bronze badges User creation with password for a specific database to secure database access :
answered Dec 17, 2017 at 11:36
Follow the below steps in order
You can check out this post to go into more details and to learn connecting to it using mongoose. answered Mar 4, 2019 at 7:42
rahil471rahil471 3042 silver badges7 bronze badges This is what i did for ubuntu 20.04 and mongodb enterprise 4.4.2:
(optional) 6.If you want your user to have root access you can either specify it when creating your user like:
or you can change user role using:
answered Dec 2, 2020 at 13:54
ma_jafarima_jafari 9581 gold badge5 silver badges24 bronze badges Some of the answers are sending mixed signals between using
I would like to clarify that aspect. First of all, authentication credentials (ie user/password) in both cases has to be created by executing
To connect to the mongo shell with authentication:
Refer to https://docs.mongodb.com/manual/tutorial/enable-authentication/ for details. answered Jan 20, 2021 at 11:32
Binita BharatiBinita Bharati 4,3821 gold badge36 silver badges22 bronze badges The best practice to connect to mongoDB as follow:
the following script will create the admin user for the DB.
This allows you to create different user and password for the different collection you creating in the MongoDB
turivishal 31.6k7 gold badges34 silver badges55 bronze badges answered Jul 22, 2018 at 8:29
Balaji.J.BBalaji.J.B 5386 silver badges14 bronze badges 1 These steps worked on me:
Pang 9,193146 gold badges85 silver badges118 bronze badges answered Jan 17, 2018 at 5:16
after you create new user, please don't forget to
Rajat Mishra 3,5054 gold badges26 silver badges37 bronze badges answered Jun 8, 2017 at 8:45
mongodb 4.4.13 community1. create database user
1.2 verify working
if it fails you get
2. modify /etc/mongod.conf
change:
to:
3. restart mongod service
this is what worked for me. answered Jun 2 at 5:29
Kelvin WangKelvin Wang 5273 silver badges20 bronze badges Many duplicate answers but I think they miss an important note: Even when authentication is enabled properly you can connect to the Mongo database without username/password! However, you can execute only harmless commands like
answered Apr 21, 2021 at 9:28
|