How to run MongoDB as a non root user in Linux?
You mention that you used the rpm installer for installing MongoDB on the Amazon Linux AMI. When you do this, the mongod user is created on the system and all of the appropriate files are created and owned by the mongod user. When starting MongoDB installed by the rpm, the command must either be run by root or run using sudo. This is because the init script must execute a change user command so the mongod process can be forked as a child of the mongod user.

Failure to use root or sudo to start the service results in the errors you quoted above.

/etc/init.d/mongod: line 58: ulimit: open files: cannot modify limit: Operation not permitted
/etc/init.d/mongod: line 60: ulimit: max user processes: cannot modify limit: Operation not permitted
Starting mongod: runuser: may not be used by non-root users


So, in order to run as a service, you must use sudo or root. There is no simple way around this except granting the mongod user a shell, assigning it a password, logging in as that user, then running the service. This will still result in errors attempting to modify the ulimits and is generally not recommended.

To start MongoDB without running it as a service, since you used the rpm, the mongod binary should be in your path, so the following should work

mongod --dbpath /path/to/data --logpath /path/to/mongod.log --fork


Note that doing this will run it as the currently logged in user, that means all of the data files as well as mongod.log must be writable by that user. Ideally, these files should be owned by that user.