<?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: Adesokan Israel</title>
    <description>The latest articles on DEV Community by Adesokan Israel (@adesokan_israel_109436759).</description>
    <link>https://dev.to/adesokan_israel_109436759</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%2F1730546%2F9244b726-4eef-489f-8793-430c4ffe585b.JPG</url>
      <title>DEV Community: Adesokan Israel</title>
      <link>https://dev.to/adesokan_israel_109436759</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adesokan_israel_109436759"/>
    <language>en</language>
    <item>
      <title>Automating AWS Resource Management with Shell Scripting</title>
      <dc:creator>Adesokan Israel</dc:creator>
      <pubDate>Fri, 16 Aug 2024 22:33:06 +0000</pubDate>
      <link>https://dev.to/adesokan_israel_109436759/automating-aws-resource-management-with-shell-scripting-1gg3</link>
      <guid>https://dev.to/adesokan_israel_109436759/automating-aws-resource-management-with-shell-scripting-1gg3</guid>
      <description>&lt;p&gt;In the dynamic world of cloud computing, managing resources across an AWS environment can be a daunting task. With numerous services spread across different regions, keeping track of everything manually is not only time-consuming but also prone to error. To address this challenge, I’ve developed a simple yet powerful shell script that automates the process of listing all resources in an AWS account.&lt;/p&gt;

&lt;p&gt;This script provides a quick and efficient way to gather detailed information about your AWS infrastructure, covering a wide range of services like EC2, RDS, S3, and more. Whether you’re a cloud architect responsible for multiple environments or a developer managing a single account, this tool can significantly simplify your workflow, ensuring that you always have an up-to-date inventory of your cloud resources.&lt;/p&gt;

&lt;p&gt;In this article, I’ll walk you through the development and functionality of this script, showcasing how automation can enhance your cloud management strategy.&lt;br&gt;
The focus of this project is to provide a solution for listing resources of a user&lt;br&gt;
on AWS in an automated way, and basically could be used to perform cron job as the case may suit the user and the need in the line of automation.&lt;/p&gt;
&lt;h2&gt;
  
  
  Supported Services
&lt;/h2&gt;

&lt;p&gt;The script currently supports listing resources for the following AWS services:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;EC2&lt;/li&gt;
&lt;li&gt;RDS&lt;/li&gt;
&lt;li&gt;S3&lt;/li&gt;
&lt;li&gt;CloudFront&lt;/li&gt;
&lt;li&gt;VPC&lt;/li&gt;
&lt;li&gt;IAM&lt;/li&gt;
&lt;li&gt;Route53&lt;/li&gt;
&lt;li&gt;CloudWatch&lt;/li&gt;
&lt;li&gt;CloudFormation&lt;/li&gt;
&lt;li&gt;Lambda&lt;/li&gt;
&lt;li&gt;SNS&lt;/li&gt;
&lt;li&gt;SQS&lt;/li&gt;
&lt;li&gt;DynamoDB&lt;/li&gt;
&lt;li&gt;EBS&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Multi-Region Support: The script can query resources across multiple AWS regions.&lt;/li&gt;
&lt;li&gt;Service Coverage: Lists resources from major AWS services such as EC2, S3, RDS, Lambda, and more.&lt;/li&gt;
&lt;li&gt;Output Formats: Results can be outputted in plain text or saved to a file for easy integration with other tools.&lt;/li&gt;
&lt;li&gt;Error Handling: Includes basic error handling to manage API rate limits and service-specific issues.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before running the script, ensure you have the following:&lt;/p&gt;

&lt;p&gt;AWS CLI: Installed and configured with the necessary permissions to query AWS resources.&lt;/p&gt;

&lt;p&gt;Bash Shell: The script is written for Unix-like environments (Linux, macOS, WSL on Windows).&lt;/p&gt;

