Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Mongo and chown /data/db yields "illegal user name" error

I'm installing MongoDB for a Node / Express tutorial and upon creation of the /data/db folder and the following command:

sudo chown 'id -u' /data/db

I received the following error:

chown: id -u: illegal user name
like image 868
phillipmaddox Avatar asked Oct 23 '13 16:10

phillipmaddox


2 Answers

You can look for the current username and then try setting the permissions.

$ whoami
username
$ sudo chown username /data/db

Hope that helps.

like image 137
xoail Avatar answered Oct 11 '22 20:10

xoail


The reason this failed is because your syntax was wrong and you misinterpreted the quoting from the source where you found it. You need to use a quote like this to execute the id command:

chown `id -u` /data/db

See the difference?

Also you seem to have arrived here at a misconception of how to install mongodb, and possibly have gone for a build from a tarball. The /data/db path is not required, it's just the default location.

But you generally can get a package install for your system:

http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/

These will typically lay out an installation with a directory structure appropriate to your system conventions, and create a mongodb user under which the mongod process runs, with all appropriate permissions. They typically have a config file that you can set options in as well. The process is also typically set-up as a "service", so you don't need to manually invoke it each time you want to use.

You can specify the --dbpath option on startup or within a config file section, which of course is loaded by the --config option.

At any rate you should generally run mongod processes as their own user (not root) using the options and permissions on data and logging directories set for that user.

like image 4
Neil Lunn Avatar answered Oct 11 '22 21:10

Neil Lunn