1

When I installed mongodb in ubuntu, user mongodb and group mongodb are created in /etc/passwd and /etc/group. But I have no idea of the password to these user and group. I have to run mongod as root user, which is not suggested. Someone suggests to change the owner of mongodb data and log files to mongodb:mongodb. But I have no idea how to run mongod as mongod? Any idea?

4
  • 1
    Well, for a start you can use passwd to change the users password. It might also need a shell in order to login properly (use chsh to change that, if needs be).
    – Philᵀᴹ
    Commented Mar 17, 2015 at 16:02
  • I will have a try to change the password of user mongodb. I just wonder, when mongodb is installed, the user mongodb is created by default. What is the password? I am confused....
    – BAE
    Commented Mar 17, 2015 at 16:35
  • How did you install MongoDB, and how are you starting mongod? If you used the official packaged install for Ubuntu the mongod service should already be set to run with the correct permissions: sudo service mongod start. The sudo in this case is to start the service. The service definition ensures that mongod runs as the mongodb user.
    – Stennie
    Commented Mar 17, 2015 at 18:03
  • I already solved this problem. In my cluster, one config server and one data server in the replication share the same mongod binary. And I did not use the default settings, such as the data path. So, I did not use the sudo service mongod start
    – BAE
    Commented Mar 17, 2015 at 18:08

2 Answers 2

2

Launch Shell as User:

If all else fails, on Ubuntu 14.04 LTS running on AWS, try this...

me@local $ ssh -i aws.pem ubuntu@foo
ubuntu@foo $ sudo -u mongodb bash   # OR whatever shell (zsh)
mongodb@foo $ mongod --dbpath /data/db --fork

OF COURSE, you'll add a much larger set of flags to the command. Note also that this assumes you're authenticated as ubuntu on an AWS EC2 instance. The first portion of each line to the left of the $ is the user@hostname

Invoke Command as User:

YMMV but this should work too...

mongodb@foo $ sudo -u mongodb mongod --dbpath /data/db --fork
2
  • refer to @Phil's comment, I had to do sudo passwd mongodb to change its password before I could sudo -u mongodb bash
    – Howard Lee
    Commented May 6, 2016 at 19:56
  • @Howard Lee That may be because you're invoking sudo as mongodb...?
    – 4Z4T4R
    Commented May 6, 2016 at 20:02
-1

The MongoDB user might have been created to be able to access services. Should using root username not be recommended, may I recommend that you create an admin user on your mongodb database? See how to do that in the MongoDB documentation:

Manage Users and Roles

Since you are able to access the database using the root username, creating an admin account will allow you to modify the mongodb user's password.

I encountered this issue with SQL Server in the past. Modifying the service account was what was required.

1
  • I think op's question is at os level, not database level.
    – Howard Lee
    Commented May 6, 2016 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.