&lt;p&gt;IAM Permissions: The IAM user or role running the script should have read-only permissions to all AWS services being queried.&lt;/p&gt;
&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzwgwumvbvoa4bfez7ej2.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzwgwumvbvoa4bfez7ej2.PNG" alt="Image description" width="800" height="417"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  STEPS
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;clone the Repository:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;https://github.com/Aymogul/Aws-resource-script.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Install AWS CLI on the instance
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="s2"&gt;"https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip"&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; &lt;span class="s2"&gt;"awscliv2.zip"&lt;/span&gt;
unzip awscliv2.zip
&lt;span class="nb"&gt;sudo&lt;/span&gt; ./aws/install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


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

&lt;ol&gt;
&lt;li&gt;Configure AWS CLI:
Ensure your AWS CLI is configured with the necessary credentials and default region
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws configure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Input your: &lt;br&gt;
Access key&lt;br&gt;
Secret Key&lt;br&gt;
Regon&lt;br&gt;
Output as JSON&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make script Executable:
Give execution permission to the script
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +x aws_resource_list.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;771 aws_resource_list.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Usage
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Run the script
This can be executed directly from the command line after you have logged into an EC2 via ssh or puTTY
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./aws_resource_list.sh &amp;lt;aws_region&amp;gt; &amp;lt;aws_service&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;example usage&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./aws_resource_list.sh us-east-1 ec2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Output:
This script will run and the output of the AWS resource list will be outputed to &lt;code&gt;aws_resources.txt&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./_aws_resource_list.sh &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; aws_resources.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Customization of Regions and other Variables:
By default, the script will query resources in all regions. You can edit the regions variable in the script to specify particular regions:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;regions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"us-east-1"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will list all EC2 instances in the &lt;code&gt;us-east-1&lt;/code&gt; region.&lt;/p&gt;

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

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

&lt;ol&gt;
&lt;li&gt;Valid AWS Services:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The script supports various services like &lt;code&gt;ec2&lt;/code&gt;, &lt;code&gt;rds&lt;/code&gt;, &lt;code&gt;s3&lt;/code&gt;, &lt;code&gt;cloudfront&lt;/code&gt;, &lt;code&gt;vpc&lt;/code&gt;, &lt;code&gt;iam&lt;/code&gt;, &lt;code&gt;route53&lt;/code&gt;, &lt;code&gt;cloudwatch&lt;/code&gt;, &lt;code&gt;cloudformation&lt;/code&gt;, &lt;code&gt;lambda&lt;/code&gt;, &lt;code&gt;sns&lt;/code&gt;, &lt;code&gt;sqs&lt;/code&gt;, &lt;code&gt;dynamodb&lt;/code&gt;, and &lt;code&gt;ebs&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Error Handling
&lt;/h3&gt;

&lt;p&gt;AWS CLI Not Installed: The script checks if AWS CLI is installed and configured. If not, it will prompt the user to install and configure it.&lt;br&gt;
Invalid Service: If an unsupported service is specified, the script will return an error message.&lt;/p&gt;

&lt;h3&gt;
  
  
  Customization
&lt;/h3&gt;

&lt;p&gt;Additional Services: You can modify the script to include additional AWS services by adding new cases to the case block.&lt;br&gt;
Output Format: The script can be enhanced to format output in different ways (e.g., JSON, CSV) depending on your requirements.&lt;/p&gt;

&lt;h3&gt;
  
  
  Contribution
&lt;/h3&gt;

&lt;p&gt;Contributions are welcome! If you have improvements or additional features, feel free to fork the repository and submit a pull request.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Super-Mario deployment on K8 with Terraform</title>
      <dc:creator>Adesokan Israel</dc:creator>
      <pubDate>Wed, 14 Aug 2024 16:11:26 +0000</pubDate>
      <link>https://dev.to/adesokan_israel_109436759/super-mario-deployment-on-k8-with-terraform-gj4</link>
      <guid>https://dev.to/adesokan_israel_109436759/super-mario-deployment-on-k8-with-terraform-gj4</guid>
      <description>&lt;p&gt;*&lt;strong&gt;&lt;em&gt;Introduction&lt;/em&gt;&lt;/strong&gt;*&lt;br&gt;
