<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: karthick-dkk</title>
    <description>The latest articles on DEV Community by karthick-dkk (@karthickdkk).</description>
    <link>https://dev.to/karthickdkk</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1166934%2Feca52f04-fa55-49b3-a85e-5d898dc2314c.jpeg</url>
      <title>DEV Community: karthick-dkk</title>
      <link>https://dev.to/karthickdkk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/karthickdkk"/>
    <language>en</language>
    <item>
      <title>Dangerous Linux Configurations You Must Avoid for Secure Systems (Deep Dive)</title>
      <dc:creator>karthick-dkk</dc:creator>
      <pubDate>Mon, 28 Oct 2024 10:18:09 +0000</pubDate>
      <link>https://dev.to/karthickdkk/dangerous-linux-configurations-you-must-avoid-for-secure-systems-deep-dive-b93</link>
      <guid>https://dev.to/karthickdkk/dangerous-linux-configurations-you-must-avoid-for-secure-systems-deep-dive-b93</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftmfepmafxdbm2dzaftqq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftmfepmafxdbm2dzaftqq.png" alt="Image description" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hey team!&lt;/p&gt;

&lt;p&gt;We all know Linux gives us &lt;strong&gt;superpowers&lt;/strong&gt;, but with great power comes… well, catastrophic failure if you mess up. 😅&lt;br&gt;
Today, I want to dive deeper into misconfigurations that can silently wreak havoc.&lt;/p&gt;

&lt;p&gt;These pitfalls are sneakier — dependencies, SSH settings, disk management, encryption, and library management — the kind of things you don’t realize are dangerous until you’re troubleshooting at 4 AM.&lt;/p&gt;

&lt;p&gt;Let’s walk through these pitfalls together and sprinkle in some humor to keep us awake!&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Giving Everyone Root Access&lt;/li&gt;
&lt;li&gt;Disabling the Firewall? Please Don’t!&lt;/li&gt;
&lt;li&gt;Improper Library and Dependency Management&lt;/li&gt;
&lt;li&gt;Dangerous SSH Configurations&lt;/li&gt;
&lt;li&gt;Running Services as Root (The “No-No” of All No-Nos)&lt;/li&gt;
&lt;li&gt;Poor Disk Management Practices&lt;/li&gt;
&lt;li&gt;Skipping Encryption for Sensitive Data&lt;/li&gt;
&lt;li&gt;Ignoring Kernel and Security Updates&lt;/li&gt;
&lt;li&gt;Not Monitoring Processes and Services&lt;/li&gt;
&lt;li&gt;Incorrectly Editing the /etc/fstab File&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For more details. Please &lt;a href="https://medium.com/devsecops-community/top-10-dangerous-linux-configurations-you-must-avoid-for-secure-systems-deep-dive-9c9b678b640c" rel="noopener noreferrer"&gt;check out here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow &lt;a class="mentioned-user" href="https://dev.to/karthickdkk"&gt;@karthickdkk&lt;/a&gt; for more.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>devops</category>
      <category>ubuntu</category>
      <category>systems</category>
    </item>
    <item>
      <title>Automate EC2 Instances</title>
      <dc:creator>karthick-dkk</dc:creator>
      <pubDate>Fri, 05 Jan 2024 00:06:05 +0000</pubDate>
      <link>https://dev.to/karthickdkk/automate-ec2-instances-nf1</link>
      <guid>https://dev.to/karthickdkk/automate-ec2-instances-nf1</guid>
      <description>&lt;p&gt;Hey Folks, Have you Ever automated EC2 Instances.?&lt;/p&gt;

&lt;h2&gt;
  
  
  AWS
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;As&lt;/strong&gt; organizations scale their cloud infrastructure on Amazon Web Services (AWS), the cost of running instances can become a significant concern. Many workloads do not require 24/7 availability, leading to unnecessary expenses. Fortunately, AWS offers a simple and effective solution to address this issue: using AWS Lambda to automate the start and stop processes of EC2 instances at regular intervals. In this blog post, we will explore the benefits of automating EC2 instances and demonstrate how to implement this cost optimization strategy using AWS Lambda.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of Automating EC2 Instances
&lt;/h2&gt;

