forked from Fascinated/docs
add user and db creation section
This commit is contained in:
parent
192e252c48
commit
f5bce8ae80
@ -152,6 +152,42 @@ security:
|
|||||||
|
|
||||||
7. Save the file and exit the editor. You can do this by pressing `CTRL + X`, then `Y`, then `ENTER`.
|
7. Save the file and exit the editor. You can do this by pressing `CTRL + X`, then `Y`, then `ENTER`.
|
||||||
|
|
||||||
|
## Adding a user / database
|
||||||
|
|
||||||
|
1. Connect to MongoDB, so that we can create a user. Run the following command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mongo -u admin -p --authenticationDatabase admin
|
||||||
|
```
|
||||||
|
|
||||||
|
This will ask you for the password that you set earlier in the Securing MongoDB section.
|
||||||
|
|
||||||
|
2. Switch to the database that you want to add a user to eg: `forum`. Run the following command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
use forum
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Create a user. Make sure to change the `db` to match the database used above. Run the following command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
db.createUser(
|
||||||
|
{
|
||||||
|
user: "forum",
|
||||||
|
pwd: "SET ME", # Generate a random string with: openssl rand -base64 32 | cut -c1-32
|
||||||
|
roles: [ { role: "readWrite", db: "forum" } ]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Exit the mongo shell. Run the following command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
exit
|
||||||
|
```
|
||||||
|
|
||||||
|
You have now created a user for the `forum` database. You can repeat this process for any other databases that you want to create users for.
|
||||||
|
|
||||||
## Optional: Allowing remote connections
|
## Optional: Allowing remote connections
|
||||||
|
|
||||||
1. Open the MongoDB configuration file. Run the following command:
|
1. Open the MongoDB configuration file. Run the following command:
|
||||||
|
Loading…
Reference in New Issue
Block a user