In the ever-evolving world of DevOps and cloud infrastructure, automating deployments has become crucial for managing complex systems efficiently. Kubernetes, with its robust orchestration capabilities, has emerged as the go-to solution for containerized applications, while Terraform allows for infrastructure as code, enabling repeatable and consistent deployments.&lt;/p&gt;

&lt;p&gt;Imagine combining these powerful tools to deploy something as iconic as Super Mario! In this guide, we’ll walk you through how to deploy the classic Super Mario game on a Kubernetes cluster using Terraform. This tutorial not only showcases the power of Kubernetes and Terraform but also adds a touch of nostalgia by bringing a beloved game into the world of cloud-native applications. Whether you’re a DevOps enthusiast, a cloud engineer, or a gaming aficionado, this deployment will take you on a fun and educational journey into the realms of modern infrastructure management. Let's dive in and bring Mario to life in the cloud!&lt;/p&gt;

&lt;p&gt;Prerequisites:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;AWS account &lt;/li&gt;
&lt;li&gt;An Ubuntu Instance&lt;/li&gt;
&lt;li&gt;IAM role&lt;/li&gt;
&lt;li&gt;Terraform should be installed on instance&lt;/li&gt;
&lt;li&gt;AWS CLI and KUBECTL on Instance&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  General project overview
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;login and basic setup on AWS&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Setup Docker,Terraform,AWS CLI and kubectl&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Provision IAM role for the EC2&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Attach IAM role with the EC2&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Build the infrastucture using Terraform&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create service and deployment for EKS&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Destroy the infrastructure&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  STEP 1: Launch Ubuntu instance
&lt;/h2&gt;

&lt;p&gt;a.&lt;strong&gt;Sign in to AWS Console&lt;/strong&gt;: Log in to your AWS Management Console.&lt;/p&gt;

&lt;p&gt;b.&lt;strong&gt;Navigate to EC2 Dashboard&lt;/strong&gt;: Go to the EC2 Dashboard by selecting “Services” in the top menu and then choosing “EC2” under the Compute section.&lt;/p&gt;

&lt;p&gt;c. &lt;strong&gt;Launch Instance&lt;/strong&gt;: Click on the “Launch Instance” button to start the instance creation process.&lt;/p&gt;

&lt;p&gt;d. &lt;strong&gt;Choose an Amazon Machine Image (AMI)&lt;/strong&gt;: Select an appropriate AMI for your instance. For example, you can choose Ubuntu image.&lt;/p&gt;

&lt;p&gt;e. &lt;strong&gt;Choose an Instance Type&lt;/strong&gt;: In the “Choose Instance Type” step, select t2.micro as your instance type. Proceed by clicking “Next: Configure Instance Details.”&lt;/p&gt;

&lt;p&gt;f. &lt;strong&gt;Configure Instance Details&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For “Number of Instances,” set it to 1 (unless you need multiple instances).&lt;/li&gt;
&lt;li&gt;Configure additional settings like network, subnets, IAM role, etc., if necessary.&lt;/li&gt;
&lt;li&gt;For “Storage,” click “Add New Volume” and set the size to 8GB (or modify the existing storage to 8GB).&lt;/li&gt;
&lt;li&gt;Click “Next: Add Tags” when you’re done.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;g. &lt;strong&gt;Add Tags (Optional)&lt;/strong&gt;: Add any desired tags to your instance. This step is optional, but it helps in organizing instances.&lt;/p&gt;

&lt;p&gt;h. &lt;strong&gt;Configure Security Group&lt;/strong&gt;:&lt;br&gt;
Choose an existing security group or create a new one.&lt;br&gt;
Ensure the security group has the necessary inbound/outbound rules to allow access as required.&lt;/p&gt;

