Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. #### User Setup ####
  2.  
  3. #Create group
  4. sudo groupadd kritdev;
  5.  
  6. #Create user
  7. sudo su -c "useradd devadmin -s /bin/bash -m -G kritdev";
  8. usermod -aG sudo devadmin;
  9.  
  10. #Set user temporary password
  11. echo "devadmin:devadmin" | sudo chpasswd
  12.  
  13.  
  14. #Add SSH key
  15. echo "devadmin" | su devadmin -c "mkdir ~/.ssh";
  16. echo "devadmin" | su devadmin -c "chmod 700 ~/.ssh";
  17.  
  18. echo "devadmin" | su devadmin -c 'sudo -S echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCcKK/shbCKUXZ9CfY76c88/O8ehhAErLxjnB7zvL8vBOr2iipTB7Nge+6+dVsZlHhLx+SM9R5eqkPweu0RfUWNU++UIqu2ezv7YhJrMIkNX+HYEvDxY2WQHRJ/d2uu++kXmsnz69r5yGy3SDadldiwRmyXShJwy9ykK6hh5XLPndEZwJiqGKYcMnk33nG123QC/RXXxIrmSfocOGgZOIhlQR4FBsulmjCDE36sa/Pu5FM+oODzlnOjX2HPYMs3VCWK888UPxMvfo5F8YfAMozCyadfu1ZzLKR95Dn4o6ncrbAgLFtA4//3/zOldhMks+fGJdjsjiLI5TtlVR9yc/L9 teodormatis@stefan.todirica-C02QQ2W7FVH8" >> ~/.ssh/authorized_keys';
  19.  
  20. echo "devadmin" | su devadmin -c "chmod 600 ~/.ssh/authorized_keys";
  21.  
  22. #Disable password authentication
  23. sudo sed -i '/PasswordAuthentication yes/c\PasswordAuthentication no' /etc/ssh/sshd_config;
  24.  
  25. #Reload sshd
  26. sudo systemctl reload sshd;
  27.  
  28.  
  29. #### nginx Setup ####
  30. sudo apt-get update;
  31. sudo apt-get install nginx -y;
  32. yes | sudo ufw enable;
  33. sudo ufw allow 'Nginx Full';
  34. sudo ufw allow 'ssh';
  35.  
  36. #### Let's Encrypt Setup ####
  37. yes "" | sudo apt-add-repository ppa:certbot/certbot;
  38.  
  39. sudo apt-get update;
  40. sudo apt-get install python-certbot-nginx -y;
  41.  
  42. sudo sed -i '/server_name _;/c\server_name dev.krit.ro; \
  43. #Proxy Location Block' /etc/nginx/sites-available/default
  44.  
  45. sudo systemctl reload nginx;
  46.  
  47. sudo certbot --non-interactive --agree-tos -m teodormatis@gmail.com --redirect --nginx -d dev.krit.ro
  48. sudo certbot --non-interactive --agree-tos -m teodormatis@gmail.com --redirect --nginx -d dev.api.krit.ro
  49. sudo certbot --non-interactive --agree-tos -m teodormatis@gmail.com --redirect --nginx -d dev.admin.krit.ro
  50.  
  51. sudo systemctl enable certbot.timer;
  52. sudo systemctl start certbot.timer;
  53.  
  54. #### NodeJS Setup ####
  55. curl -sL https://deb.nodesource.com/setup_11.x -o nodesource_setup.sh;
  56. sudo sh nodesource_setup.sh;
  57. sudo apt-get install -y nodejs;
  58. sudo apt-get install -y build-essential;
  59.  
  60. cat >~/hello.js <<EOL
  61. #!/usr/bin/env nodejs
  62. var http = require('http');
  63. http.createServer(function (req, res) {
  64. res.writeHead(200, {'Content-Type': 'text/plain'});
  65. res.end('Hello World\n');
  66. }).listen(8080, 'localhost');
  67. console.log('Server running at http://localhost:8080/');
  68. EOL
  69.  
  70. chmod +x ./hello.js;
  71.  
  72. sudo npm install -g pm2;
  73. pm2 startup systemd;
  74. sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u devadmin --hp /home/devadmin;
  75.  
  76. pm2 start hello.js;
  77.  
  78. #### Mod NGINX server file ####
  79.  
  80. sudo sed -i '49,54 s/^/#/' /etc/nginx/sites-available/default;
  81. sudo sed -i '/#Proxy Location Block/i \
  82. location / {\
  83. proxy_pass http://localhost:8080;\
  84. proxy_http_version 1.1;\
  85. proxy_set_header Upgrade $http_upgrade;\
  86. proxy_set_header Connection 'upgrade';\
  87. proxy_set_header Host $host;\
  88. proxy_cache_bypass $http_upgrade;\
  89. auth_basic "Username and Password Required";\
  90. auth_basic_user_file /etc/nginx/.htpasswd;\
  91. }' /etc/nginx/sites-available/default;
  92.  
  93.  
  94.  
  95. sudo systemctl restart nginx;
  96.  
  97. #### Install MariaDB ####
  98. sudo apt-get install -y mariadb-server mariadb-client;
  99.  
  100. mysql_secure_installation <<EOF
  101. n
  102. somepass
  103. somepass
  104. y
  105. y
  106. y
  107. y
  108. y
  109. EOF
  110.  
  111. sudo systemctl restart mysql.service;
  112.  
  113. #### Password protect nginx reverse proxy ####
  114. sudo apt-get install -y apache2-utils;
  115.  
  116. sudo htpasswd -c /etc/nginx/.htpasswd devadmin devadmin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement