<?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: Teniola </title>
    <description>The latest articles on DEV Community by Teniola  (@tennie).</description>
    <link>https://dev.to/tennie</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%2F1724033%2F204ac687-3059-491f-b453-f1f8e0d647f0.jpg</url>
      <title>DEV Community: Teniola </title>
      <link>https://dev.to/tennie</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tennie"/>
    <language>en</language>
    <item>
      <title>Building a Weather Dashboard with Python and AWS S3</title>
      <dc:creator>Teniola </dc:creator>
      <pubDate>Fri, 24 Jan 2025 10:07:29 +0000</pubDate>
      <link>https://dev.to/tennie/building-a-weather-dashboard-with-python-and-aws-s3-2k4i</link>
      <guid>https://dev.to/tennie/building-a-weather-dashboard-with-python-and-aws-s3-2k4i</guid>
      <description>&lt;h2&gt;
  
  
  Weather Dashboard
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Overview
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;Weather Dashboard&lt;/strong&gt; is a Python-based application designed to fetch real-time weather data for specified cities and store this data in an AWS S3 bucket. It leverages the OpenWeather API for retrieving weather information and uses the Boto3 library to interact with AWS S3, making it a handy tool for anyone who wants to organize and store weather data efficiently.&lt;/p&gt;




&lt;h3&gt;
  
  
  Features
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Fetches real-time weather data for multiple cities&lt;/li&gt;
&lt;li&gt;Displays temperature (°F), humidity, and weather conditions&lt;/li&gt;
&lt;li&gt;Automatically stores weather data in AWS S3&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  - Supports multiple cities tracking
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Python 3.6 or higher&lt;/strong&gt; installed on your system.&lt;/li&gt;
&lt;li&gt;An &lt;strong&gt;AWS account&lt;/strong&gt; with S3 access configured.&lt;/li&gt;
&lt;li&gt;An &lt;strong&gt;OpenWeather API key&lt;/strong&gt; to fetch weather data.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. Clone the Repository
&lt;/h4&gt;

&lt;p&gt;Run the following commands to clone the repository and navigate to its directory:&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/Teni1023/weather-dashboard.git
&lt;span class="nb"&gt;cd &lt;/span&gt;weather-dashboard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Create and Activate a Virtual Environment
&lt;/h4&gt;

&lt;p&gt;Create a virtual environment to manage dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python &lt;span class="nt"&gt;-m&lt;/span&gt; venv venv
&lt;span class="nb"&gt;source &lt;/span&gt;venv/bin/activate  &lt;span class="c"&gt;# On Windows, use `venv\Scripts\activate`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Install Required Packages
&lt;/h4&gt;

&lt;p&gt;Install the dependencies listed in the &lt;code&gt;requirements.txt&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Configure Environment Variables
&lt;/h4&gt;

&lt;p&gt;Create a &lt;code&gt;.env&lt;/code&gt; file in the root directory of the project and add the following environment variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OPENWEATHER_API_KEY=your_openweather_api_key
AWS_ACCESS_KEY=your_aws_access_key
AWS_SECRET_KEY=your_aws_secret_key
AWS_REGION=your_aws_region
S3_BUCKET_NAME=your_s3_bucket_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the placeholders with your actual API keys and AWS details.&lt;/p&gt;




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

&lt;p&gt;Run the application with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python src/weather_dashboard.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The application will fetch weather data for the cities specified in the code.&lt;/li&gt;
&lt;li&gt;It will display the weather data in a readable format on the console.&lt;/li&gt;
&lt;li&gt;Additionally, the weather data will be saved to your configured AWS S3 bucket.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Code Structure
&lt;/h3&gt;

&lt;p&gt;Here's an overview of the key components of the application:&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;code&gt;weather_dashboard.py&lt;/code&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The main script containing the logic for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fetching weather data using the OpenWeather API.&lt;/li&gt;
&lt;li&gt;Displaying the data in a user-friendly format.&lt;/li&gt;
&lt;li&gt;Saving the data to AWS S3.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Methods
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;code&gt;__init__()&lt;/code&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Initializes the &lt;code&gt;WeatherDashboard&lt;/code&gt; class.&lt;/li&gt;
&lt;li&gt;Loads environment variables and sets up configurations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;code&gt;create_bucket_if_not_exists()&lt;/code&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Checks if the specified S3 bucket exists.&lt;/li&gt;
&lt;li&gt;Creates the bucket if it doesn't exist.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;code&gt;fetch_weather(city)&lt;/code&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Fetches real-time weather data for the specified city from the OpenWeather API.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;code&gt;display_weather_data(city, weather_data)&lt;/code&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Displays weather details such as temperature, humidity, wind speed, and weather description in a readable format.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;code&gt;save_weather_data_to_s3(city, weather_data)&lt;/code&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Saves the fetched weather data to the specified AWS S3 bucket for future reference.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Example Output
&lt;/h3&gt;

&lt;p&gt;Here’s what the output of the application might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Bucket my-weather-bucket exists
Fetching weather for Philadelphia...
Weather data for Philadelphia:
Temperature: 75°F
Weather: clear sky
Humidity: 50%
Wind Speed: 5 mph
Timestamp: 2023-10-01 12:00:00
----------------------------------------
Successfully saved data for Philadelphia to S3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;The Weather Dashboard is a simple yet powerful tool for fetching, displaying, and storing weather data. By integrating Python, AWS S3, and the OpenWeather API, this project demonstrates how you can combine various technologies to build a functional and scalable application.&lt;/p&gt;