&lt;p&gt;i. &lt;strong&gt;Review and Launch&lt;/strong&gt;: Review the configuration details. Ensure everything is set as desired.&lt;/p&gt;

&lt;p&gt;j.&lt;strong&gt;Select Key Pair&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select “Choose an existing key pair” and choose the key pair from the dropdown.&lt;/li&gt;
&lt;li&gt;Acknowledge that you have access to the selected private key file.&lt;/li&gt;
&lt;li&gt;Click “Launch Instances” to create the instance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;k. &lt;strong&gt;Access the EC2 Instance&lt;/strong&gt;: Once the instance is launched, you can access it using the key pair and the instance’s public IP or DNS.&lt;br&gt;
Ensure you have necessary permissions and follow best practices while configuring security groups and key pairs to maintain security for your EC2 instance.&lt;/p&gt;
&lt;h2&gt;
  
  
  STEP 2: Create IAM role
&lt;/h2&gt;

&lt;p&gt;Search for IAM in the search bar of AWS and click on roles.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd0pqv27zforn4rrx4vup.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd0pqv27zforn4rrx4vup.PNG" alt="Image description" width="733" height="195"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create Role &lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhdlrv6jelxomm2emyves.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhdlrv6jelxomm2emyves.PNG" alt="Image description" width="724" height="208"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select entity type as AWS service&lt;/p&gt;

&lt;p&gt;Use case as EC2 and click on Next.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgollbwba4s8gbfg6e251.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgollbwba4s8gbfg6e251.PNG" alt="Image description" width="724" height="325"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select Administrator Access for permision policy&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjdlxwzfvx5lxaepi1tuk.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjdlxwzfvx5lxaepi1tuk.PNG" alt="Image description" width="728" height="222"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Name the Role &lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frnurby4wafz8vd4zpako.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frnurby4wafz8vd4zpako.PNG" alt="Image description" width="724" height="357"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Role creation successful&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw9slxr6j9p0yzxq4yug1.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw9slxr6j9p0yzxq4yug1.PNG" alt="Image description" width="727" height="207"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then attach this role to Ec2 instance that we created earlier, so we can provision cluster from that instance.&lt;/p&gt;

&lt;p&gt;Go to EC2 Dashboard and select the instance.&lt;/p&gt;

&lt;p&gt;Click on Actions –&amp;gt; Security –&amp;gt; Modify IAM role.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd782hwktkj4v3e785k6t.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd782hwktkj4v3e785k6t.PNG" alt="Image description" width="730" height="159"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select the Role that created earlier and click on Update IAM role.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7jqll3qf31ffppb3fpxj.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7jqll3qf31ffppb3fpxj.PNG" alt="Image description" width="727" height="209"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From this point, you can connect to the server via any means you prefer either: AWS instance connect or putty&lt;/p&gt;

&lt;p&gt;STEP 3: Cluster provision&lt;br&gt;
Now clone this Repo.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/Aymogul/k8-super-mario-deployment-with-terraform.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;change directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;k8-super-mario-deployment-with-terraform 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update the server and Provide the executable permission to script.sh file, and run it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;su
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo chmod&lt;/span&gt; +x script.sh
./script.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The execution of this script will install AWS CLI, Terraform, Kubectl and Docker.&lt;/p&gt;

&lt;p&gt;check the versions of installed tools&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nt"&gt;--version&lt;/span&gt;
aws &lt;span class="nt"&gt;--version&lt;/span&gt;
kubectl version &lt;span class="nt"&gt;--client&lt;/span&gt;
terraform &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now change directory into the EKS-TF&lt;/p&gt;

&lt;p&gt;Run Terraform init&lt;/p&gt;

&lt;p&gt;NOTE: Don’t forgot to change the s3 bucket name in the backend.tf file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;EKS-TF
terraform init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;The next step is to run validate and plan the terraform deployment&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform validate
terraform plan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Provision the cluster by running this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform apply &lt;span class="nt"&gt;--auto-approve&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Update the Kubernetes configuration&lt;/p&gt;

