Linux Advanced

πŸ” What is Linux Secure Shell (SSH)?

SSH (Secure Shell) is a safe way to remotely connect to another Linux system over a network. 🌐
It encrypts everything β€” your commands, passwords, and data β€” making it private and secure.


βœ… Why SSH is Useful:

  • πŸ’» Remote Login: Access your Linux server from anywhere

  • πŸ”’ Secure: All data is encrypted

  • πŸ§‘β€πŸ’» Control Servers: Run commands, transfer files, manage services

πŸ” How SSH Works:

  • Uses public & private keys or passwords for authentication

  • Runs on port 22 by default

  • Public Key πŸ“€: Shared with the server

  • Private Key πŸ”’: Kept secret by the user (on your computer)

βœ… Why Key’s are Important:

  • πŸ”’ High Security: Much safer than using passwords

  • 🚫 Prevents Hacking: No one can connect without the matching private key

  • πŸ€– Automation: Perfect for scripts and tools that need secure, auto-login

  • πŸ™… Passwordless Login: Just run ssh user@ip β€” no typing passwords!

πŸ§ͺ Example:

  1. You generate the key pair:

    ssh-keygen

  2. Copy the public key to the server:

    ssh-copy-id username@server-ip

  3. Then connect securely:

    ssh usernameserveur iptv

πŸ‘€ Users & πŸ‘ͺ Groups in Linux

πŸ”Ή User = A person who can log in (e.g., john, root)
πŸ”Ή Group = A collection of users with shared access

Linux uses users and groups to manage file and system permissions πŸ”

πŸ› οΈ Basic Commands:

  • Create user: sudo adduser john

  • Create group: sudo groupadd devs

  • Add user to group: sudo usermod -aG devs john

  • Check your user: whoami

  • List user’s groups: groups john

πŸ” File access is controlled by:

  • User

  • Group

  • Others

βœ… This keeps the system secure and organized!

πŸ” How to Connect to a Server via SSH

  1. Get your server details:

    • IP address (e.g., 192.168.1.10)

    • Username (e.g., ubuntu, ec2-user)

  2. Use the SSH command:ssh username@server-ip

    βœ… Example: ssh ubuntu@192.168.1.10

  3. If using a private key (like for AWS EC2):ssh -i path/to/key.pem username@server-ip

    βœ… Example:ssh -i mykey.pem ubuntu@54.123.45.67

  4. Accept the connection (first time only)

  5. πŸ” You’re in! Now you can run commands on the remote server.

πŸ”— Connect EC2 to EC2 Using SSH

βœ… 1. Make sure both EC2 instances:

  • Are in the same VPC or reachable via public IP

  • Have Security Group rules that allow SSH (port 22) from each other's IP


πŸ› οΈ 2. On Source EC2 (Instance A):

  • Have the private key (.pem) of the destination EC2 (Instance B)

πŸ’» 3. SSH from Instance A to Instance B:

ssh -i "destination-key.pem" ec2-user@<instance-a-ip>

βœ… Example:ssh -i "mykey.pem" user@<instance-a-ip>

  • Use private IP if both EC2s are in the same VPC (faster and safer)

  • Don’t forget to chmod 400 key.pem before using it!

πŸ” File Permissions in Linux

Every file and folder in Linux has permissions to control who can read, write, or run it.

πŸ‘₯ Three Types of Users:

SymbolUser TypeWho is it?
uUser (owner)The creator of the file
gGroupUsers in the same group
oOthersEveryone else

πŸ“„ Three Types of Permissions:

SymbolPermissionWhat it allows
rReadView file contents
wWriteEdit or delete the file
xExecuteRun the file like a script

πŸ” Example: Check Permissions

ls -l

You’ll see output like: -rwxr-xr-- 1 user group 1234 Jul 21 myscript.sh

Breakdown of -rwxr-xr--:

SectionMeaning
-File type (- = file, d = dir)
rwxOwner: read, write, execute
r-xGroup: read, execute
r--Others: read only

πŸ”§ chmod Command Modify Permissions

Use the chmod command:

chmod 755 myfile

This gives:

  • Owner: rwx (7)

  • Group: r-x (5)

  • Others: r-x (5)

