A Beginner’s Guide to Linux, SSH, and Bash Scripting

 🐧 Linux Basics, SSH, SCP & Bash Scripting – A Beginner-Friendly Guide

If you are starting your journey into Linux or DevOps, understanding basic Linux commands, SSH connections, file transfers, and shell scripting is a must.
This blog walks you step-by-step through essential Linux commands, connecting to a Linux server, and writing your first Bash script.


🔹 1. Basic Linux Commands

Check Current User

whoami

Displays the username of the currently logged-in user.


Create a File

touch merifile.txt

Creates an empty file named merifile.txt.


List Files and Directories

ls

For a detailed view:

ls -la

Shows file permissions, owner, size, and hidden files.


Present Working Directory

pwd

Displays the current directory path.


Create and Navigate Directories

mkdir TWG cd TWG

Go one step back:

cd ..

Move Files

mv ../merifile.txt .

Moves merifile.txt from the parent directory to the current directory.


Clear the Terminal

clear

🔹 2. Editing Files Using Nano

Open a file:

nano merifile.txt

Add content:

Hi This is Ghouse and definitely attend my 1pm Sunday session.

Save and exit:

  • Ctrl + X

  • Press Y

  • Press Enter

View file content:

cat merifile.txt

🔹 3. Useful Linux Commands

Print Output

echo "hello world"

Command History

history

Shows all commands used so far.


Remove a File

rm filename

⚠️ Be careful: deleted files cannot be recovered easily.


Go to Home Directory

cd

🔹 4. SSH – Secure Shell Protocol

SSH is used to securely connect to a remote Linux server.

Requirements

  • A private key (.pem file)

  • Server username

  • Server public IP or DNS


Connect to a Linux Server

Assume your key is downloaded to:

Downloads/keys
cd Downloads/keys ssh -i OurKey.pem ubuntu@ec2-65-78-69-99.eu-west-1.compute.amazonaws.com

➡ This connects to the server using:

  • Username: ubuntu

  • Authentication: private key


🔹 5. SCP – Secure Copy Protocol

Used to transfer files between local machine and server.

Copy File from Local to Server

scp -i sk-key.pem from_local.txt ubuntu@ec2-54-xx.compute.aws.com:/home/ubuntu/newfolder/

Copy File from Server to Local

scp -i sk-key.pem ubuntu@ec2-54-xx.compute.aws.com:/home/ubuntu/newfolder/merifile.txt .

📌 Note:
SCP commands are always executed from your local Linux machine, not inside EC2.


🔹 6. Bash Scripting Basics

Shebang Line

#!/bin/bash

Tells the system to use Bash shell to run the script.


Create Scripts Folder

mkdir scripts cd scripts

Check which bash is used:

which bash

Create First Script

nano devops_first.sh

Script content:

#!/bin/bash echo "This is Ghouse"

Run the script:

bash devops_first.sh

Make Script Executable

chmod 777 devops_first.sh ./devops_first.sh

🔹 7. Interactive Bash Script Example

Create Script

nano onescript.sh

Script Code

#!/bin/bash echo "I will be a great DevOps engineer" name="Ghouse" echo "Hello ${name}, please enter your age" read age echo "My age is ${age}" echo "Apka swagat hai DevopsByGhouse channel pe" sleep 2 echo "Please subscribe"

Make it executable:

chmod +x onescript.sh ./onescript.sh

🔹 8. Script with Arguments

#!/bin/bash echo "I will be a great DevOps engineer" echo "Sub: Hello, I am $1" sleep 2 echo "Welcome to DevopsByGhouse"

Run:

./onescript.sh Adnan

Output:

Sub: Hello, I am Adnan

🔹 9. Conditional Statements in Bash

#!/bin/bash if [ "$1" = "like" ] then echo "Please like the channel" else echo "Please subscribe" fi

Run:

./onescript.sh like

Comments

Popular posts from this blog

Managing Amazon EBS Volumes and Snapshots Across Regions

Git for Beginners: Complete Guide from Installation to First Push on GitHub

AWS - Amazon Web Services