&lt;p&gt;Make sure change your desired region&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws eks update-kubeconfig &lt;span class="nt"&gt;--name&lt;/span&gt; EKS_CLOUD &lt;span class="nt"&gt;--region&lt;/span&gt; us-west-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now change directory back to k8-super-mario-deployment-with-terraform&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ..
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;let's now move to the most exciting part of the project as we deploy the game on EKS cluster and enjoy the thrill of super-mario.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deployment
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; deployment.yaml
&lt;span class="c"&gt;#to check the deployment &lt;/span&gt;
kubectl get all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Now let’s apply the service&lt;/p&gt;

&lt;h2&gt;
  
  
  Service
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; service.yaml
kubectl get all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let’s describe the service and copy the LoadBalancer Ingress&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl describe service mario-service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Paste the ingress link in a browser and you will see the Mario game.&lt;/p&gt;

&lt;h1&gt;
  
  
  EUREKA
&lt;/h1&gt;

&lt;p&gt;Enjoy the classic thrill of super-mario...&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw7q0zy63mi66wkz1pi0m.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw7q0zy63mi66wkz1pi0m.PNG" alt="Image description" width="724" height="401"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuif1eu8ugoy1zdj3ihq1.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuif1eu8ugoy1zdj3ihq1.PNG" alt="Image description" width="726" height="402"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Destruction :
&lt;/h2&gt;

&lt;p&gt;Let’s remove the service and deployment first&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get all
kubectl delete service mario-service
kubectl delete deployment mario-deployment

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

&lt;/div&gt;



&lt;p&gt;Destruction of the infrastructure&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform destroy &lt;span class="nt"&gt;--auto-approve&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Deploying Super Mario on Kubernetes using Terraform demonstrates the power of modern infrastructure tools like Kubernetes for container orchestration and Terraform for infrastructure as code. This project combines nostalgia with practical skills, showcasing how these technologies enable consistent and scalable deployments. By following the steps in this guide, you've not only deployed a classic game but also gained valuable insights into managing complex systems in the cloud. The knowledge gained here can be applied to various projects, setting you up for success in the evolving world of DevOps and cloud infrastructure.&lt;br&gt;
&lt;strong&gt;Thank you for following&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Linux users creation with Bash script</title>
      <dc:creator>Adesokan Israel</dc:creator>
      <pubDate>Thu, 04 Jul 2024 16:38:58 +0000</pubDate>
      <link>https://dev.to/adesokan_israel_109436759/linux-users-creation-with-bash-script-4733</link>
      <guid>https://dev.to/adesokan_israel_109436759/linux-users-creation-with-bash-script-4733</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In a growing organization, managing user accounts efficiently is crucial. Automating the process can save significant time and reduce errors. This article explains a Bash script designed to read a list of users and groups from a text file, create the users and groups, set up home directories, generate passwords, and log all actions. This script is particularly useful for SysOps engineers responsible for maintaining system user accounts.&lt;/p&gt;

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

&lt;p&gt;The purpose of this blog is to provide solution for the creation of Linux users using bash script in an automated and reliable way. Below is the scenario for the problem statement.&lt;br&gt;
Your company has employed many new developers. As a SysOps engineer, write a bash script called create_users.sh that reads a text file containing the employee’s usernames and group names, where each line is formatted as user;groups.&lt;br&gt;
The script creates users and groups as specified, set up home directories with appropriate permissions and ownership, generate random passwords for the users, and log all actions to /var/log/user_management.log. Additionally, store the generated passwords securely in /var/secure/user_passwords.txt.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Script Overview&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The create_users.sh script reads a text file where each line is formatted as user;groups, creates the users and groups, sets up home directories, and generates random passwords. Actions are logged to /var/log/user_management.log, and passwords are securely stored in /var/secure/user_passwords.csv.&lt;/p&gt;
&lt;h2&gt;
  
  
  Detailed Breakdown
