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?
2 Answers
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
-
refer to @Phil's comment, I had to do
sudo passwd mongodb
to change its password before I couldsudo -u mongodb bash
Commented May 6, 2016 at 19:56 -
@Howard Lee That may be because you're invoking
sudo
as mongodb...?– 4Z4T4RCommented May 6, 2016 at 20:02
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:
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.
-
I think op's question is at os level, not database level. Commented May 6, 2016 at 19:53
passwd
to change the users password. It might also need a shell in order to login properly (usechsh
to change that, if needs be).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
. Thesudo
in this case is to start the service. The service definition ensures thatmongod
runs as the mongodb user.