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:
You generate the key pair:
ssh-keygen
Copy the public key to the server:
ssh-copy-id username@server-ip
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
Get your server details:
IP address (e.g.,
192.168.1.10
)Username (e.g.,
ubuntu
,ec2-user
)
Use the SSH command:ssh username@server-ip
β Example: ssh ubuntu@192.168.1.10
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
Accept the connection (first time only)
π 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:
Symbol | User Type | Who is it? |
u | User (owner) | The creator of the file |
g | Group | Users in the same group |
o | Others | Everyone else |
π Three Types of Permissions:
Symbol | Permission | What it allows |
r | Read | View file contents |
w | Write | Edit or delete the file |
x | Execute | Run 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--
:
Section | Meaning |
- | File type (- = file, d = dir) |
rwx | Owner: read, write, execute |
r-x | Group: 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
Symbol | Binary | Value | Meaning |
--- | 000 | 0 | No permission |
--x | 001 | 1 | Execute only |
-w- | 010 | 2 | Write only |
-wx | 011 | 3 | Write & Execute |
r-- | 100 | 4 | Read only |
r-x | 101 | 5 | Read & Execute |
rw- | 110 | 6 | Read & Write |
rwx | 111 | 7 | All 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 groupgroupname
: 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.
Subscribe to my newsletter
Read articles from sarvesh chaudhari directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