&lt;/h2&gt;

&lt;p&gt;Log and Secure Password File Setup:&lt;br&gt;
The script begins by setting up the log file and secure password file. It ensures that the directories exist and sets appropriate permissions for the password file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LOG_FILE="/var/log/user_management.log"
PASSWORD_FILE="/var/secure/user_passwords.csv"

mkdir -p /var/log
touch $LOG_FILE

mkdir -p /var/secure
touch $PASSWORD_FILE
chmod 600 $PASSWORD_FILE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Logging Function:&lt;br&gt;
A function is defined to log messages with timestamps.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;log_message&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;date&lt;/span&gt; +&lt;span class="s1"&gt;'%Y-%m-%d %H:%M:%S'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; - &lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$LOG_FILE&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Password Generation&lt;/p&gt;

&lt;p&gt;A helper function generates random passwords.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;generate_password&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;tr&lt;/span&gt; &lt;span class="nt"&gt;-dc&lt;/span&gt; A-Za-z0-9 &amp;lt;/dev/urandom | &lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; 12
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Input File Check&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The script checks if an input file is provided and exits if not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-z&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Usage: &lt;/span&gt;&lt;span class="nv"&gt;$0&lt;/span&gt;&lt;span class="s2"&gt; &amp;lt;user-file&amp;gt;"&lt;/span&gt;
    &lt;span class="nb"&gt;exit &lt;/span&gt;1
&lt;span class="k"&gt;fi

&lt;/span&gt;&lt;span class="nv"&gt;USER_FILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt; Processing the Input File&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The script reads the input file line by line, ignoring whitespace and empty lines, and processes each user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="nv"&gt;IFS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;';'&lt;/span&gt; &lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; username &lt;span class="nb"&gt;groups&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nv"&gt;username&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$username&lt;/span&gt; | xargs&lt;span class="si"&gt;)&lt;/span&gt;
    &lt;span class="nb"&gt;groups&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$groups&lt;/span&gt; | xargs&lt;span class="si"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-z&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt; Creating Users and Groups&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For each user, the script checks if the user already exists, creates the primary group (same as the username), creates the user, sets up home directory permissions, and generates a password.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&amp;gt;&amp;amp;1&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;log_message &lt;span class="s2"&gt;"User &lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="s2"&gt; already exists"&lt;/span&gt;