&lt;p&gt;Feel free to clone the repository, explore the code, and customize it to suit your needs. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Deploying Your First Server with Terraform: A Beginner's Guide</title>
      <dc:creator>Teniola </dc:creator>
      <pubDate>Tue, 31 Dec 2024 00:07:00 +0000</pubDate>
      <link>https://dev.to/tennie/deploying-your-first-server-with-terraform-a-beginners-guide-2fl5</link>
      <guid>https://dev.to/tennie/deploying-your-first-server-with-terraform-a-beginners-guide-2fl5</guid>
      <description>&lt;p&gt;My name is Tennie, and I began my DevOps journey a few months ago. I am passionate about continuous learning, and I recently joined the Terraform 30-Day Challenge to deepen my understanding and sharpen my skills in infrastructure automation. My goal for this challenge is to become proficient in Terraform, master its concepts and applications, and ultimately achieve certification. For the next 30 days, I will be updating my progress as I take on this exciting learning journey!&lt;/p&gt;

&lt;p&gt;Day 3&lt;br&gt;
In this article i will be explaining Deploying Your First Server with Terraform as a beginner &lt;/p&gt;

&lt;p&gt;Terraform is a powerful Infrastructure as Code (IaC) tool that allows you to define and provision your infrastructure using declarative configuration files. This guide will walk you through the steps to deploy your first server using Terraform. By the end of this article, you’ll have a basic understanding of how Terraform works and a running server.&lt;/p&gt;

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

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

&lt;p&gt;Terraform Installed: Download and install Terraform from Terraform’s official website.&lt;/p&gt;