linux File Permissions

SymbolBinaryValueMeaning
---0000No permission
--x0011Execute only
-w-0102Write only
-wx0113Write & Execute
r--1004Read only
r-x1015Read & Execute
rw-1106Read & Write
rwx1117All permissions

πŸ§ͺ Example: Make file readable & writable by owner, readable by others

chmod 644 filename

πŸ§ͺ Example: Give full access to owner, read+execute to group/others

chmod 755 filename

groupadd in Linux?

groupadd is a Linux command used to create a new group πŸ†•πŸ‘₯

Groups are used to manage permissions for multiple users together.

Command: sudo groupadd groupname

  • sudo: Run as superuser (you need admin rights to create a group)

  • groupadd: Command to add a new group

  • groupname: The name of the group you want to create

Add a user to the group

sudo usermod -aG devteam username

βœ… This allows username to become a member of devteam

πŸ”Ή sudo chown β€” Change File Owner

The chown command lets you change the owner of a file or folder.

🧩 Syntax: sudo chown new_owner filename

βœ… Example: sudo chown john report.txt

🎯 Now user john owns the file report.txt

πŸ”Έ sudo chgrp β€” Change File Group

The chgrp command lets you change only the group of a file or folder.

🧩 Syntax: sudo chgrp groupname filename

βœ… Example: sudo chgrp devteam report.txt

🎯 Now the file belongs to the group devteam

πŸ› οΈ Why use these?

πŸ” For controlling who can access or modify files
πŸ‘¨β€πŸ‘©β€πŸ‘§ Helps in multi-user environments like servers

πŸ” grep – Search for text

Used to find matching words/lines in a file.

grep "apple" fruits.txt

βœ… Shows all lines with the word apple.

πŸ“Š awk – Extract specific columns

Used to print selected fields (columns) from text.

awk '{print $1}' data.txt

βœ… Prints the first word (or column) of each line.

πŸ‘‰ Combine with grep:

grep "apple" fruits.txt | awk '{print $2}'

βœ… Finds lines with "apple" and shows their second column.

πŸ› οΈ sed – Stream Editor

Used for searching and replacing text.

sed 's/old/new/' filename.txt

βœ… Replaces first 'old' with 'new' in each line.

πŸ‘‰ Replace all:

sed 's/old/new/g' filename.txt

πŸ” find Command in Linux

The find command is used to search for files and directories in your Linux system based on name, size, date, type, etc. πŸ”ŽπŸ“

βœ… Basic Syntax: find [path] [options] [expression]

🌐 1. ping – Check if a host is reachable

ping google.com

πŸ“‘ Sends ICMP packets to check if a server is online and how long it takes to respond.

βœ… Use: Test network connection
πŸ§ͺ Output: Response time (ms), packet loss

🌍 2. traceroute – Trace path of packets to a destination

traceroute google.com

🧭 Shows every hop (router) your packet passes through to reach the destination.

βœ… Use: Find slow or failing network points
πŸ” Output: Each step & delay in reaching a server

πŸ•΅οΈ 3. nslookup – Query DNS records

nslookup google.com

πŸ“– Asks DNS servers for info like IP addresses of a domain.

βœ… Use: Check domain name resolution
🌐 Output: IP address of a domain

🧠 4. dig – Advanced DNS lookup tool

dig google.com

πŸ§ͺ Similar to nslookup but gives more detailed DNS info (like TTL, record types, etc.)

βœ… Use: Deep dive into DNS records (A, MX, TXT, etc.)

πŸ“₯ 5. wget – Download files from the web

wget https://example.com/file.txt

πŸ“‚ Saves files from the internet directly to your system.

βœ… Use: Script-based or bulk file downloads
πŸ’‘ Add -O filename to rename it while saving

🌐 6. curl – Transfer data from/to a server

curl https://example.com

🧰 Can download data, send forms, or access APIs. More flexible than wget.

βœ… Use: Web testing, APIs, downloading
πŸ”„ Supports GET, POST, PUT, DELETE, etc.

1
Subscribe to my newsletter

Read articles from sarvesh chaudhari directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

sarvesh chaudhari
sarvesh chaudhari