简体   繁体   中英

How do I change EC2 user from ubuntu to mongodb?

Launched Ubuntu 14.04 LTS micro instance on EC2, installed latest MongoDB following their official documentation . When I run sudo mongod --fork --dbpath /somedbpath --logpath /somelogpath followed by mongo ,

I get the warning that it shouldn't be run as a root user. I did notice the installation process created a mongodb user and group and I can see them in the outputs of compgen -u and compgen -g respectively. I shutdown the mongod server and even deleted all files created in the dbpath directory. Now, I'd like to run the daemon as mongodb user, as I've learned it has all the appropriate permissions and ulimits required for optimal performance.

How do I switch from ubuntu to mongodb user, though? I ran sudo passwd mongodb and updated a password. Then I tried su mongodb , entered the password when prompted, but hitting ENTER kept me logged in as ubuntu only. I tried logging out and back in. I manually created the mongodb dir under /home since it wasn't present. I even created a .ssh dir inside that and copied the authorized_keys file from /home/ubuntu/.ssh to see if I can log into the server by ssh -i pemfile mongodb@serveruri but it throws Permission denied (publickey). I'm inclined to following the best practices and would like to be able to launch the mongo daemon as mongodb.

以mangodb用户身份运行命令:

sudo -u mangodb mongod --fork --dbpath /somedbpath --logpath /somelogpath

To solve this, I had to change permissions on the data directory (and it's files) and the log path, like so -

cd /var/log
sudo chown -R mongodb:mongodb mongodb/

cd /
sudo chown -R mongodb:mongodb data/

Then I ran the command similar to 7171u 's answer, ie,

sudo -u mongodb mongod --fork --dbpath /data/ --logpath /var/log/mongodb/mongod.log

And the warning's gone!

Its good that you solved it on your own, but this is still not clear to you.

go through the below mentioned link, to understand the role of each user.

http://www.cyberciti.biz/faq/understanding-etcpasswd-file-format/

mongod user is the one which doesnot have a home directory, that's why not /home, and it also does not have a shell too. check your /etc/passwd file for the mongod user.

mongod:x:993:990:mongod:/var/lib/mongo:/bin/false

this is the default entry for the mongod user in the above mentioned file.

its home directory is /var/lib/mongo and its shell is false.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM