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
Displays the username of the currently logged-in user.
Create a File
Creates an empty file named merifile.txt.
List Files and Directories
For a detailed view:
Shows file permissions, owner, size, and hidden files.
Present Working Directory
Displays the current directory path.
Create and Navigate Directories
Go one step back:
Move Files
Moves merifile.txt from the parent directory to the current directory.
Clear the Terminal
🔹 2. Editing Files Using Nano
Open a file:
Add content:
Save and exit:
-
Ctrl + X -
Press
Y -
Press
Enter
View file content:
🔹 3. Useful Linux Commands
Print Output
Command History
Shows all commands used so far.
Remove a File
⚠️ Be careful: deleted files cannot be recovered easily.
Go to Home Directory
🔹 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:
➡ 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
Copy File from Server to Local
📌 Note:
SCP commands are always executed from your local Linux machine, not inside EC2.
🔹 6. Bash Scripting Basics
Shebang Line
Tells the system to use Bash shell to run the script.
Create Scripts Folder
Check which bash is used:
Create First Script
Script content:
Run the script:
Make Script Executable
🔹 7. Interactive Bash Script Example
Create Script
Script Code
Make it executable:
🔹 8. Script with Arguments
Run:
Output:
🔹 9. Conditional Statements in Bash
Run:
Comments
Post a Comment