Skip to main content

Command Palette

Search for a command to run...

Linux Administration, AWS AMI, and Shell Scripting Basics for Beginners ๐Ÿš€

Updated
โ€ข5 min read
Linux Administration, AWS AMI, and Shell Scripting Basics for Beginners ๐Ÿš€

Linux and AWS are among the most important technologies in the DevOps world. Understanding concepts like Amazon Machine Images (AMI), EBS Volumes, Nginx deployment, and Shell Scripting can help beginners build a strong foundation in Linux Administration and Cloud Computing.

In this article, we'll explore these concepts step by step with practical examples.


๐Ÿ“Œ What is AMI (Amazon Machine Image)?

An Amazon Machine Image (AMI) is a pre-configured template that contains:

  • Operating System

  • Application Server

  • Installed Software

  • Configurations

AMI allows us to create multiple EC2 instances with the same configuration whenever required.

Why Use AMI?

  • Faster server deployment

  • Backup of configured instances

  • Easy scaling

  • Consistent environments


๐Ÿš€ Creating an AMI from an EC2 Instance

Suppose you have already launched an EC2 instance and deployed a website.

Step 1: Launch an EC2 Instance

Create an EC2 instance using Ubuntu or Amazon Linux.


Step 2: Attach an EBS Volume

Attach a 20GB EBS Volume to the instance.

Verify attached storage:

lsblk

Check mounted filesystems:

df -h

Step 3: Install Nginx

Update packages:

sudo apt update

Install Nginx:

sudo apt install nginx -y

Check Nginx status:

sudo systemctl status nginx

Enable Nginx:

sudo systemctl enable nginx

Step 4: Deploy a Web Page

Navigate to:

cd /var/www/html

Create or modify:

sudo nano index.html

Add sample HTML content and save.


Step 5: Configure Security Group

Allow HTTP traffic.

Inbound Rule

Type Port Source
HTTP 80 Anywhere (0.0.0.0/0)

Save the rules.


Step 6: Verify Website

Copy the Public IP of the EC2 instance.

Open browser:

http://<public-ip>

You should see the Nginx webpage.


๐Ÿ–ผ๏ธ Creating an AMI

After configuring the server:

Steps:

  1. Select EC2 Instance

  2. Click Actions

  3. Select Image and Templates

  4. Click Create Image

  5. Enter Image Name

  6. Add additional volume if required

  7. Click Create Image

AWS will take some time to generate the AMI.


๐Ÿš€ Launching a New Instance from AMI

  1. Open AMIs

  2. Select your created AMI

  3. Click Launch Instance

  4. Choose Key Pair

  5. Configure instance details

  6. Launch

The new instance will have:

  • Nginx installed

  • Website deployed

  • Attached configurations preserved

This is useful for backup and scaling purposes.


๐Ÿš Introduction to Shell Scripting

Shell scripting automates repetitive Linux tasks.

A shell script is a text file containing Linux commands.

Create Script

touch user.sh

Edit:

nano user.sh

Structure of a Shell Script

#!/bin/bash

echo "Hello World"

Give Execute Permission

chmod 777 user.sh

Run:

./user.sh

๐Ÿ‘ค Creating a User Using Shell Script

#!/bin/bash

read -p "Enter Username: " name

sudo useradd -m $name

echo "User Created Successfully"

๐Ÿ“ Creating Files and Folders Using User Input

#!/bin/bash

read -p "Enter file name: " file

touch $file

Folder Creation

#!/bin/bash

read -p "Enter folder name: " folder

mkdir $folder

๐Ÿ” Creating Folder and Assigning Permissions

#!/bin/bash

read -p "Enter folder name: " folder

mkdir $folder

chmod 777 $folder

echo "Folder Created Successfully"

Permission Meaning

Value Permission
7 Read + Write + Execute
6 Read + Write
5 Read + Execute
4 Read Only

๐Ÿ”€ Conditional Statements in Shell Scripting

Conditional statements allow decision-making.

Example

#!/bin/bash

read -p "Enter Name: " name
read -p "Enter Percentage: " per

if [[ $name == "linux" ]]
then
    echo "Approved"

elif [[ $per -ge 100 ]]
then
    echo "Accepted"

else
    echo "Rejected"
fi

๐ŸŽ“ Grade Calculator Using If-Else

#!/bin/bash

read -p "Enter Marks: " mark

if [[ $mark -ge 90 ]]
then
    echo "Grade A"

elif [[ $mark -ge 80 ]]
then
    echo "Grade B"

elif [[ $mark -ge 70 ]]
then
    echo "Grade C"

else
    echo "Grade D"
fi

Sample Output

Enter Marks: 85
Grade B

โš™๏ธ Using Functions in Shell Script

Functions improve code reusability.

Example

#!/bin/bash

user_validation() {

read -p "Enter Name: " name
read -p "Enter Percentage: " per

if [[ $name == "linux" ]]
then
    echo "Approved"

elif [[ $per -ge 100 ]]
then
    echo "Accepted"

else
    echo "Rejected"
fi

}

user_validation

๐ŸŽฏ Conclusion

Learning Linux Administration and AWS basics is a great starting point for a DevOps career. In this article, we covered:

โœ… AMI Creation and Usage โœ… EBS Volume Attachment and Mounting โœ… Unmounting Volumes Safely โœ… Nginx Installation and Deployment โœ… Security Group Configuration โœ… Shell Scripting Basics โœ… User Creation Automation โœ… File and Folder Management โœ… Conditional Statements โœ… Functions in Shell Scripts

Mastering these fundamentals will help you automate tasks, manage cloud infrastructure, and build scalable environments efficiently.

Happy Learning! ๐Ÿš€๐Ÿงโ˜๏ธ