Saturday, July 7, 2018

[MEMO] Setup local mongod (unsecured)

1. Download mongod (version >= 3.4, so it supports Decimal128)

2. Do not start mongod with --auth, setup a script and run the daemon just like this:
#!/bin/sh
./mongod \--dbpath /Users/tyliu2/mongodb-osx-x86_64-3.6.4/data/db \--logpath /Users/tyliu2/mongodb-osx-x86_64-3.6.4/logs/mongod.log \--pidfilepath /Users/tyliu2/mongodb-osx-x86_64-3.6.4/logs/mongod.pid \--port 27017
3. Start mongod as above

4. Choose and download your favourite mongo db client (I chose Robo 3T)

5. Login with direct connection

6. Setup username and password for admin
use admin
db.createUser({
    user: "admin",
    pwd: "XXXXXXXX",
    roles: [
        { role: "root", db: "admin" }
    ], 
              passwordDigestor: "server" //if version 4.0 else set it false
})
**!! Please note that in MongoDB ver4, you need to specify passwordDigestor

7. Add "--auth" to the mongod startup script
#!/bin/sh
./mongod \        --auth \        --dbpath /Users/tyliu2/mongodb-osx-x86_64-3.6.4/data/db \        --logpath /Users/tyliu2/mongodb-osx-x86_64-3.6.4/logs/mongod.log \        --pidfilepath /Users/tyliu2/mongodb-osx-x86_64-3.6.4/logs/mongod.pid \        --port 27017
8. Stop and restart mongod with the above script

9. Login with user "admin" and its password

10. Create a new user that uses a new db for your application
use test
db.createUser({
    user: "test",
    pwd: "XXXXXXXX",
    roles: [
        { role: "readWrite", db: "test" }
    ]
})

[MEMO] The steps to run your own secured git repository

1. Create user "git"
adduser git

2. Plant public key to /home/git/.ssh/authorized_keys
ssh-keygen -t rsa

3. Create bare repository
cd /home/git
mkdir git-test.git
cd git-test.git
git init --bare

4. Download plink.exe and pagent.exe
- Run pagent
- Add private key to pagent (click the small tray icon)

Set GIT_SSH env var in local
GIT_SSH={your path to plink.exe}

Prepare client repository
mkdir git-test
git init
git add .
git commit -m "initial commit"
git remote add origin ssh://git@14.199.45.48/home/git/git-test.git
git push origin master