&lt;p&gt;Cost Savings: By stopping non-critical EC2 instances when they are not in use, organizations can significantly reduce their cloud infrastructure costs. AWS charges on a pay-as-you-go model, which means that instances running 24/7 can lead to higher bills. Automating the start and stop process allows you to pay only for the compute resources you genuinely need.&lt;/p&gt;

&lt;h2&gt;
  
  
  Environment Friendly:
&lt;/h2&gt;

&lt;p&gt;Implementing EC2 instance automation promotes sustainable practices by reducing the overall carbon footprint. Unnecessary instances that consume energy can be turned off, resulting in a greener and more eco-friendly cloud infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enhanced Security:
&lt;/h2&gt;

&lt;p&gt;Stopping instances when they are not needed can minimize the attack surface and potential security risks. It is a proactive approach to limit exposure to the public internet during periods of inactivity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Simplified Management:
&lt;/h2&gt;

&lt;p&gt;Automating the start and stop of EC2 instances frees up valuable time for your IT team. Manual intervention to manage instance uptime can be a time-consuming task, and automation reduces the burden of administrative work.&lt;br&gt;
Note: The following resolution is a simple solution. For a more robust solution, use the AWS Instance Scheduler. For more information, see Automate starting and stopping AWS instances.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's start&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Step 1: Create a custom AWS IAM policy&lt;br&gt;
Step 2: Create an IAM role for Lambda&lt;br&gt;
Step 3: Create Lambda functions that stop and start your EC2&lt;br&gt;
Step 4: Test your Lambda functions&lt;br&gt;
Step 5: Create EventBridge rules that trigger your function on a schedule&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Note: *&lt;/em&gt;&lt;br&gt;
You can also create rules that trigger on an event that takes place in your AWS account.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Create an IAM policy and execution role for your Lambda function:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Login into the AWS Console. And go to IAM Config&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create an IAM policy using the JSON policy editor. Copy and paste the following JSON policy document into the policy editor:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzgptmadl04oqxnuq74bg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzgptmadl04oqxnuq74bg.png" alt="Image description" width="756" height="306"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
{
"Version": "2012–10–17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*"
},
{
"Effect": "Allow",
"Action": [
"ec2:Start*",
"ec2:Stop*"
],
"Resource": "*"
}
]
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Create an &lt;strong&gt;IAM&lt;/strong&gt; role for Lambda:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb569tzrhbfoeqccf7evw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb569tzrhbfoeqccf7evw.png" alt="Image description" width="800" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;In the navigation pane of the IAM console, choose Roles, and then choose Create role.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For Select trusted entity, choose AWS service.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Important: When attaching a permissions policy to Lambda, make sure that you choose the IAM policy that you just created.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Now Select Policy Previously we created&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; &lt;strong&gt;Create Lambda functions that stop and start your EC2 instances:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;In the Lambda console, choose Create function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Choose Author from scratch.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Under Basic information,&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Add the following:&lt;/strong&gt;&lt;br&gt;
For Function name, enter a name that identifies it as the function used to stop your EC2 instances. For example, “StopEC2Instances”.&lt;br&gt;
For Runtime, choose Python 3.9.&lt;br&gt;
Under Permissions, expand Change default execution role.&lt;br&gt;
Under Execution role, choose Use an existing role.&lt;br&gt;
Under Existing role, choose the IAM role that you created.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Choose Create function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Under Code, Code source, copy and paste the following code into the editor pane in the code editor (&lt;strong&gt;lambda_function&lt;/strong&gt;). This code stops the EC2 instances that you identify.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;6.Check you Instance IDs and Region and change to the below config&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import boto3
region = 'ap-south-1'
instances = ['i-12345cb6de4f78g9h', 'i-08ce9b2d7eccf6d26']
ec2 = boto3.client('ec2', region_name=region)
def lambda_handler(event, context):
ec2.stop_instances(InstanceIds=instances)
print('stopped your instances: ' + str(instances))
( Code as case sensitive and it will prompt error for Extra space )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;**Important: **For region, replace “ap-south-1” with the AWS Region that your instances are in. For instances, replace the example EC2 instance IDs with the IDs of the specific instances that you want to stop and start.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Choose &lt;em&gt;Deploy&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On the Configuration tab, choose General configuration, Edit. Set Timeout to 10 seconds and then select Save.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Configure the Lambda function settings as needed for your use case. For example, if you want to stop and start multiple instances, you might need a different value for Timeout and Memory.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Repeat steps 1–7 to create another function. Do the following differently so that this function starts your EC2 instances:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In step 3, enter a different Function name than the one you used before. For example, “StartEC2Instances”.&lt;br&gt;
In step 5, copy and paste the following code into the editor pane in the code editor (lambda_function):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; function code — &lt;strong&gt;starting EC2 instances&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import boto3
region = 'ap-south-1'
instances = ['i-12345cb6de4f78g9h', 'i-08ce9b2d7eccf6d26']
ec2 = boto3.client('ec2', region_name=region)
def lambda_handler(event, context):
ec2.start_instances(InstanceIds=instances)
print('started your instances: ' + str(instances))
( Code as case sensitive and it will prompt error for Extra space )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; For region and instances , use the same values that you used for the code to stop your EC2 instances.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Test your** Lambda** functions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;In the Lambda console, choose Functions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Choose one of the functions that you created.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the Code tab.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Code source section, select Test.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Configure test event dialog box, choose Create new test event.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter an Event name. Then, choose Create.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note: You don’t need to change the JSON code for the test event — the function doesn’t use it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Choose Test to run the function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Repeat steps 1–6 for the other function that you created (Start Instances).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Tip: You can check the status of your EC2 instances before and after testing to confirm that your functions work as expected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Create &lt;strong&gt;EventBridge&lt;/strong&gt; rules that trigger your Lambda functions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open the Eventbridge console.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select Create rule.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter a Name for your rule, such as “&lt;strong&gt;StopEC2Instances&lt;/strong&gt;”. You can optionally enter a Description.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In Define pattern, select Schedule.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Do either of the following:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For Fixed rate of, enter an interval of time in minutes, hours, or days.&lt;br&gt;
For Cron expression, enter an expression that tells Lambda when to stop your instances. For information on expression syntax, see Schedule expressions for rules.&lt;br&gt;
Note: Cron expressions are evaluated in UTC. Make sure that you adjust the expression for your preferred time zone.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;In Select targets, choose Lambda function from the Target drop-down menu.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For Function, choose the function that stops your EC2 instances.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Scroll down and then select Create.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Repeat steps &lt;em&gt;1–8&lt;/em&gt; to create a rule to start your EC2 instances. Do the following differently:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Enter a name for your rule, such as “&lt;em&gt;StartEC2Instances&lt;/em&gt;”.&lt;br&gt;
(Optional) Enter a Description, such as “&lt;em&gt;Starts EC2 instances every morning at 7 AM&lt;/em&gt;.”&lt;br&gt;
In &lt;em&gt;step 5&lt;/em&gt;, for Cron expression, enter an expression that tells Lambda when to start your instances.&lt;br&gt;
In &lt;em&gt;step 7&lt;/em&gt;, for Function, choose the function that starts your EC2 instances.&lt;/p&gt;

&lt;p&gt;Follow for More 👉&lt;br&gt;
Medium — &lt;a href="https://karthidkk123.medium.com/" rel="noopener noreferrer"&gt;https://karthidkk123.medium.com/&lt;/a&gt;&lt;br&gt;
Linked In — &lt;a href="https://www.linkedin.com/in/karthick-dkk/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/karthick-dkk/&lt;/a&gt;&lt;br&gt;
Instagram — &lt;a href="https://www.instagram.com/karthick_dkk_dk/" rel="noopener noreferrer"&gt;https://www.instagram.com/karthick_dkk_dk/&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