&lt;span class="k"&gt;else
    &lt;/span&gt;groupadd &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    log_message &lt;span class="s2"&gt;"Group &lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="s2"&gt; created"&lt;/span&gt;

    useradd &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; /bin/bash &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    log_message &lt;span class="s2"&gt;"User &lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="s2"&gt; created with home directory /home/&lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

    &lt;span class="nb"&gt;chmod &lt;/span&gt;700 &lt;span class="s2"&gt;"/home/&lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    log_message &lt;span class="s2"&gt;"Set permissions for /home/&lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

    &lt;span class="nv"&gt;password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;generate_password&lt;span class="si"&gt;)&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;$password&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | chpasswd
    log_message &lt;span class="s2"&gt;"Password set for user &lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="nv"&gt;$password&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$PASSWORD_FILE&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt; Adding Users to Additional Groups&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The script then adds the user to any additional groups specified in the input file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$groups&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nv"&gt;IFS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;','&lt;/span&gt; &lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-ra&lt;/span&gt; GROUP_ARRAY &lt;span class="o"&gt;&amp;lt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$groups&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;group &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GROUP_ARRAY&lt;/span&gt;&lt;span class="p"&gt;[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
        &lt;/span&gt;&lt;span class="nv"&gt;group&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$group&lt;/span&gt; | xargs&lt;span class="si"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; getent group &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$group&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
            &lt;/span&gt;groupadd &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$group&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
            log_message &lt;span class="s2"&gt;"Group &lt;/span&gt;&lt;span class="nv"&gt;$group&lt;/span&gt;&lt;span class="s2"&gt; created"&lt;/span&gt;
        &lt;span class="k"&gt;fi
        &lt;/span&gt;usermod &lt;span class="nt"&gt;-aG&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$group&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
        log_message &lt;span class="s2"&gt;"User &lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="s2"&gt; added to group &lt;/span&gt;&lt;span class="nv"&gt;$group&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;done
fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Completion
&lt;/h4&gt;

&lt;p&gt;Finally, the script logs the completion of the user creation process.&lt;/p&gt;

&lt;p&gt;"log_message "User creation process completed"&lt;/p&gt;

&lt;p&gt;echo "User creation process completed. Check the log file at $LOG_FILE for details."&lt;/p&gt;

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

&lt;p&gt;To run and test the create_users.sh script, follow these steps:&lt;/p&gt;

&lt;p&gt;Step 1:&lt;/p&gt;

&lt;h4&gt;
  
  
  Prepare Your Environment
&lt;/h4&gt;

&lt;p&gt;Ensure you have the necessary permissions to create users, groups, and modify system files. Running the script might require superuser privileges.&lt;/p&gt;

&lt;p&gt;Step 2: &lt;/p&gt;

&lt;h4&gt;
  
  
  Create the Input File
&lt;/h4&gt;

&lt;p&gt;Create a text file with the usernames and groups. For example, create a file named users.txt with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;isreal&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nb"&gt;sudo&lt;/span&gt;,dev,www-data
isreal2&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nb"&gt;sudo
&lt;/span&gt;isreal3&lt;span class="p"&gt;;&lt;/span&gt;dev,www-data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3:&lt;/p&gt;

&lt;h4&gt;
  
  
  Ensure Necessary Directories Exist
&lt;/h4&gt;

&lt;p&gt;Ensure that the directories /var/log and /var/secure exist and have the appropriate permissions. You might need to create them if they don't exist:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; /var/log /var/secure
&lt;span class="nb"&gt;sudo touch&lt;/span&gt; /var/log/user_management.log /var/secure/user_passwords.csv
&lt;span class="nb"&gt;sudo chmod &lt;/span&gt;600 /var/secure/user_passwords.csv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 4: &lt;/p&gt;

&lt;h4&gt;
  
  
  Run the Script
&lt;/h4&gt;

&lt;p&gt;To execute the script, use the following command, passing the name of the input file as an argument:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;bash create_users.sh users.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 5: &lt;/p&gt;

&lt;h4&gt;
  
  
  Verify the Script's Actions
&lt;/h4&gt;

&lt;p&gt;Check the Log File: Verify the actions logged in /var/log/user_management.log.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo cat&lt;/span&gt; /var/log/user_management.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check the Passwords File: Verify the securely stored passwords in /var/secure/user_passwords.csv.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo cat&lt;/span&gt; /var/secure/user_passwords.csv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify User and Group Creation: Check if the users and groups were created correctly.&lt;/p&gt;

&lt;p&gt;List users and groups&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;getent passwd | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-E&lt;/span&gt; &lt;span class="s1"&gt;'isreal|isreal2|isreal3'&lt;/span&gt;
getent group | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-E&lt;/span&gt; &lt;span class="s1"&gt;'isreal|sudo|dev|www-data'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check Home Directory Permissions:&lt;/p&gt;

&lt;p&gt;Ensure the home directories were created with the correct permissions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-ld&lt;/span&gt; /home/isreal /home/isreal2 /home/isreal3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

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

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

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

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

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;With this, we have successfully automated user creation with a Bash script which could help to reduce errorand ensure reliability, from defining user details in users.txt to execution, the project has transitioned from execution to completion.&lt;br&gt;
To be part of the program that provided this task scenario, visit their official websites to gain more insights&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hng.tech/internship"&gt;https://hng.tech/internship&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hng.tech/hire"&gt;https://hng.tech/hire&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading &lt;/p&gt;

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