Skip to content

Instantly share code, notes, and snippets.

@asif633
Last active September 6, 2021 02:24
Show Gist options
  • Save asif633/e0f8e47fd7d0e6e09bdf1420aa396aeb to your computer and use it in GitHub Desktop.
Save asif633/e0f8e47fd7d0e6e09bdf1420aa396aeb to your computer and use it in GitHub Desktop.
  1. List keys ls -l ~/.ssh/id_*.pub
  2. Generate key ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_sohoj_rsa -C "pietechlabs2019@gmail.com"
  3. To copy ssh key to server sudo ssh-copy-id -i ~/.ssh/id_sohoj_rsa user@host
  4. Login using sudo ssh -i ~/.ssh/id_sohoj_rsa user@host
  5. Change ssh auth ways sudo nano /etc/ssh/sshd_config
  6. Change those PasswordAuthentication no ChallengeResponseAuthentication no UsePAM no
  7. Restart using sudo systemctl restart ssh
  8. Add new user adduser sammy
  9. Give privileges usermod -aG sudo sammy
  10. Basic firewall setup ufw app list, ufw allow OpenSSH, ufw enable, ufw status
  11. Copy ssh keys from root to sammy rsync --archive --chown=sammy:sammy ~/.ssh /home/sammy
  12. Login using sudo ssh -i ~/.ssh/id_rsa sammy@host
  13. Nginx sudo apt update, sudo apt install nginx
  14. Adjust firewall sudo ufw app list, sudo ufw allow 'Nginx HTTP', sudo ufw status, systemctl status nginx
  15. Some nginx commands sudo systemctl stop nginx, sudo systemctl start nginx, sudo systemctl restart nginx, sudo systemctl reload nginx, sudo systemctl disable nginx, sudo systemctl enable nginx
  16. Nginx conf change sudo nano /etc/nginx/nginx.conf, server_names_hash_bucket_size 64;, sudo nginx -t, sudo systemctl restart nginx
  17. Lets encrypt sudo add-apt-repository ppa:certbot/certbot, sudo apt install python-certbot-nginx
  18. Add domain sudo nano /etc/nginx/sites-available/default
  19. Change server_name example.com www.example.com;, sudo nginx -t, sudo systemctl reload nginx
  20. Allowing https sudo ufw status, sudo ufw allow 'Nginx Full', sudo ufw delete allow 'Nginx HTTP', sudo ufw status
  21. Obtain SSL certificate sudo certbot --nginx -d example.com -d www.example.com
  22. Auto renewal sudo certbot renew --dry-run
  23. Install Nodejs sudo apt-get install curl curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -, sudo apt-get install nodejs, node -v, npm -v
  24. Pm2 install sudo npm install pm2@latest -g, pm2 startup systemd, pm2 start hello.js, pm2 stop hello.js
  25. Pm2 startup pm2 startup systemd, sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u sammy --hp /home/sammy, pm2 save, pm2 list, pm2 info app_name, pm2 monit, pm2 start npm --no-automation --name {app name} -- run {script name}
  26. Server setup sudo nano /etc/nginx/sites-available/default, location / { proxy_pass http://localhost:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; }, sudo nginx -t, sudo systemctl restart nginx
  27. Mongo wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -, echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list , sudo apt-get install -y mongodb-org=4.2.1 mongodb-org-server=4.2.1 mongodb-org-shell=4.2.1 mongodb-org-mongos=4.2.1 mongodb-org-tools=4.2.1
  28. Mongo commands sudo service mongod start, sudo service mongod stop, sudo service mongod restart, mongo, sudo systemctl status mongod
  29. Mongodb systemctl commands sudo systemctl status mongodb, sudo systemctl stop mongodb, sudo systemctl start mongodb, sudo systemctl restart mongodb, sudo systemctl disable mongodb, sudo systemctl enable mongodb
  30. Secure mongo use admin, db.createUser( { user: "AdminOce", pwd: "PWD2018AdminOce", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] } ), sudo nano /etc/mongod.conf, security: authorization: "enabled", sudo systemctl restart mongod, sudo systemctl status mongod, sudo systemctl enable mongod
  31. Check auth mongo, show dbs, mongo -u AdminOce -p --authenticationDatabase admin, show dbs
  32. Needed step for admin user use admin; db.grantRolesToUser('admin', [{ role: 'root', db: 'admin' }])
  33. Check Link https://medium.com/mongoaudit/how-to-enable-authentication-on-mongodb-b9e8a924efac
  34. Node js env set sudo nano ~/.bash_profile, export DATABASE_USERNAME="" export DATABASE_PASSWORD="" export DATABASE_NAME="strapi" export DATABASE_PORT=27017 export DATABASE_HOST="127.0.0.1" , source ~/.bash_profile
  35. Strapi npm i -g strapi@latest
@asif633
Copy link
Author

asif633 commented Jan 6, 2020

mongo --port 27017 --authenticationDatabase "admin" -u "myUserAdmin" -p

@asif633
Copy link
Author

asif633 commented Jan 8, 2021

Kill port sudo kill -9 sudo lsof -t -i:9001

@asif633
Copy link
Author

asif633 commented Sep 6, 2021

sudo apt -y install curl dirmngr apt-transport-https lsb-release ca-certificates
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment