-
-
Save Shahzad6077/191a4eceb832de3fcab872cf38d4f2b8 to your computer and use it in GitHub Desktop.
Revisions
-
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -287,7 +287,7 @@ sudo certbot renew --dry-run sudo apt-get install -y figlet ``` 2. Type ```figlet``` and type in your custom welcome message 3. Copy the text and go into motd ```sudo nano /etc/motd``` 4. Paste text and save 5. Restart terminal to see your new welcome message -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 14 additions and 17 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -202,7 +202,7 @@ ssh-add ~/.ssh/id_ed25519 cd .ssh cat id_ed25519.pub ``` > copy the output including email 2. Go to GitHub > Settings > SSH and GPG Keys 3. Click "New SSH Key" 4. Paste the SSH key in the input box @@ -227,22 +227,9 @@ cd /var/www ``` sudo git clone [email protected]:user/your-repository.git ``` 4. if this gives permission error clone from HTTPS instead 5. type ```ls``` and boom your project is there 6. ```cd``` into your projext and type ```npm install``` to install all packages that your project contains ## Install PM2 1. Install pm2 globally: @@ -294,4 +281,14 @@ This command gives you a certificate & Certbot edits your Nginx configuration au ``` sudo certbot renew --dry-run ``` # BONUS: Change Welcome Message 1. Install figlet ``` sudo apt-get install -y figlet ``` 2. Type ```figlet``` and type in your custom welcome message 3. Copy the text and go into motd ```nano /etc/motd``` 4. Paste text and save 5. Restart terminal to see your new welcome message # Congratulations you are done! Happy Hacking :D -
carlssonk revised this gist
Oct 23, 2021 . No changes.There are no files selected for viewing
-
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -122,6 +122,10 @@ ufw allow https ufw allow XXXXX # the port you choosed earlier ``` To check your firewall status: ```ufw status``` 2. Reboot session and connect again to make sure everything is working: ``` reboot ``` ## Install Node.js & Npm 1. Install latest version of nodejs: -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 35 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,7 @@ ## Prerequisites * Download [PuTTY & PuTTYgen](https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html) * Download [WinSCP](https://winscp.net/eng/download.php) * Have your application on a GitHub repo. ## Create Droplet & Generate SSH Key 1. Create New Project/Create New Droplet @@ -118,6 +119,7 @@ ufw enable ufw allow ssh ufw allow http ufw allow https ufw allow XXXXX # the port you choosed earlier ``` To check your firewall status: ```ufw status``` @@ -174,9 +176,7 @@ systemctl start mongodb systemctl restart mongodb ``` ## Generate SSH key & add it to GitHub ### Generating SSH key for github 1. Create ssh key for github: ``` @@ -186,16 +186,45 @@ ssh-keygen -t ed25519 -C "[email protected]" ### Adding your SSH key to the ssh-agent 1. Ensure the ssh-agent is running. ``` eval "$(ssh-agent -s)" ``` 2. Add your SSH private key to the ssh-agent. ``` ssh-add ~/.ssh/id_ed25519 ``` ### Adding your SSH key to GitHub 1. copy SSH key that you just created: ``` cd .ssh cat id_ed25519.pub ``` > copy the output except for the email 2. Go to GitHub > Settings > SSH and GPG Keys 3. Click "New SSH Key" 4. Paste the SSH key in the input box > IF YOU ARE STUCK generating SSH key and adding it to GitHub. Follow these steps: > https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent > > https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account ## Clone App from github > If your project is not on github, upload it to github so we can clone it to your droplet 1. Make sure you are standing on root: ``` cd ``` 2. Go into /var/www ``` cd /var/www ``` > You can remove default html folder if you want "sudo rm -fr html" 3. Clone app from GitHub ``` sudo git clone [email protected]:user/your-repository.git ``` ### Clone app from GitHub 1. Create ssh key for github: ``` ssh-keygen -t rsa -C '[email protected]' -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 8 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -184,10 +184,16 @@ ssh-keygen -t ed25519 -C "[email protected]" ``` 2. When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location. ### Adding your SSH key to the ssh-agent 1. Ensure the ssh-agent is running. ``` # start the ssh-agent in the background $ eval "$(ssh-agent -s)" > Agent pid XXXXX ``` > IF YOU ARE STUCK generating SSH key and adding it to GitHub. Follow these steps: > https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent > > https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account 1. Create ssh key for github: -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 15 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -166,7 +166,7 @@ location / { sudo apt install -y mongodb ``` After install mongodb should be running To check status of db: ```systemctl status mongodb``` Commands to start, stop and restart the database ``` systemctl stop mongodb @@ -176,6 +176,20 @@ systemctl restart mongodb ## Clone App from github > If your project is not on github, upload it to github so we can clone it to your droplet ### Generating SSH key for github 1. Create ssh key for github: ``` ssh-keygen -t ed25519 -C "[email protected]" ``` 2. When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location. ### Adding your SSH key to the ssh-agent 1. > If you get stuck generating SSH key and adding it to GitHub. Follow these steps: > https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent > https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account 1. Create ssh key for github: ``` ssh-keygen -t rsa -C '[email protected]' -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -162,6 +162,17 @@ location / { 7. Now restart the service ```sudo service nginx restart``` ## Install MongoDB ``` sudo apt install -y mongodb ``` After install mongodb should be running To check status of db: ```systemctl status mongodb``` Commands to start, stop and restart the database ``` systemctl stop mongodb systemctl start mongodb systemctl restart mongodb ``` ## Clone App from github > If your project is not on github, upload it to github so we can clone it to your droplet -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -98,8 +98,8 @@ sudo nano /etc/ssh/sshd_config # If the row start with a '#' you should remove it # Ex. Port 25565 ``` Save file: Ctrl+X & Y 7. Reboot session: ``` reboot -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -99,7 +99,7 @@ sudo nano /etc/ssh/sshd_config # Ex. Port 25565 ``` Save file: Ctrl+X & Y 7. Reboot session: ``` reboot -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 15 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -79,7 +79,7 @@ sudo apt update ``` ## Disable Root & Password Login AND Change SSH-port ### Disable Root & Password Login 1. Go into ssh config file: ``` sudo nano /etc/ssh/sshd_config @@ -89,7 +89,7 @@ sudo nano /etc/ssh/sshd_config 4. Search for PasswordAuthentication: **Ctrl+W** and type "PasswordAuthentication" 5. Set PasswordAuthentication to "no" ### Change SSH-port > A lot of attacks on web servers occur by scripts trying to get into the default port for SSH, port 22. Therefore, we change this, feel free to take a five-digit port (difficulty guessing), but not higher than 65535. (Also: Note the number should not start with 0.) 6. Find the row Port 22 and change it to another port, eg. XXXXX @@ -99,7 +99,7 @@ sudo nano /etc/ssh/sshd_config # Ex. Port 25565 ``` Exit with Ctrl+X & Y 7. Reboot session: ``` reboot @@ -133,16 +133,6 @@ sudo apt-get install nodejs ``` You can make sure they are installed: ```"npm -v" and "node -v"``` ## NGINX 1. Install nginx: ``` @@ -171,6 +161,8 @@ location / { 6. Check so nginx is configured properly ```sudo nginx -t```. It should say something like the test is successful 7. Now restart the service ```sudo service nginx restart``` ## Install MongoDB ## Clone App from github > If your project is not on github, upload it to github so we can clone it to your droplet 1. Create ssh key for github: @@ -188,6 +180,16 @@ git clone [email protected]:user/your/repository 8. type ```ls``` and boom your project is there 9. ```cd``` into your projext and type ```npm install``` to install all packages that your project contains ## Install PM2 1. Install pm2 globally: ``` sudo npm install -g pm2 ``` 2. Start server: ```pm2 start index.js``` or ```pm2 start npm -- start``` 3. App should now be running on the droplets ip adress:</br> > ex.165.227.216.5:8080 ## Add domain 1. First buy your domain through preferred service: ex, namecheap, godaddy. 2. Then in DigitalOcean go to the networking tab and add your domain -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 8 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -72,6 +72,12 @@ sudo service ssh restart 7. Exit terminal and login as new user. Load config, click **Data** and change root to your [username]. ## Ensure everything is up to date Update packages ``` sudo apt update ``` ## Disable Root & Password Login AND Change SSH-port #### Disable Root & Password Login 1. Go into ssh config file: @@ -115,12 +121,8 @@ ufw allow https ``` To check your firewall status: ```ufw status``` ## Install Node.js & Npm 1. Install latest version of nodejs: > Note: this is version 14 we are installing, check nodejs homepage and see if there is a newer version, pick the one that says recommended for most users, and change "14" in this command to the new version ``` curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -86,7 +86,7 @@ sudo nano /etc/ssh/sshd_config #### Change SSH-port > A lot of attacks on web servers occur by scripts trying to get into the default port for SSH, port 22. Therefore, we change this, feel free to take a five-digit port (difficulty guessing), but not higher than 65535. (Also: Note the number should not start with 0.) 6. Find the row Port 22 and change it to another port, eg. XXXXX **Important: Make sure to remember the Port you changed to** ``` # If the row start with a '#' you should remove it -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -72,7 +72,7 @@ sudo service ssh restart 7. Exit terminal and login as new user. Load config, click **Data** and change root to your [username]. ## Disable Root & Password Login AND Change SSH-port #### Disable Root & Password Login 1. Go into ssh config file: ``` @@ -87,7 +87,6 @@ sudo nano /etc/ssh/sshd_config > A lot of attacks on web servers occur by scripts trying to get into the default port for SSH, port 22. Therefore, we change this, feel free to take a five-digit port (difficulty guessing), but not higher than 65535. (Also: Note the number should not start with 0.) 6. Find the row Port 22 and change it to another port, eg. XXXXX **Important: Make sure to remember the Port you changed to** ``` # If the row start with a '#' you should remove it @@ -101,7 +100,7 @@ reboot ``` 8. Close terminal and open PuTTY 9. Now in the port input, type in your new port > Note that if you try to open the terminal with another port like 22 you will get a "connection refused error". 10. Save and open terminal ## Enable Firewall -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -87,6 +87,7 @@ sudo nano /etc/ssh/sshd_config > A lot of attacks on web servers occur by scripts trying to get into the default port for SSH, port 22. Therefore, we change this, feel free to take a five-digit port (difficulty guessing), but not higher than 65535. (Also: Note the number should not start with 0.) 6. Find the row Port 22 and change it to another port, eg. XXXXX **Important: Make sure to remember the Port you changed to** ``` # If the row start with a '#' you should remove it -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 7 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -86,33 +86,22 @@ sudo nano /etc/ssh/sshd_config #### Change SSH-port > A lot of attacks on web servers occur by scripts trying to get into the default port for SSH, port 22. Therefore, we change this, feel free to take a five-digit port (difficulty guessing), but not higher than 65535. (Also: Note the number should not start with 0.) 6. Find the row Port 22 and change it to another port, eg. XXXXX **Important: Make sure to remember the Port you changed to** ``` # If the row start with a '#' you should remove it # Ex. Port 25565 ``` Exit with Ctrl+X and Save 7. Reboot session: ``` reboot ``` 8. Close terminal and open PuTTY 9. Now in the port input, type in your new port > Note that if you try to open the terminal with another port like 22 you will get a "connection refused error". 10. Save and open terminal ## Enable Firewall > Note: to enable firewall you need to be on the root user. Type ```sudo -i``` or ```sudo -s``` to switch to the root user</br> -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 4 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -86,17 +86,16 @@ sudo nano /etc/ssh/sshd_config #### Change SSH-port > A lot of attacks on web servers occur by scripts trying to get into the default port for SSH, port 22. Therefore, we change this, feel free to take a five-digit port (difficulty guessing), but not higher than 65535. (Also: Note the number should not start with 0.) ``` # Find the row Port 22 and change it to another port, eg. XXXXX # If the row start with a '#' you should remove it # Ex. Port 25565 ``` Exit with Ctrl+X and Save Reboot session ``` reboot ``` ## Change SSH-port AND -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 19 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -72,24 +72,39 @@ sudo service ssh restart 7. Exit terminal and login as new user. Load config, click **Data** and change root to your [username]. ## Disable Root & Password Login & Change SSH-port #### Disable Root & Password Login 1. Go into ssh config file: ``` sudo nano /etc/ssh/sshd_config ``` 2. Search for PermitRootLogin: **Ctrl+W** and type "PermitRootLogin" 3. Set PermitRootLogin to "no" 4. Search for PasswordAuthentication: **Ctrl+W** and type "PasswordAuthentication" 5. Set PasswordAuthentication to "no" #### Change SSH-port > A lot of attacks on web servers occur by scripts trying to get into the default port for SSH, port 22. Therefore, we change this, feel free to take a five-digit port (difficulty guessing), but not higher than 65535. (Also: Note the number should not start with 0.) ``` # Find the row Port 22 and change it to another port, eg. XXXXX # If the row start with a '#' you should remove it # Example below Port 25565 ``` Reload sshd: ``` sudo systemctl reload sshd ``` ## Change SSH-port AND > A lot of attacks on web servers occur by scripts trying to get into the default port for SSH, port 22. Therefore, we change this, feel free to take a five-digit port (difficulty guessing), but not higher than 65535. (Also: Note the number should not start with 0.) 1. Nano into sshd_config ``` ``` ``` nano /etc/ssh/sshd_config # hitta raden Port 22 och ändra till en annan port, t.ex. XXXXX -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 12 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -88,6 +88,18 @@ sudo nano /etc/ssh/sshd_config sudo systemctl reload sshd ``` ## Change SSH-port > A lot of attacks on web servers occur by scripts trying to get into the default port for SSH, port 22. Therefore, we change this, feel free to take a five-digit port (difficulty guessing), but not higher than 65535. (Also: Note the number should not start with 0.) ``` nano /etc/ssh/sshd_config # hitta raden Port 22 och ändra till en annan port, t.ex. XXXXX # om raden Port 22 börjar med #-tecken så ta bort detta tecken # spara (ctrl + o), stäng (ctrl + x) reboot # vänta några sekunder och logga in via SSH: root@serverip -p XXXXX ``` ## Enable Firewall > Note: to enable firewall you need to be on the root user. Type ```sudo -i``` or ```sudo -s``` to switch to the root user</br> > Type ```su - [username]``` to switch back to your user after enabling firewall -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 12 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -88,6 +88,18 @@ sudo nano /etc/ssh/sshd_config sudo systemctl reload sshd ``` ## Enable Firewall > Note: to enable firewall you need to be on the root user. Type ```sudo -i``` or ```sudo -s``` to switch to the root user</br> > Type ```su - [username]``` to switch back to your user after enabling firewall 1. Enable firewall, ssh, http & https: ``` ufw enable ufw allow ssh ufw allow http ufw allow https ``` To check your firewall status: ```ufw status``` ## Install packages 1. Update packages: ``` @@ -104,18 +116,6 @@ sudo apt-get install nodejs ``` You can make sure they are installed: ```"npm -v" and "node -v"``` ## Install PM2 1. Install pm2 globally: ``` -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 26 additions and 26 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -104,22 +104,17 @@ sudo apt-get install nodejs ``` You can make sure they are installed: ```"npm -v" and "node -v"``` ## Enable Firewall > Note: to enable firewall you need to be on the root user. Type ```sudo -i``` or ```sudo -s``` to switch to the root user</br> > Type ```su - [username]``` to switch back to your user after enabling firewall 1. Enable firewall, ssh, http & https: ``` ufw enable ufw allow ssh ufw allow http ufw allow https ``` To check your firewall status: ```ufw status``` ## Install PM2 1. Install pm2 globally: @@ -131,18 +126,6 @@ sudo npm install -g pm2 3. App should now be running on the droplets ip adress:</br> > ex.165.227.216.5:8080 ## NGINX 1. Install nginx: ``` @@ -171,6 +154,23 @@ location / { 6. Check so nginx is configured properly ```sudo nginx -t```. It should say something like the test is successful 7. Now restart the service ```sudo service nginx restart``` ## Clone App from github > If your project is not on github, upload it to github so we can clone it to your droplet 1. Create ssh key for github: ``` ssh-keygen -t rsa -C '[email protected]' ``` 2. Open **WinSCP** and choose import droplet & login 3. In /home/[username]/ add .ssh because its hidden by default, so go into the /home/[username]/.ssh directory 4. Drag over the **id_rsa.pub** file to the **document** folder and open the file 5. Copy the key and add it to ssh in GitHub 6. Now in your droplets terminal clone the project from github: ``` git clone [email protected]:user/your/repository ``` 8. type ```ls``` and boom your project is there 9. ```cd``` into your projext and type ```npm install``` to install all packages that your project contains ## Add domain 1. First buy your domain through preferred service: ex, namecheap, godaddy. 2. Then in DigitalOcean go to the networking tab and add your domain -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -102,7 +102,7 @@ curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - ``` sudo apt-get install nodejs ``` You can make sure they are installed: ```"npm -v" and "node -v"``` ## Clone App from github > If your project is not on github, upload it to github so we can clone it to your droplet -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,7 @@ ## Configure PuTTY 1. Open PuTTY 2. Add your droplets IP Adress to **'Host Name (or IP Adress)'** 3. In Connection -> Data, set username to "root" 4. In SSH -> Auth, load your **privatekey.ppk** that you created from last step 5. Set a session name and SAVE -
carlssonk revised this gist
Oct 23, 2021 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Deploy Node.js Application to DigitalOcean > This step by step tutorial will show you how to set up a Node.js server with MongoDB to DigitalOcean using PM2, NGINX as reverse proxy and a SSL from LetsEncrypt. We will also add a custom domain name. ## Prerequisites * Download [PuTTY & PuTTYgen](https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html) @@ -10,8 +10,8 @@ 1. Create New Project/Create New Droplet 2. Choose Ubuntu, Choose your desired plan & country 3. Click on New SSH Key 4. Open PuTTyGen and generate a new RSA Key 5. Copy the key in the input field and add it to your droplet, **Add SSH Key** 7. **IMPORTANT** Be sure to save the public key as **.txt** and your private key as **.ppk** on your computer, you will need these later 8. **Create Droplet** -
carlssonk revised this gist
Mar 4, 2021 . 1 changed file with 27 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -185,3 +185,30 @@ location / { * ns3.digitalocean.com 8. Click save > Note: it can take up to a couple of hours for the domain name to take effect, but usually it takes 5-15 minutes ## Add SSL with LetsEncrypt (enables HTTPS) > Note: certbot is deprecated. So its best to install snapshot of certbot so it stays up to date. We will install certbot by following [these instructions](https://certbot.eff.org/lets-encrypt/ubuntubionic-nginx) > This installation is for web server on Nginx with Ubuntu 20.04 1. Make sure everything is up to date ```sudo apt-get update``` 2. You should already have snapd installed, so make sure its up to date with this command: ``` sudo snap install core; sudo snap refresh core ``` 3. Before installing certbot, remove it so we can install certbot snap, we dont want them to collide: ``` sudo apt-get remove certbot ``` 4. Now install certbot: ``` sudo snap install --classic certbot ``` 5. Prepare cerbot with your domains, it should look like this: ``` sudo certbot --nginx -d mywebsite.com -d www.mywebsite.com ``` This command gives you a certificate & Certbot edits your Nginx configuration automatically to serve it, turning on HTTPS access in a single step 6. Almost done, but this certificate will expire in 90 days, to renew it after every 90 days type this command: ``` sudo certbot renew --dry-run ``` # Congratulations you are done! Happy Hacking :D -
carlssonk revised this gist
Mar 4, 2021 . 1 changed file with 53 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -94,7 +94,7 @@ sudo systemctl reload sshd sudo apt update ``` 2. Install latest version of nodejs: > Note: this is version 14 we are installing, check nodejs homepage and see if there is a newer version, pick the one that says recommended for most users, and change "14" in this command to the new version ``` curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - ``` @@ -132,7 +132,56 @@ sudo npm install -g pm2 > ex.165.227.216.5:8080 ## Enable Firewall > Note: to enable firewall you need to be on the root user. Type ```sudo -i``` or ```sudo -s``` to switch to the root user</br> > Type ```su - [username]``` to switch back to your user after enabling firewall 1. Enable firewall, ssh, http & https: ``` ufw enable ufw allow ssh ufw allow http ufw allow https ``` To check your firewall status: ```ufw status``` ## NGINX 1. Install nginx: ``` sudo apt install nginx ``` 2. Go into default folder: ``` sudo nano /etc/nginx/sites-available/default ``` 3. Remove everything inside the location brackets and add proxies: ``` location / { proxy_pass http://localhost:8080; #whatever port your app runs on. 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; } ``` > Note: if localhost does not work use ip address from your droplet. 4. Above the location we have **server_name_;**. Set the server name to your domain name if you want to use a domain name for this app. It should look like this ```server_name mywebsite.com www.mywebsite.com``` 5. Exit and save: Ctrl+X & Y 6. Check so nginx is configured properly ```sudo nginx -t```. It should say something like the test is successful 7. Now restart the service ```sudo service nginx restart``` ## Add domain 1. First buy your domain through preferred service: ex, namecheap, godaddy. 2. Then in DigitalOcean go to the networking tab and add your domain 3. Where it says **HOSTNAME** you will add a "@" and at **WILL DIRECT TO** you want to put your droplet 4. Click on **Create Record**. > The record you are creating is **"A"** 5. Create a Record for the **www** version, so do the same but replace "@" with "www" 6. Go to your domain name provider. Click on your domain or click manage domain and go to nameservers and click **Custom DNS** 7. Add 3 nameservers. It should look like this: * ns1.digitalocean.com * ns2.digitalocean.com * ns3.digitalocean.com 8. Click save > Note: it can take up to a couple of hours for the domain name to take effect, but usually it takes 5-15 minutes -
carlssonk revised this gist
Mar 4, 2021 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -129,7 +129,10 @@ sudo npm install -g pm2 2. Start server: ```pm2 start index.js``` or ```pm2 start npm -- start``` 3. App should now be running on the droplets ip adress:</br> > ex.165.227.216.5:8080 ## Enable Firewall > NOTE: to enable firewall you need to be on the root user. Type ```sudo -i``` or ```sudo -s``` to switch to the root user</br> > Type ```su - [username]``` to switch back to your user after enabling firewall -
carlssonk revised this gist
Mar 4, 2021 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -128,7 +128,8 @@ sudo npm install -g pm2 ``` 2. Start server: ```pm2 start index.js``` or ```pm2 start npm -- start``` 3. App should now be running on the droplets ip adress:</br> > ex.165.227.216.5:8080 -
carlssonk revised this gist
Mar 4, 2021 . 1 changed file with 29 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Deploy Node.js Application to DigitalOcean > This step by step tutorial will show you how to set up a node.js server to DigitalOcean using PM2, NGINX as reverse proxy and a SSL from LetsEncrypt. We will also add a custom domain name. ## Prerequisites * Download [PuTTY & PuTTYgen](https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html) @@ -83,13 +83,13 @@ sudo nano /etc/ssh/sshd_config 4. Search for PasswordAuthentication: **Ctrl+W** and type "PasswordAuthentication" 5. Set PasswordAuthentication to "no" 6. Reload sshd: ``` sudo systemctl reload sshd ``` ## Install packages 1. Update packages: ``` sudo apt update ``` @@ -98,12 +98,37 @@ sudo apt update ``` curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - ``` 3. Install nodejs & npm: ``` sudo apt-get install nodejs ``` You can make sure they are installed: ```npm --version” & “node --version``` ## Clone App from github > If your project is not on github, upload it to github so we can clone it to your droplet 1. Create ssh key for github: ``` ssh-keygen -t rsa -C '[email protected]' ``` 2. Open **WinSCP** and choose import droplet & login 3. In /home/[username]/ add .ssh because its hidden by default, so go into the /home/[username]/.ssh directory 4. Drag over the **id_rsa.pub** file to the **document** folder and open the file 5. Copy the key and add it to ssh in GitHub 6. Now in your droplets terminal clone the project from github: ``` git clone [email protected]:user/your/repository ``` 8. type ```ls``` and boom your project is there 9. ```cd``` into your projext and type ```npm install``` to install all packages that your project contains ## Install PM2 1. Install pm2 globally: ``` sudo npm install -g pm2 ``` 2. Start server: ```pm2 start index.js``` or ```pm2 start npm -- start``` 3. App should now be running on the droplets ip adress: > ex.165.227.216.5:8080 -
carlssonk revised this gist
Mar 4, 2021 . 1 changed file with 10 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,15 +24,15 @@ ## Create New User 1. Login to your server, click **yes** if first time connecting to server 2. Add user and assign him to the sudo group: ``` adduser [username] usermod -aG sudo [username] ``` You can check to make sure that user was added in sudo group ``id [username]`` 3. Login as that user:</br> ``` sudo su - [username] @@ -43,46 +43,46 @@ sudo su - [username] ``` mkdir ~/.ssh ``` 2. Change permission: ``` chmod 700 ~/.ssh ``` 3. Create and go into new file: ``` nano ~/.ssh/authorized_keys ``` 4. Copy ssh key from **publickey.txt** (exclude "Comment: rsa-key-date") Inside **authorized_keys** on the first line type: "ssh-rsa" space and add your key, also make everything in one line. > It should look something like this now: “ssh-rsa AAAABaxASDVAV17547DFDVGDVG...”</br> Save file: Ctrl+X & Y 5. Set permission for that file: ``` chmod 600 ~/.ssh/authorized_keys ``` 6. Restart service: ``` sudo service ssh restart ``` 7. Exit terminal and login as new user. Load config, click **Data** and change root to your [username]. ## Disable Root & Password Login 1. Go into ssh config file: ``` sudo nano /etc/ssh/sshd_config ``` 2. Search for PermitRootLogin: **Ctrl+W** and type "PermitRootLogin" 3. Set PermitRootLogin to "no" 4. Search for PasswordAuthentication: **Ctrl+W** and type "PasswordAuthentication" 5. Set PasswordAuthentication to "no" 6. Reload sshd ``` sudo systemctl reload sshd
NewerOlder