automated terminal push
All checks were successful
learn org at code.softwareshinobi.com/bash.softwareshinobi.com/pipeline/head This commit looks good
All checks were successful
learn org at code.softwareshinobi.com/bash.softwareshinobi.com/pipeline/head This commit looks good
This commit is contained in:
104
docs/.recycle/019-working-with-cloudflare-api-with-bash.md
Normal file
104
docs/.recycle/019-working-with-cloudflare-api-with-bash.md
Normal file
@@ -0,0 +1,104 @@
|
||||
# Working with Cloudflare API with Bash
|
||||
|
||||
I host all of my websites on **DigitalOcean** Droplets and I also use Cloudflare as my CDN provider. One of the benefits of using Cloudflare is that it reduces the overall traffic to your user and also hides your actual server IP address behind their CDN.
|
||||
|
||||
My personal favorite Cloudflare feature is their free DDoS protection. It has saved my servers multiple times from different DDoS attacks. They have a cool API that you could use to enable and disable their DDoS protection easily.
|
||||
|
||||
This chapter is going to be an exercise! I challenge you to go ahead and write a short bash script that would enable and disable the Cloudflare DDoS protection for your server automatically if needed!
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before following this guide here, please set up your Cloudflare account and get your website ready. If you are not sure how to do that you can follow these steps here: [Create a Cloudflare account and add a website](https://support.cloudflare.com/hc/en-us/articles/201720164-Step-2-Create-a-Cloudflare-account-and-add-a-website).
|
||||
|
||||
Once you have your Cloudflare account, make sure to obtain the following information:
|
||||
|
||||
* A Cloudflare account
|
||||
* Cloudflare API key
|
||||
* Cloudflare Zone ID
|
||||
|
||||
Also, Make sure curl is installed on your server:
|
||||
|
||||
```bash
|
||||
curl --version
|
||||
```
|
||||
|
||||
If curl is not installed you need to run the following:
|
||||
|
||||
* For RedHat/CentOs:
|
||||
|
||||
```bash
|
||||
yum install curl
|
||||
```
|
||||
|
||||
* For Debian/Ubuntu
|
||||
|
||||
```bash
|
||||
apt-get install curl
|
||||
```
|
||||
|
||||
## Challenge - Script requirements
|
||||
|
||||
The script needs to monitor the CPU usage on your server and if the CPU usage gets high based on the number vCPU it would enable the Cloudflare DDoS protection automatically via the Cloudflare API.
|
||||
|
||||
The main features of the script should be:
|
||||
|
||||
* Checks the script CPU load on the server
|
||||
* In case of a CPU spike the script triggers an API call to Cloudflare and enables the DDoS protection feature for the specified zone
|
||||
* After the CPU load is back to normal the script would disable the "I'm under attack" option and set it back to normal
|
||||
|
||||
## Example script
|
||||
|
||||
I already have prepared a demo script which you could use as a reference. But I encourage you to try and write the script yourself first and only then take a look at my script!
|
||||
|
||||
To download the script just run the following command:
|
||||
|
||||
```bash
|
||||
wget https://raw.githubusercontent.com/bobbyiliev/cloudflare-ddos-protection/main/protection.sh
|
||||
```
|
||||
|
||||
Open the script with your favorite text editor:
|
||||
|
||||
```bash
|
||||
nano protection.sh
|
||||
```
|
||||
|
||||
And update the following details with your Cloudflare details:
|
||||
|
||||
```bash
|
||||
CF_CONE_ID=YOUR_CF_ZONE_ID
|
||||
CF_EMAIL_ADDRESS=YOUR_CF_EMAIL_ADDRESS
|
||||
CF_API_KEY=YOUR_CF_API_KEY
|
||||
```
|
||||
|
||||
After that make the script executable:
|
||||
|
||||
```bash
|
||||
chmod +x ~/protection.sh
|
||||
```
|
||||
|
||||
Finally, set up 2 Cron jobs to run every 30 seconds. To edit your crontab run:
|
||||
|
||||
```bash
|
||||
crontab -e
|
||||
```
|
||||
|
||||
And add the following content:
|
||||
|
||||
```bash
|
||||
* * * * * /path-to-the-script/cloudflare/protection.sh
|
||||
* * * * * ( sleep 30 ; /path-to-the-script/cloudflare/protection.sh )
|
||||
```
|
||||
|
||||
Note that you need to change the path to the script with the actual path where you've stored the script at.
|
||||
|
||||
## Conclusion
|
||||
|
||||
This is quite straight forward and budget solution, one of the downsides of the script is that if your server gets unresponsive due to an attack, the script might not be triggered at all.
|
||||
|
||||
Of course, a better approach would be to use a monitoring system like Nagios and based on the statistics from the monitoring system then you can trigger the script, but this script challenge could be a good learning experience!
|
||||
|
||||
Here is another great resource on how to use the Discord API and send notifications to your Discord Channel with a Bash script:
|
||||
|
||||
[How To Use Discord Webhooks to Get Notifications for Your Website Status on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-use-discord-webhooks-to-get-notifications-for-your-website-status-on-ubuntu-18-04)
|
||||
|
||||
>{notice} This content was initially posted on [DevDojo](https://devdojo.com/bobbyiliev/bash-script-to-automatically-enable-cloudflare-ddos-protection)
|
||||
95
docs/.recycle/021-how-to-send-emails-with-bash.md
Normal file
95
docs/.recycle/021-how-to-send-emails-with-bash.md
Normal file
@@ -0,0 +1,95 @@
|
||||
# Sending emails with Bash and SSMTP
|
||||
|
||||
SSMTP is a tool that delivers emails from a computer or a server to a configured mail host.
|
||||
|
||||
SSMTP is not an email server itself and does not receive emails or manage a queue.
|
||||
|
||||
One of its primary uses is for forwarding automated email (like system alerts) off your machine and to an external email address.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
You would need the following things in order to be able to complete this tutorial successfully:
|
||||
|
||||
* Access to an Ubuntu 18.04 server as a non-root user with sudo privileges and an active firewall installed on your server. To set these up, please refer to our [Initial Server Setup Guide for Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04)
|
||||
|
||||
* An SMTP server along with SMTP username and password, this would also work with Gmail's SMTP server, or you could set up your own SMTP server by following the steps from this tutorial on [How to Install and Configure Postfix as a Send-Only SMTP Server on Ubuntu 16.04](https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-16-04)
|
||||
|
||||
## Installing SSMTP
|
||||
|
||||
In order to install SSMTP, you’ll need to first update your apt cache with:
|
||||
|
||||
```bash
|
||||
sudo apt update
|
||||
```
|
||||
|
||||
Then run the following command to install SSMTP:
|
||||
|
||||
```bash
|
||||
sudo apt install ssmtp
|
||||
```
|
||||
|
||||
Another thing that you would need to install is `mailutils`, to do that run the following command:
|
||||
|
||||
```bash
|
||||
sudo apt install mailutils
|
||||
```
|
||||
|
||||
## Configuring SSMTP
|
||||
|
||||
Now that you have `ssmtp` installed, in order to configure it to use your SMTP server when sending emails, you need to edit the SSMTP configuration file.
|
||||
|
||||
Using your favourite text editor to open the `/etc/ssmtp/ssmtp.conf` file:
|
||||
|
||||
```bash
|
||||
sudo nano /etc/ssmtp/ssmtp.conf
|
||||
```
|
||||
|
||||
You need to include your SMTP configuration:
|
||||
|
||||
```
|
||||
root=postmaster
|
||||
mailhub=<^>your_smtp_host.com<^>:587
|
||||
hostname=<^>your_hostname<^>
|
||||
AuthUser=<^>your_gmail_username@your_smtp_host.com<^>
|
||||
AuthPass=<^>your_gmail_password<^>
|
||||
FromLineOverride=YES
|
||||
UseSTARTTLS=YES
|
||||
```
|
||||
|
||||
Save the file and exit.
|
||||
|
||||
## Sending emails with SSMTP
|
||||
|
||||
Once your configuration is done, in order to send an email just run the following command:
|
||||
|
||||
```bash
|
||||
echo "<^>Here add your email body<^>" | mail -s "<^>Here specify your email subject<^>" <^>your_recepient_email@yourdomain.com<^>
|
||||
```
|
||||
|
||||
You can run this directly in your terminal or include it in your bash scripts.
|
||||
|
||||
## Sending A File with SSMTP (optional)
|
||||
|
||||
If you need to send files as attachments, you can use `mpack`.
|
||||
|
||||
To install `mpack` run the following command:
|
||||
|
||||
```bash
|
||||
sudo apt install mpack
|
||||
```
|
||||
|
||||
Next, in order to send an email with a file attached, run the following command.
|
||||
|
||||
```bash
|
||||
mpack -s "<^>Your Subject here<^>" your_file.zip <^>your_recepient_email@yourdomain.com<^>
|
||||
```
|
||||
|
||||
The above command would send an email to `<^>your_recepient_email@yourdomain.com<^>` with the `<^>your_file.zip<^>` attached.
|
||||
|
||||
## Conclusion
|
||||
|
||||
SSMTP is a great and reliable way to implement SMTP email functionality directly in bash scripts.
|
||||
|
||||
For more information about SSMTP I would recommend checking the official documentation [here](https://wiki.archlinux.org/index.php/SSMTP).
|
||||
|
||||
>{notice} This content was initially posted on the [DigitalOcean community forum](https://www.digitalocean.com/community/questions/how-to-send-emails-from-a-bash-script-using-ssmtp).
|
||||
@@ -1,82 +0,0 @@
|
||||
# A Linux Learning Playground Situation
|
||||
|
||||

|
||||
|
||||
wanna play with the application in this picture? connect to the server using the instructions below and run the command `hollywood`
|
||||
|
||||
## Introduction:
|
||||
|
||||
Welcome, aspiring Linux ninjas! This tutorial will guide you through accessing Shinobi Academy Linux, a custom-built server designed to provide a safe and engaging environment for you to learn and experiment with Linux. Brought to you by Softwareshinobi ([https://softwareshinobi.digital/](https://softwareshinobi.digital/)), this server is your gateway to the exciting world of open-source exploration.
|
||||
|
||||
## What You'll Learn:
|
||||
|
||||
* Connecting to a Linux server (using SSH)
|
||||
* Basic Linux commands (navigation, listing files, etc.)
|
||||
* Exploring pre-installed tools like cmatrix and hollywood
|
||||
|
||||
## What You'll Need:
|
||||
|
||||
* A computer with internet access
|
||||
* An SSH client (built-in on most Linux and macOS systems, downloadable for Windows)
|
||||
|
||||
## About Shinobi Academy:
|
||||
|
||||
Shinobi Academy, the online learning platform brought to you by Softwareshinobi!
|
||||
|
||||
Designed to empower aspiring tech enthusiasts, Shinobi Academy offers a comprehensive range of courses and resources to equip you with the skills you need to excel in the ever-evolving world of technology.
|
||||
|
||||
## Connecting to Shinobi Academy Linux:
|
||||
|
||||
1. Open your SSH client.
|
||||
2. Enter the following command (including the port number):
|
||||
|
||||
```
|
||||
ssh -p 2222 shinobi@linux.softwareshinobi.digital
|
||||
```
|
||||
|
||||
3. When prompted, enter the password "shinobi".
|
||||
|
||||
```
|
||||
username / shinobi
|
||||
```
|
||||
|
||||
```
|
||||
password / shinobi
|
||||
```
|
||||
|
||||
**Congratulations!** You're now connected to Shinobi Academy Linux.
|
||||
|
||||
## Exploring the Server:
|
||||
|
||||
Once connected, you can use basic Linux commands to navigate the system and explore its features. Here are a few examples:
|
||||
|
||||
* **`ls`:** Lists files and directories in the current directory.
|
||||
* **`cd`:** Changes directory. For example, `cd Desktop` will move you to the Desktop directory (if it exists).
|
||||
* **`pwd`:** Shows the current working directory.
|
||||
* **`man` followed by a command name:** Provides detailed information on a specific command (e.g., `man ls`).
|
||||
|
||||
## Pre-installed Goodies:
|
||||
|
||||
Shinobi Academy Linux comes pre-installed with some interesting tools to enhance your learning experience:
|
||||
|
||||
* **`cmatrix`:** Simulates the iconic falling code effect from the movie "The Matrix".
|
||||
* **`hollywood`:** Creates a variety of dynamic text effects on your terminal.
|
||||
|
||||
**Experimenting with these tools is a great way to explore the possibilities of Linux.**
|
||||
|
||||
## Conclusion:
|
||||
|
||||
By following these steps, you've successfully connected to Shinobi Academy Linux and begun your journey into the world of Linux. Use this platform to explore, experiment, and build your Linux skills!
|
||||
|
||||
A big thanks to Gemini for putting together these awesome docs!
|
||||
|
||||
## Master Linux Like a Pro: 1-on-1 Tutoring:
|
||||
|
||||
**Tired of fumbling in the terminal?** Imagine wielding Linux commands with ease, managing servers like a corporate ninja – just like my government and corporate gigs.
|
||||
|
||||
**1-on-1 tutoring unlocks your potential:**
|
||||
|
||||
* **Terminal mastery:** Conquer the command line and automate tasks like a pro.
|
||||
* **Become a command jedi:** Craft commands with lightning speed, streamlining your workflow.
|
||||
|
||||
**Ready to transform your skills?** [Learn More!](tutor.softwareshinobi.digital/linux)
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 10 KiB |
Binary file not shown.
Reference in New Issue
Block a user