&lt;p&gt;Cloud Provider Account: Create an account with your preferred cloud provider (e.g., AWS&lt;/p&gt;

&lt;p&gt;Access Credentials: Set up access credentials for your cloud provider.&lt;/p&gt;

&lt;p&gt;Code Editor: Use a code editor like Visual Studio Code.&lt;/p&gt;

&lt;p&gt;Step 1: Initialize Your Terraform Project&lt;/p&gt;

&lt;p&gt;Create a Project Directory:&lt;/p&gt;

&lt;p&gt;mkdir terraform-server-deploy &amp;amp;&amp;amp; cd terraform-server-deploy&lt;/p&gt;

&lt;p&gt;Write Your First Configuration File:&lt;/p&gt;

&lt;p&gt;Create a file named main.tf and open it in your editor. Add the following:&lt;/p&gt;

&lt;p&gt;provider "aws" {&lt;br&gt;
  region = "us-west-2"&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;resource "aws_instance" "example" {&lt;br&gt;
  ami           = "ami-0c55b159cbfafe1f0"&lt;br&gt;&lt;br&gt;
  instance_type = "t2.micro"&lt;/p&gt;

&lt;p&gt;tags = {&lt;br&gt;
    Name = "TerraformExampleServer"&lt;br&gt;
  }&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Replace the ami value with an appropriate AMI ID for your region.&lt;/p&gt;

&lt;p&gt;Initialize the Directory:&lt;br&gt;
Run the following command to initialize your project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This downloads the necessary provider plugins.&lt;/p&gt;

&lt;p&gt;Step 2: Preview and Apply the Configuration&lt;/p&gt;

&lt;p&gt;Preview Changes:&lt;br&gt;
Run terraform plan to see what Terraform will create:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Apply the Configuration:&lt;br&gt;
Use the following command to create the server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Review the proposed changes and type yes to confirm.&lt;/p&gt;

&lt;p&gt;Step 3: Verify the Server&lt;/p&gt;

&lt;p&gt;Once the terraform apply command completes, you’ll see output with information about the resources created. Use your cloud provider’s console to confirm the instance is running.&lt;/p&gt;

&lt;p&gt;Step 4: Clean Up Resources&lt;/p&gt;

&lt;p&gt;To avoid unnecessary charges, destroy the resources when you’re done:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Type yes to confirm the destruction of resources.&lt;/p&gt;

</description>
      <category>terraform</category>
    </item>
    <item>
      <title>Step-by-Step Guide to Setting Up Terraform, AWS CLI, and VS Code</title>
      <dc:creator>Teniola </dc:creator>
      <pubDate>Sun, 29 Dec 2024 21:09:58 +0000</pubDate>
      <link>https://dev.to/tennie/step-by-step-guide-to-setting-up-terraform-aws-cli-and-vs-code-39i9</link>
      <guid>https://dev.to/tennie/step-by-step-guide-to-setting-up-terraform-aws-cli-and-vs-code-39i9</guid>
      <description>&lt;p&gt;My name is Tennie, and I began my DevOps journey a few months ago. I am passionate about continuous learning, and I recently joined the Terraform 30-Day Challenge to deepen my understanding and sharpen my skills in infrastructure automation. My goal for this challenge is to become proficient in Terraform, master its concepts and applications, and ultimately achieve certification. For the next 30 days, I will be updating my progress as I take on this exciting learning journey!&lt;/p&gt;

&lt;p&gt;Day 2&lt;/p&gt;

&lt;p&gt;In this article i will be explaining detailed guide on how to set up Terraform, AWS CLI, and VS Code&lt;/p&gt;

&lt;p&gt;Download Terraform&lt;/p&gt;

&lt;p&gt;The official Terraform download page: &lt;a href="https://www.terraform.io/downloads" rel="noopener noreferrer"&gt;https://www.terraform.io/downloads&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Select the version compatible with your operating system (Windows, macOS, Linux).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install Terraform&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Windows:&lt;br&gt;
Extract the downloaded .zip file.&lt;br&gt;
Move the terraform.exe file to a directory included in your system's PATH, such as C:\Windows\System32.&lt;/p&gt;

&lt;p&gt;Verify the installation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
terraform --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install AWS CLI&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Download AWS CLI&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Visit the official AWS CLI download page: &lt;a href="https://aws.amazon.com/cli/" rel="noopener noreferrer"&gt;https://aws.amazon.com/cli/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;2.1 Install AWS CLI&lt;/p&gt;

&lt;p&gt;Windows:&lt;br&gt;
Run the installer and follow the prompts.&lt;br&gt;
Verify the installation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configure AWS CLI&lt;br&gt;
Run the following command to configure the AWS CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
aws configure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Provide:&lt;/p&gt;

&lt;p&gt;Access Key ID&lt;br&gt;
Secret Access Key&lt;br&gt;
Default region (e.g., us-east-1)&lt;br&gt;
Output format (e.g., json)&lt;/p&gt;

&lt;p&gt;Install Visual Studio Code (VS Code)&lt;br&gt;
3.1 Download and Install VS Code&lt;br&gt;
Download VS Code from: &lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;https://code.visualstudio.com/&lt;/a&gt;.&lt;br&gt;
Install it by following the prompts for your OS.&lt;/p&gt;

&lt;p&gt;3.2 Install Extensions&lt;/p&gt;

&lt;p&gt;Open VS Code.&lt;/p&gt;

&lt;p&gt;Go to the Extensions Marketplace (Ctrl+Shift+X or Cmd+Shift+X).&lt;br&gt;
Search for and install the following extensions:&lt;/p&gt;

</description>
      <category>awscli</category>
      <category>terraform</category>
      <category>vscode</category>
    </item>
    <item>
      <title>What is infrastructure as code and how its transforming DevOps</title>
      <dc:creator>Teniola </dc:creator>
      <pubDate>Tue, 24 Dec 2024 01:17:31 +0000</pubDate>
      <link>https://dev.to/tennie/what-is-infrastructure-as-code-and-how-its-transforming-devops-12h2</link>
      <guid>https://dev.to/tennie/what-is-infrastructure-as-code-and-how-its-transforming-devops-12h2</guid>
      <description>&lt;p&gt;My name is Tennie, and I began my DevOps journey a few months ago. I am passionate about continuous learning, and I recently joined the Terraform 30-Day Challenge to deepen my understanding and sharpen my skills in infrastructure automation. My goal for this challenge is to become proficient in Terraform, master its concepts and applications, and ultimately achieve certification. For the next 30 days, I will be updating my progress as I take on this exciting learning journey!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Day 1&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this article i will be explaining what infrastructure as code is and how its transforming DevOps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Infrastructure as Code (IaC)&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;Infrastructure as code (IaC) is the ability to provision and support  computing infrastructure using code instead of manual processes and settings. Any application environment requires many infrastructure components like operating systems, database connections, and storage. Developers have to regularly set up, update, and maintain the infrastructure to develop, test, and deploy applications. &lt;/p&gt;

&lt;p&gt;Manual infrastructure management is time-consuming and prone to error—especially when you manage applications at scale. Infrastructure as code lets you define your infrastructure's desired state without including all the steps to get to that state. It automates infrastructure management so developers can focus on building and improving applications instead of managing environments. Organizations use infrastructure as code to control costs, reduce risks, and respond with speed to new business opportunities.&lt;br&gt;
Infrastructure as Code (IaC) is the practice of managing and provisioning computing infrastructure through machine-readable configuration files, rather than physical hardware configuration or interactive configuration tools. It enables developers and operators to define and manage infrastructure resources.&lt;/p&gt;

&lt;p&gt;IaC automates infrastructure deployment and configuration processes, making them consistent, repeatable, and version-controlled&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%2Ffmn8ld7vgjantrf69ksh.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%2Ffmn8ld7vgjantrf69ksh.png" alt="Image description" width="800" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why IaC is Transforming DevOps&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;DevOps is the process of improving collaboration between software development and IT operations teams. It aims to shorten the application development lifecycle and provide continuous delivery of high-quality software. DevOps teams integrate operations activities with developer tools and code commits, so applications can have extremely rapid release cycles.&lt;/p&gt;

&lt;p&gt;A key goal of DevOps is to automate infrastructure tasks across the development process. You can integrate infrastructure as code (IaC) into continuous integration and continuous deployment (CI/CD) pipelines. This way, when software goes through its build and release process, the necessary infrastructure changes can be made in tandem.&lt;/p&gt;

&lt;p&gt;DevOps teams use infrastructure as code for many purposes:&lt;/p&gt;

&lt;p&gt;Quickly set up complete environments, from development to production&lt;br&gt;
Help ensure consistently reproducible configurations between environments&lt;br&gt;
Integrate seamlessly with cloud providers and efficiently scale infrastructure resources up or down based on demand&lt;br&gt;
IaC provides a common language for both developers and operations. Changes can be reviewed in a transparent manner, which fosters better collaboration in a DevOps environment.&lt;/p&gt;

&lt;p&gt;IaC is revolutionizing DevOps by addressing many challenges associated with traditional infrastructure management. Here's why it's transformative:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Consistency and Standardization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Reduces human errors by automating deployments.&lt;br&gt;
Ensures consistent environments across development, staging, and production.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Speed and Agility&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Allows for rapid provisioning and de-provisioning of resources.&lt;br&gt;
Enhances scalability, especially in dynamic environments like cloud computing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Version Control&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;IaC configurations are stored as code, making them versionable with tools like Git.&lt;br&gt;
Facilitates auditing, rollback, and collaboration among teams.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Collaboration and Automation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Bridges the gap between developers and operations teams by treating infrastructure the same way as application code.&lt;br&gt;
Integrates seamlessly into CI/CD pipelines, enabling automated testing and deployment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cost Efficiency&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Minimizes downtime with predictable deployments.&lt;br&gt;
Reduces resource wastage by automating resource cleanup.&lt;br&gt;
Disaster Recovery and Scaling&lt;/p&gt;

&lt;p&gt;IaC scripts make it easy to rebuild infrastructure quickly in case of failure.&lt;br&gt;
Supports horizontal and vertical scaling through repeatable configurations.&lt;br&gt;
&lt;strong&gt;Real-Life Impact on DevOps&lt;/strong&gt;&lt;br&gt;
Improved Time-to-Market: Faster environment provisioning leads to quicker deployments.&lt;br&gt;
Error Reduction: Pre-tested, automated configurations eliminate manual errors.&lt;br&gt;
Greater Flexibility: Teams can experiment with different setups without fear of long-term consequences.&lt;br&gt;
IaC is a cornerstone of modern DevOps practices, enabling teams to achieve higher efficiency, reliability, and innovation in software delivery.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>terraform</category>
      <category>infrastructureascode</category>
    </item>
    <item>
      <title>Set up SSH Key Authentication</title>
      <dc:creator>Teniola </dc:creator>
      <pubDate>Sat, 23 Nov 2024 23:37:19 +0000</pubDate>
      <link>https://dev.to/tennie/set-up-ssh-key-authentication-1nc5</link>
      <guid>https://dev.to/tennie/set-up-ssh-key-authentication-1nc5</guid>
      <description>&lt;p&gt;Continuing on my DevOps journey,  I dove deeper into practical tasks that strengthened my skills in Linux server management, security, and automation. I set up SSH key authentication, secured Nginx with SSL/TLS, and implemented best practices for web server security. Exploring load balancing, I configured Nginx to distribute traffic for high availability. Documenting these steps keeps my journey purposeful and impactful.&lt;/p&gt;

&lt;p&gt;Generate an SSH key pair on your local machine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-keygen -t rsa -b 4096 -C "test2@gmail.com"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy the public key to the remote server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-copy-id user@remote_server_ip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test the connection:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh user@remote_server_ip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Confirm no password is requested.&lt;br&gt;
Disable Password Authentication for SSH:&lt;/p&gt;

&lt;p&gt;Open the SSH configuration file on the remote server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nano /etc/ssh/sshd_config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Modify or add the following lines:&lt;br&gt;
yaml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PasswordAuthentication no
PubkeyAuthentication yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart the SSH service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl restart sshd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Web Server Security&lt;br&gt;
Enhance Nginx Security with SSL/TLS:&lt;/p&gt;

&lt;p&gt;Install Certbot and request a free SSL certificate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify SSL is working:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://yourdomain.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Implement Security Best Practices:&lt;/p&gt;

&lt;p&gt;Update Nginx:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update &amp;amp;&amp;amp; sudo apt upgrade
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set up HTTP to HTTPS redirection:&lt;br&gt;
nginx&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
    return 301 https://$host$request_uri;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Limit buffer size and request rate:&lt;br&gt;
nginx&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;client_max_body_size 10M;
limit_req_zone $binary_remote_addr zone=mylimit:10m rate=5r/s;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Load Balancing&lt;br&gt;
Basic Load-Balancing Concepts:&lt;/p&gt;

&lt;p&gt;Distribute incoming traffic across multiple servers.&lt;br&gt;
Ensure high availability and fault tolerance.&lt;br&gt;
Set Up Nginx as a Simple Load Balancer:&lt;/p&gt;

&lt;p&gt;Edit the Nginx configuration file:&lt;br&gt;
nginx&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;upstream backend {
    server backend1.example.com;
    server backend2.example.com;
}
server {
    listen 80;
    server_name yourdomain.com;
    location / {
        proxy_pass http://backend;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test the configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nginx -t
sudo systemctl reload nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Linux Network Configuration</title>
      <dc:creator>Teniola </dc:creator>
      <pubDate>Wed, 13 Nov 2024 23:57:46 +0000</pubDate>
      <link>https://dev.to/tennie/linux-network-configuration-3ga4</link>
      <guid>https://dev.to/tennie/linux-network-configuration-3ga4</guid>
      <description>&lt;p&gt;A few more steps forward in my DevOps journey! This time, I worked on  another task in Linux administration which is focused on configuring server and network settings. In this task, I set a static IP address, configured firewall rules for added security, and installed and set up Nginx to host a simple website. I also explored DNS concepts to understand how domain resolution works. Each step helped solidify the foundational skills necessary for effective system management—a critical part of any DevOps role. Documenting these tasks not only tracks my progress but serves as a practical guide for anyone on a similar path.&lt;/p&gt;

&lt;p&gt;This task focuses on configuring essential server and network settings on Linux. Key objectives include assigning a static IP, setting up a firewall for security, installing and configuring Nginx to host a basic website, and learning DNS for domain resolution. Completing this task will build foundational skills in network management, server setup, and security configuration on Ubuntu.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Network Configuration
Objective: Configure network settings on a Linux server, assign a static IP address, and troubleshoot network issues with basic tools.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Step 1: Set up a Static IP Address&lt;br&gt;
Identify the Network Interface:&lt;/p&gt;

&lt;p&gt;The network interface represents the physical or virtual network adapter through which the system connects to a network.&lt;br&gt;
Use the following command to list all available network interfaces and their current IP addresses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ip a
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look for your primary interface (often named eth0, enp0s3, or something similar). The IP and subnet mask appear as inet /.&lt;br&gt;
Edit the Network Configuration File:&lt;/p&gt;

&lt;p&gt;Ubuntu (using Netplan):&lt;br&gt;
Netplan is the default network configuration utility on recent Ubuntu versions.&lt;br&gt;
Open /etc/netplan/01-netcfg.yaml (the filename may vary in the /etc/netplan/ directory) to configure your network.&lt;br&gt;
Update or add your settings for the desired static IP, gateway, and DNS servers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;network:
  version: 2
  ethernets:
    enp0s3:
      dhcp4: no  # Disables DHCP, which automatically assigns IPs
      addresses:
        - 192.168.1.100/24  # Sets static IP and subnet mask
      gateway4: 192.168.1.1  # Sets the gateway IP for outbound traffic
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save changes and apply them using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo netplan apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Using ifconfig:&lt;/p&gt;

&lt;p&gt;This tool displays network interface configurations (IP addresses, subnet masks, etc.). It’s commonly pre-installed or installable with sudo apt install net-tools.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ifconfig
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using ip:&lt;/p&gt;

&lt;p&gt;The ip command provides comprehensive network configuration details and is widely used on modern systems.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ip addr show
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Testing Network Connectivity with ping:&lt;/p&gt;

&lt;p&gt;Verifies that a remote server is reachable. A successful response means the network is configured and routing correctly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ping google.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Firewall Configuration
Objective: Set up a firewall to manage incoming and outgoing traffic, limiting access only to necessary services.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Step 1: Install and Configure UFW (Ubuntu)&lt;br&gt;
Install UFW:&lt;/p&gt;

&lt;p&gt;UFW (Uncomplicated Firewall) simplifies the management of iptables-based firewall settings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install ufw
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enable UFW:&lt;/p&gt;

&lt;p&gt;Activates the firewall. You may need to confirm any prompts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw enable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Allow Traffic for Specific Services:&lt;/p&gt;

&lt;p&gt;Allowing specific services like SSH (for remote login) and HTTP/HTTPS (for web services) is crucial. UFW has predefined rules for these services:&lt;br&gt;
SSH:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw allow ssh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;HTTP (port 80):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw allow http
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;HTTPS (port 443):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw allow https
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check Status:&lt;/p&gt;

&lt;p&gt;Verifies the current firewall rules.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check Status:&lt;/p&gt;

&lt;p&gt;View the active firewall rules and settings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo firewall-cmd --list-all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Install and Configure Nginx
Objective: Install the Nginx web server and configure a basic website.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Step 1: Install Nginx&lt;br&gt;
Ubuntu:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2: Start and Enable Nginx Service&lt;br&gt;
Start Nginx:&lt;/p&gt;

&lt;p&gt;Starts the web server, making it active immediately.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl start nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3: Configure a Basic HTML Page&lt;br&gt;
Create a Test HTML File:&lt;/p&gt;

&lt;p&gt;Place an HTML page in Nginx’s default root directory (/var/www/html/). This will act as the main website.&lt;br&gt;
Create a sample file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo "&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;&amp;lt;h1&amp;gt;My Nginx Server!&amp;lt;/h1&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;" | sudo tee /var/www/html/index.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify Nginx Setup:&lt;/p&gt;

&lt;p&gt;Open a web browser and enter the server’s IP address (e.g., &lt;a href="http://192.168.1.100" rel="noopener noreferrer"&gt;http://192.168.1.100&lt;/a&gt;). You should see the "My Nginx Serve!" message if the setup is successful.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Domain Name System (DNS)
Objective: Understand DNS basics and configure the system to use specific DNS servers.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Step 1: Basic DNS Concepts&lt;br&gt;
DNS (Domain Name System): Translates domain names (like example.com) to IP addresses.&lt;br&gt;
Resolver: A DNS resolver queries name servers to get IPs for requested domain names.&lt;br&gt;
Name Servers: DNS servers that hold information about domain names and provide IP mappings.&lt;br&gt;
Step 2: Set Up a Local DNS Resolver&lt;br&gt;
Edit the /etc/resolv.conf File:&lt;/p&gt;

&lt;p&gt;Configure the system to use specific DNS servers by editing the /etc/resolv.conf file. This example sets Google’s DNS servers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nameserver 8.8.8.8
nameserver 8.8.4.4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install and Use dig for DNS Queries:&lt;/p&gt;

&lt;p&gt;Ubuntu: Install dnsutils to access dig.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install dnsutils
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use dig to check domain resolution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dig example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3: Verify DNS Settings&lt;br&gt;
Use ping to check if the server can resolve domain names, which confirms DNS configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ping google.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Basic Linux Administration</title>
      <dc:creator>Teniola </dc:creator>
      <pubDate>Wed, 13 Nov 2024 00:25:25 +0000</pubDate>
      <link>https://dev.to/tennie/basic-linux-administration-1mb8</link>
      <guid>https://dev.to/tennie/basic-linux-administration-1mb8</guid>
      <description>&lt;p&gt;Its few months into my DevOps journey, I've engaged in extensive learning, relearning, and unlearning to build a strong technical foundation. Along the way, I've worked on  various tasks and am now documenting my progress to share my learning experience. Here, I present a Basic Linux Administration task I worked on, detailing the foundational skills required for any successful devOps student.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Introduction *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This article provides a comprehensive overview of essential Linux administration and server configuration tasks, structured to build foundational skills and progress to more advanced topics. The journey begins with Basic Linux Administration, aimed at equipping users with fundamental skills like managing user accounts, file permissions, and package installations. It then transitions to Networking and Web Servers, where users will learn key networking concepts and set up a simple web server. Finally, the guide delves into Advanced Linux Server Configuration, covering deeper configurations and optimizations to enhance server performance and security. Together, these tasks offer a structured pathway for mastering Linux server management.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;User Management&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Step 1.1: Create and Manage User Accounts&lt;/p&gt;

&lt;p&gt;Create a New User&lt;/p&gt;

&lt;p&gt;To set up a new user account, the &lt;code&gt;useradd&lt;/code&gt; command is used. This creates a user with a default home directory and configuration settings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo groupadd groupname
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set a Password for the New User&lt;br&gt;
After creating the user account, &lt;code&gt;passwd&lt;/code&gt; is used to assign a password. This step is critical to ensure security by allowing only authorized access.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo passwd username
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 1.2: Set Up Password Policies&lt;/p&gt;

&lt;p&gt;Enforce Password Expiration&lt;br&gt;
To enhance security, password expiration policies are configured using chage. Setting an expiration period ensures that users regularly update their passwords.&lt;br&gt;
with this ,password expires every 90 days&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo chage -M 90 username
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify Group Membership&lt;br&gt;
The groups command allows you to verify a user’s group memberships, helping ensure correct permission assignment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;groups username
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;File System Navigation and Permissions
Step 2.1: Navigate the Linux File System
Change Directory
The cd command allows movement through directories, essential for accessing files and folders within the system.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /path/to/directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;List Directory Contents&lt;br&gt;
Using ls -l provides a detailed list of files, including permissions, which is useful for managing and auditing file access.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ls -l
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Show Current Directory Path&lt;br&gt;
pwd displays the current directory’s path, which helps verify your location in the file system.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pwd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2.2: Set File and Directory Permissions&lt;br&gt;
Change File Permissions&lt;br&gt;
The chmod command adjusts file permissions (read, write, execute) for the owner, group, and others, crucial for access control.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod 755 filename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change File Ownership&lt;br&gt;
To assign a file to a specific user or group, use chown. This step helps manage ownership, especially in multi-user environments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo chown user:group filename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check Permissions&lt;br&gt;
Running ls -l filename provides a view of the file’s current permissions, helping confirm the correct settings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ls -l filename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Package Management
Step 3.1: Install Software
Using apt (for Ubuntu)
To install software on Ubuntu/Debian, first update the package list with apt update and then use apt install to install the package.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update
sudo apt install packagename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3.2: Update Software&lt;br&gt;
Using apt&lt;br&gt;
The command apt update &amp;amp;&amp;amp; apt upgrade ensures all installed packages are up-to-date.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update &amp;amp;&amp;amp; sudo apt upgrade
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3.3: Remove Software&lt;br&gt;
Using apt&lt;br&gt;
Use apt remove to uninstall unwanted software on Ubuntu.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt remove packagename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Bash Scripting
Step 4.1: Create a Simple Bash Script (user_report.sh)
Open a New File
Use a text editor like nano or vim to create the script file.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nano user_report.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the Following Script Content&lt;br&gt;
This script generates a report displaying the number of active users and available disk space.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
echo "User Report"
echo "-----------"
echo "Number of users on the system:"
who | wc -l
echo ""
echo "Disk Space Report"
echo "-----------------"
df -h /
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save and Close the Script&lt;br&gt;
Save your changes in the editor. In nano, use CTRL+O to save and CTRL+X to exit.&lt;/p&gt;

&lt;p&gt;Step 4.2: Make the Script Executable&lt;br&gt;
Add Execute Permissions&lt;br&gt;
Make the script executable with chmod +x. This allows it to be run directly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod +x user_report.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 4.3: Run the Script&lt;br&gt;
Execute the Script&lt;br&gt;
Run the script to confirm it displays the user count and disk space information correctly.&lt;/p&gt;

&lt;p&gt;./user_report.sh&lt;/p&gt;

&lt;p&gt;Set Minimum Password Age&lt;br&gt;
The minimum password age prevents users from changing their passwords too frequently, which can disrupt security protocols&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo chage -m 1 username
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 1.3: Manage User Groups&lt;br&gt;
Create a Group&lt;br&gt;
Groups help organize users with similar permissions. To create a new group, use &lt;code&gt;groupadd&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo groupadd groupname
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add a User to a Group&lt;br&gt;
Adding a user to a group with usermod grants them the permissions associated with that group, aiding in efficient permission management.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo usermod -aG groupname username
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify Group Membership&lt;br&gt;
The groups command allows you to verify a user’s group memberships, helping ensure correct permission assignment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;groups username
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify Group Membership&lt;br&gt;
The groups command allows you to verify a user’s group memberships, helping ensure correct permission assignment.&lt;/p&gt;

&lt;p&gt;groups username&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;File System Navigation and Permissions
Step 2.1: Navigate the Linux File System
Change Directory
The cd command allows movement through directories, essential for accessing files and folders within the system.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /path/to/directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;List Directory Contents&lt;br&gt;
Using ls -l provides a detailed list of files, including permissions, which is useful for managing and auditing file access.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ls -l
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Show Current Directory Path&lt;br&gt;
pwd displays the current directory’s path, which helps verify your location in the file system.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pwd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2.2: Set File and Directory Permissions&lt;br&gt;
Change File Permissions&lt;br&gt;
The chmod command adjusts file permissions (read, write, execute) for the owner, group, and others, crucial for access control.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod 755 filename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change File Ownership&lt;br&gt;
To assign a file to a specific user or group, use chown. This step helps manage ownership, especially in multi-user environments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo chown user:group filename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check Permissions&lt;br&gt;
Running ls -l filename provides a view of the file’s current permissions, helping confirm the correct settings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ls -l filename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Package Management
Step 3.1: Install Software
Using apt (for Ubuntu)
To install software on Ubuntu/Debian, first update the package list with apt update and then use apt install to install the package.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update
sudo apt install packagename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3.2: Update Software&lt;br&gt;
Using apt&lt;br&gt;
The command apt update &amp;amp;&amp;amp; apt upgrade ensures all installed packages are up-to-date.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update &amp;amp;&amp;amp; sudo apt upgrade
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3.3: Remove Software&lt;br&gt;
Using apt&lt;br&gt;
Use apt remove to uninstall unwanted software on Ubuntu.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt remove packagename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Bash Scripting
Step 4.1: Create a Simple Bash Script (user_report.sh)
Open a New File
Use a text editor like nano or vim to create the script file.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nano user_report.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the Following Script Content&lt;br&gt;
This script generates a report displaying the number of active users and available disk space.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
echo "User Report"
echo "-----------"
echo "Number of users on the system:"
who | wc -l
echo ""
echo "Disk Space Report"
echo "-----------------"
df -h /
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save and Close the Script&lt;br&gt;
Save your changes in the editor. In nano, use CTRL+O to save and CTRL+X to exit.&lt;/p&gt;

&lt;p&gt;Step 4.2: Make the Script Executable&lt;br&gt;
Add Execute Permissions&lt;br&gt;
Make the script executable with chmod +x. This allows it to be run directly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod +x user_report.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 4.3: Run the Script&lt;br&gt;
Execute the Script&lt;br&gt;
Run the script to confirm it displays the user count and disk space information correctly.&lt;/p&gt;

&lt;p&gt;./user_report.sh&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Linux User Creation Bash Script</title>
      <dc:creator>Teniola </dc:creator>
      <pubDate>Wed, 03 Jul 2024 13:55:00 +0000</pubDate>
      <link>https://dev.to/tennie/linux-user-creation-bash-script-llg</link>
      <guid>https://dev.to/tennie/linux-user-creation-bash-script-llg</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;We can use a Bash script to automate the creation of users and groups, set up home directories, generate random passwords, and log all actions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Script Overview
&lt;/h2&gt;

&lt;p&gt;The script we're going to discuss performs the following functions:&lt;/p&gt;

&lt;p&gt;Create Users and Groups: Reads a file containing usernames and group names, creates the users and groups if they do not exist, and assigns users to the specified groups.&lt;/p&gt;

&lt;p&gt;Setup Home Directories: Sets up home directories with appropriate permissions and ownership for each user.&lt;/p&gt;

&lt;p&gt;Generate Random Passwords: Generates random passwords for the users and stores them securely.&lt;/p&gt;

&lt;p&gt;Log Actions: Logs all actions to /var/log/user_management.log for auditing and troubleshooting.&lt;/p&gt;

&lt;p&gt;Store Passwords Securely: Stores the generated passwords in /var/secure/user_passwords.csv with restricted access.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Script
&lt;/h2&gt;

&lt;p&gt;Here is the complete Bash script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash

LOG_FILE="/var/log/user_management.log"
PASSWORD_FILE="/var/secure/user_passwords.csv"

# Ensure /var/secure exists and has the correct permissions
mkdir -p /var/secure
chmod 700 /var/secure
touch "$PASSWORD_FILE"
chmod 600 "$PASSWORD_FILE"

# Function to log messages
log_message() {
    echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
}

# Function to generate random passwords
generate_password() {
    local password_length=12
    tr -dc A-Za-z0-9 &amp;lt;/dev/urandom | head -c $password_length
}

# Function to add users, groups and set up home directories
setup_user() {
    local username=$1
    local groups=$2

    # Create the user
    # &amp;amp;&amp;gt;/dev/null
    if ! id -u "$username" &amp;amp;&amp;gt;/dev/null; then
        password=$(generate_password)
        useradd -m -s /bin/bash "$username"
        echo "$username:$password" | chpasswd
        log_message "User $username created."

        # Store the username and password
        echo "$username,$password" &amp;gt;&amp;gt; "$PASSWORD_FILE"
        log_message "Password for $username stored."
    else
        log_message "User $username already exists."
    fi

    # Create groups and add user to groups
    IFS=',' read -ra group_array &amp;lt;&amp;lt;&amp;lt; "$groups"
    for group in "${group_array[@]}"; do
        if ! getent group "$group" &amp;amp;&amp;gt;/dev/null; then
            groupadd "$group"
            log_message "Group $group created."
        fi
        usermod -aG "$group" "$username"
        log_message "Added $username to $group."
    done
    # Set up the home directory
    local home_dir="/home/$username"
    chown "$username":"$username" "$home_dir"
    chmod 700 "$home_dir"
    log_message "Home directory for $username set up with appropriate permissions."
}

# Main script
if [ $# -eq 0 ]; then
    log_message "Usage: $0 &amp;lt;input_file&amp;gt;"
    exit 1
fi

input_file=$1
log_message "Starting user management script."

# Read the input file and process each line
while IFS=';' read -r username groups; do
    setup_user "$username" "$groups"
done &amp;lt; "$input_file"

log_message "User management script completed."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Logging and Password File Setup
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The script ensures that the /var/secure directory exists and has the appropriate permissions.&lt;/li&gt;
&lt;li&gt;It creates the password file /var/secure/user_passwords.csv and ensures only the owner can read it.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; /var/secure
&lt;span class="nb"&gt;chmod &lt;/span&gt;700 /var/secure
&lt;span class="nb"&gt;touch&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$PASSWORD_FILE&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;chmod &lt;/span&gt;600 &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$PASSWORD_FILE&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Message_Log
&lt;/h3&gt;

&lt;p&gt;The log_message function logs messages to /var/log/user_management.log with a timestamp.&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="nb"&gt;tee&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$LOG_FILE&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  password function
&lt;/h3&gt;

&lt;p&gt;The generate_password function generates a random password of a specified length (12 characters in this case).&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;local &lt;/span&gt;&lt;span class="nv"&gt;password_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;12
    &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; &lt;span class="nv"&gt;$password_length&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  User Setup Function
&lt;/h3&gt;

&lt;p&gt;The setup_user function creates users, adds them to groups, sets up home directories with appropriate permissions, and logs each action. It also generates and stores passwords securely.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;setup_user&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;local &lt;/span&gt;&lt;span class="nv"&gt;username&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;
    &lt;span class="nb"&gt;local groups&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;

    &lt;span class="c"&gt;# Create the user&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;!&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; &amp;amp;&amp;gt;/dev/null&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
        &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;
        useradd &lt;span class="nt"&gt;-m&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;
        &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;"User &lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="s2"&gt; created."&lt;/span&gt;

        &lt;span class="c"&gt;# Store the username and password&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="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$PASSWORD_FILE&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
        log_message &lt;span class="s2"&gt;"Password for &lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="s2"&gt; stored."&lt;/span&gt;
    &lt;span class="k"&gt;else
        &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;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Main Script
&lt;/h3&gt;

&lt;p&gt;The main part of the script takes an input file as an argument, reads it line by line, and processes each line to create users and groups, set up home directories, and log actions.&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="nv"&gt;$# &lt;/span&gt;&lt;span class="nt"&gt;-eq&lt;/span&gt; 0 &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;log_message &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;input_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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  This makes sure you run the script with an input_file, i.e input.txt
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    &lt;span class="nv"&gt;input_file&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;
    log_message &lt;span class="s2"&gt;"Starting user management script."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;To use this script, save it to a file (e.g., user_management.sh), make it executable, and run it as a root user with the path to your input file as an argument:&lt;/p&gt;

&lt;p&gt;input.txt&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    user1&lt;span class="p"&gt;;&lt;/span&gt;group1,group2
    user2&lt;span class="p"&gt;;&lt;/span&gt;group3,group4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;on the Command Line(CMD) | Terminal&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; +x user_management.sh
    ./create_users.sh input.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Talents&lt;br&gt;&lt;br&gt;
&lt;a href="https://hng.tech/internship" rel="noopener noreferrer"&gt;HNG Internship&lt;/a&gt; &lt;br&gt;
&lt;a href="https://hng.tech/hire" rel="noopener noreferrer"&gt;HNG Tech&lt;/a&gt;&lt;/p&gt;

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