linux tutorials
linux tutorials
1. Question:
What is the difference between a Hard Link and a Soft Link in Linux?
2. Answer:
○ Hard Link: A hard link is a mirror copy of the original file. It shares the same inode
number as the original file. Deleting the original file doesn’t affect the hard link.
○ Soft Link (Symbolic Link): A soft link is more like a shortcut that points to the original
file. It has a different inode number and if the original file is deleted, the soft link
becomes broken (dangling link).
3. What Skills Required to Prepare This Question:
Unset
# Create a file
touch file1.txt
# Check inodes
ls -li
Unset
# Check overall disk usage
df -h
2. Answer:
The Linux boot process consists of several stages:
Unset
# View boot log
dmesg | less
2. Answer:
Service management in Linux depends on the init system:
○ Practice starting, stopping, and enabling services using systemctl and service
commands
○ Learn the differences between systemd and SysVinit
○ Understand how to debug failed services using logs (journalctl)
5. Examples for This Question:
Unset
# Start and enable Apache service
journalctl -u apache2
Question 5: What are file permissions in Linux and how do you modify them?
1. Question:
What are file permissions in Linux and how do you modify them?
2. Answer:
Linux file permissions are divided into three types:
Unset
# View file permissions
ls -l
# Set read, write, execute for user, read and execute for group and
others
2. Answer:
Linux offers several tools for scheduling tasks:
Unset
# Schedule a cron job to run every day at 2 AM
crontab -e
0 2 * * * /path/to/script.sh
crontab -l
2. Answer:
You can check running processes using the following commands:
Unset
# List all processes
ps aux
# Display real-time processes
top
htop
pgrep nginx
pstree
2. Answer:
Linux provides commands for user and group management:
○ User Management:
■ Add a user: useradd username
■ Delete a user: userdel username
■ Modify a user: usermod
■ Set password: passwd username
○ Group Management:
■ Add a group: groupadd groupname
■ Delete a group: groupdel groupname
■ Add user to a group: usermod -aG groupname username
○ User and group information is stored in /etc/passwd, /etc/group, and
/etc/shadow.
3. What Skills Required to Prepare This Question:
○ Understanding of Linux user and group management
○ Familiarity with permission models and file ownership
○ Proficiency with related command-line tools
4. How to Study This Question:
Unset
# Add a new user
# List users
cat /etc/passwd
# List groups
cat /etc/group
Unset
# Enable UFW firewall
# Set PermitRootLogin no
2. Answer:
You can monitor system performance using several built-in and third-party tools:
Unset
# Real-time CPU and memory usage
top
iostat
iftop
vmstat 5
htop
2. Answer:
There are multiple tools to configure firewalls in Linux:
Unset
# UFW example
# iptables example
sudo iptables -L
# firewalld example
Question 12: How do you mount and unmount file systems in Linux?
1. Question:
How do you mount and unmount file systems in Linux?
2. Answer:
Mounting and unmounting file systems can be done using the following commands:
Unset
# Mount a disk
# Unmount a disk
sudo umount /mnt/data
df -h
# Example line
2. Answer:
Network issues can be diagnosed using several tools:
Unset
# Check network interfaces
ip addr
ping google.com
traceroute google.com
dig openai.com
Unset
# Check overall disk usage
df -h
du -sh /var/log
Question 15: How do you create and manage symbolic and hard links in Linux?
1. Question:
How do you create and manage symbolic and hard links in Linux?
2. Answer:
Linux supports two types of links:
○ Hard Links:
■ Point directly to the inode of a file
■ Cannot span across file systems
■ Created using: ln source_file link_name
○ Symbolic (Soft) Links:
■ Point to the path of the target file
■ Can link directories and cross file systems
■ Created using: ln -s source_file link_name
3. Managing Links:
ln original.txt hardlink.txt
ln -s /var/www/html website_link
# View links
ls -l
readlink website_link
# Remove a link
rm hardlink.txt
2. Answer:
Cron is a time-based job scheduler in Linux used to run scripts and commands at specified
intervals.
○ Edit crontab:
■ crontab -e to edit the user's cron jobs
■ crontab -l to list existing cron jobs
■ crontab -r to remove all cron jobs
○ Cron Syntax:
■ * * * * * /path/to/command
■ Format: minute hour day month day_of_week command
○ System-Wide Cron Jobs:
■ Placed in /etc/crontab or /etc/cron.d/
○ Logs:
■ Cron logs can be found in /var/log/syslog or /var/log/cron
3. What Skills Required to Prepare This Question:
Unset
# Edit user's crontab
crontab -e
0 0 * * * /home/user/backup.sh
crontab -l
Question 17: How do you configure SSH for secure remote access?
1. Question:
How do you configure SSH for secure remote access?
2. Answer:
SSH (Secure Shell) allows secure remote login and command execution.
○ Basic Setup:
■ Install SSH: sudo apt install openssh-server
■ Start service: sudo systemctl start ssh
○ Security Enhancements:
■ Disable root login:
■ Edit /etc/ssh/sshd_config: PermitRootLogin no
■ Use SSH Keys:
■ Generate key: ssh-keygen
■ Copy key to server: ssh-copy-id user@server
■ Change default port:
■ Edit /etc/ssh/sshd_config: Port 2222
○ Restart SSH Service:
■ sudo systemctl restart ssh
3. What Skills Required to Prepare This Question:
Unset
# Install SSH server
ssh-keygen
# Set PermitRootLogin no
2. Answer:
Systemd is a system and service manager for Linux.
Unset
# Start and enable nginx service
journalctl -u nginx
# Disable a service
2. Answer:
Linux uses a permission model with three sets of permissions: user (owner), group, and
others.
○ View Permissions:
■ ls -l filename shows permissions (e.g., -rwxr-xr--)
○ Change Permissions with chmod:
■ Symbolic Mode: chmod u+x script.sh (add execute for user)
■ Numeric Mode: chmod 755 script.sh
■ 7 = read + write + execute (rwx)
■ 5 = read + execute (r-x)
■ 5 = read + execute (r-x)
○ Change Ownership with chown:
■ sudo chown user:group file
○ Change Group with chgrp:
■ sudo chgrp groupname file
3. What Skills Required to Prepare This Question:
Unset
# View permissions
ls -l file.txt
Question 20: How do you configure NFS (Network File System) in Linux?
1. Question:
How do you configure NFS (Network File System) in Linux?
2. Answer:
NFS allows file sharing between Linux systems over a network.
Unset
# On NFS server - configure exports
echo "/srv/nfs 192.168.1.0/24(rw,sync,no_subtree_check)" | sudo tee -a
/etc/exports
sudo exportfs -a
# Verify mount
df -h | grep nfs
2. Answer:
Linux provides several commands to manage users and groups:
○ Create User:
■ sudo useradd -m username (creates user with home directory)
■ Set password: sudo passwd username
○ Modify User:
■ sudo usermod -aG groupname username (add user to a group)
■ sudo usermod -s /bin/bash username (change default shell)
○ Delete User:
■ sudo userdel -r username (removes user and home directory)
○ Manage Groups:
■ Create group: sudo groupadd groupname
■ Delete group: sudo groupdel groupname
■ Change group ownership: sudo chgrp groupname file
3. What Skills Required to Prepare This Question:
○ Understanding of Linux user/group management
○ Familiarity with system permissions and file ownership
○ Knowledge of user security policies
4. How to Study This Question:
Unset
# Create a new user with a home directory
2. Answer:
Linux provides several tools to monitor system performance:
Unset
# Monitor CPU and memory
top
iostat
iftop
tail -f /var/log/syslog
Question 23: How do you configure a firewall in Linux using iptables or firewalld?
1. Question:
How do you configure a firewall in Linux using iptables or firewalld?
2. Answer:
Linux firewalls can be configured using iptables or firewalld.
○ Using firewalld:
■ Start/enable firewalld: sudo systemctl enable --now firewalld
■ Check status: sudo firewall-cmd --state
■ Allow a port: sudo firewall-cmd --permanent --add-port=80/tcp
■ Reload firewall: sudo firewall-cmd --reload
○ Using iptables:
■ Allow traffic on port 22 (SSH): sudo iptables -A INPUT -p tcp --dport
22 -j ACCEPT
■ Drop all other incoming traffic: sudo iptables -P INPUT DROP
■ List rules: sudo iptables -L -v
■ Save rules: sudo iptables-save > /etc/iptables/rules.v4
3. What Skills Required to Prepare This Question:
Unset
# Using firewalld - allow HTTP traffic
sudo iptables -L -v
2. Answer:
RAID (Redundant Array of Independent Disks) improves performance and redundancy.
○ Install mdadm:
■ sudo apt install mdadm
○ Create RAID Array:
■ Example for RAID 1 (mirroring):
sudo mdadm --create --verbose /dev/md0 --level=1
--raid-devices=2 /dev/sd[b-c]
○ Check RAID Status:
■ cat /proc/mdstat
■ sudo mdadm --detail /dev/md0
○ Create File System and Mount:
■ sudo mkfs.ext4 /dev/md0
■ sudo mount /dev/md0 /mnt/raid
○ Save Configuration:
■ sudo mdadm --detail --scan | sudo tee -a
/etc/mdadm/mdadm.conf
■ Update initramfs: sudo update-initramfs -u
3. What Skills Required to Prepare This Question:
Unset
# Install mdadm
cat /proc/mdstat
sudo mdadm --detail /dev/md0
2. Answer:
Linux offers several tools to diagnose and troubleshoot network problems:
Unset
# Check IP address and network interfaces
ip addr
ping google.com
ip route
cat /etc/resolv.conf
ss -tuln
Question 26: How do you create and manage logical volumes using LVM?
1. Question:
How do you create and manage logical volumes using LVM in Linux?
2. Answer:
LVM (Logical Volume Manager) allows flexible disk management.
Unset
# Create physical volumes
2. Answer:
Securing a Linux server involves multiple layers of protection:
Unset
# Disable root SSH login
2. Answer:
Passwordless SSH allows users to authenticate using SSH keys instead of passwords.
Unset
cat ~/.ssh/id_rsa.pub | ssh user@remote_server 'cat >>
~/.ssh/authorized_keys'
Unset
chmod 700 ~/.ssh
ssh-copy-id [email protected]
Question 29: How do you manage and schedule tasks using cron in Linux?
1. Question:
How do you manage and schedule tasks using cron in Linux?
2. Answer:
Cron is a time-based job scheduler in Unix-like systems.
○ Edit Crontab:
■ crontab -e to edit the user's crontab file.
○ Crontab Syntax:
Unset
* * * * * command_to_execute
| | | | |
Unset
# Open crontab
crontab -e
# Example jobs:
0 2 * * * /home/user/backup.sh
0 0 * * 0 rm -rf /tmp/*
Question 30: How do you recover a Linux system with a forgotten root password?
1. Question:
How do you recover a Linux system with a forgotten root password?
2. Answer:
To reset a forgotten root password:
Unset
# After booting into single-user mode
mount -o remount,rw /
# Reset root password
passwd root
reboot
2. Answer:
Static IP configuration depends on the Linux distribution.
On Debian/Ubuntu-based systems:
Unset
sudo nano /etc/network/interfaces
Unset
auto eth0
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
○ Restart networking:
Unset
sudo systemctl restart networking
3.
On RHEL/CentOS-based systems:
Unset
sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
○ Update with:
Unset
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
Unset
sudo systemctl restart network
4.
What Skills Required to Prepare This Question:
Unset
# Check current IP configuration
ip addr
# Verify static IP
ping google.com
2. Answer:
Linux offers several tools to monitor system performance:
○ CPU Usage:
Unset
# Monitor CPU and memory
top
df -h
iftop
# Monitor overall system health
glances
2. Answer:
iptables is a command-line firewall tool in Linux.
Unset
sudo iptables -L -v
○
Basic Commands:
Unset
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
Unset
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
■ Block an IP address:
Unset
sudo iptables -A INPUT -s 192.168.1.50 -j DROP
■ Drop all other incoming traffic:
Unset
sudo iptables -P INPUT DROP
○
Save and Persist Rules:
■ On Debian/Ubuntu:
Unset
sudo iptables-save > /etc/iptables/rules.v4
■ On CentOS/RHEL:
Unset
sudo service iptables save
3.
What Skills Required to Prepare This Question:
Unset
# Allow SSH and HTTP
# View rules
sudo iptables -L -v
2. Answer:
systemd is a system and service manager for Linux, controlling how services run.
○ Start/Stop/Restart a Service:
Unset
sudo systemctl start apache2
○
Enable/Disable Service at Boot:
Unset
sudo systemctl enable apache2
○
Check Service Status:
Unset
sudo systemctl status apache2
○
Reload Systemd and Daemons:
Unset
sudo systemctl daemon-reload
○
List All Services:
Unset
systemctl list-units --type=service
3.
What Skills Required to Prepare This Question:
# Check status
Question 35: How do you configure NFS (Network File System) in Linux?
1. Question:
How do you configure NFS (Network File System) in Linux?
2. Answer:
NFS allows file sharing between Linux systems over a network.
On NFS Server:
○ Install NFS:
Unset
sudo apt install nfs-kernel-server # Debian/Ubuntu
Unset
sudo mkdir -p /srv/nfs/shared
sudo chown nobody:nogroup /srv/nfs/shared
Unset
sudo nano /etc/exports
/srv/nfs/shared 192.168.1.0/24(rw,sync,no_subtree_check)
Unset
sudo exportfs -a
3.
On NFS Client:
Unset
sudo apt install nfs-common # Debian/Ubuntu
Unset
sudo mount 192.168.1.100:/srv/nfs/shared /mnt
4.
What Skills Required to Prepare This Question:
Unset
# Server-side
sudo exportfs -v
# Client-side
# Verify mount
df -h | grep nfs
2. Answer:
RAID (Redundant Array of Independent Disks) enhances storage performance and redundancy.
○ Install mdadm (RAID utility):
Unset
sudo apt install mdadm # Debian/Ubuntu
○
Create RAID Array (e.g., RAID 1):
Unset
sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2
/dev/sd[b-c]
○
Verify RAID Status:
Unset
cat /proc/mdstat
○
Create Filesystem and Mount:
Unset
sudo mkfs.ext4 /dev/md0
○
Persist RAID Configuration:
Unset
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
sudo update-initramfs -u
3.
What Skills Required to Prepare This Question:
Unset
# Create RAID 5 with 3 disks
cat /proc/mdstat
Question 37: How do you set file permissions using chmod in Linux?
1. Question:
How do you set file permissions using chmod in Linux?
2. Answer:
The chmod command changes file and directory permissions in Linux.
○ Symbolic Method:
Unset
chmod u+rwx file.txt
Unset
chmod g-w file.txt
Unset
chmod o+x script.sh
○
Numeric Method:
Permissions use a three-digit octal representation:
■ r = 4, w = 2, x = 1
■ Example: chmod 755 script.sh sets:
■ Owner: read, write, execute (7)
■ Group: read, execute (5)
■ Others: read, execute (5)
○ Recursive Permission Change:
Unset
chmod -R 755 /var/www/html
3.
What Skills Required to Prepare This Question:
Unset
# Grant read, write to owner, read-only to others
2. Answer:
Linux provides several commands for managing users and groups.
○
Delete a User:
Unset
sudo deluser john
○
Modify a User (e.g., change shell):
Unset
sudo usermod -s /bin/bash john
○
Add User to a Group:
Unset
sudo usermod -aG sudo john
○
Create a Group:
Unset
sudo groupadd developers
○
Change File Ownership:
Unset
sudo chown john:developers project.txt
○
List User and Group Info:
Unset
id john
groups john
3.
What Skills Required to Prepare This Question:
Unset
# Add user and grant sudo privileges
2. Answer:
Several tools help diagnose and fix network problems in Linux.
○ Check IP Configuration:
Unset
ip addr
○
Test Connectivity:
Unset
ping google.com
○
Check Routing Table:
Unset
ip route
○
DNS Resolution Issues:
Unset
dig google.com
nslookup google.com
○
Trace Network Path:
Unset
traceroute google.com
○
Check Open Ports and Connections:
Unset
netstat -tuln
○
Monitor Network Traffic:
Unset
tcpdump -i eth0
3.
What Skills Required to Prepare This Question:
telnet google.com 80
2. Answer:
UFW (Uncomplicated Firewall) simplifies firewall management on Linux.
Unset
sudo apt install ufw
○
Enable/Disable UFW:
Unset
sudo ufw enable
sudo ufw disable
○
Allow/Deny Ports:
Unset
sudo ufw allow 22/tcp # Allow SSH
○
Allow Specific IP:
Unset
sudo ufw allow from 192.168.1.100
○
Delete a Rule:
Unset
sudo ufw delete allow 80/tcp
○
View Firewall Status and Rules:
Unset
sudo ufw status verbose
3.
What Skills Required to Prepare This Question:
Unset
# Allow HTTPS traffic
2. Answer:
Cron is a time-based job scheduler in Unix-like systems.
○
Cron Syntax:
Unset
* * * * * /path/to/command
| | | | |
○
View Scheduled Cron Jobs:
Unset
crontab -l
○
Remove All Cron Jobs for User:
Unset
crontab -r
○
Common Examples:
Unset
0 0 * * 0 /usr/bin/logrotate
3.
What Skills Required to Prepare This Question:
Unset
# Run a script every 15 minutes
*/15 * * * * /path/to/script.sh
0 1 * * 0 /sbin/reboot
2. Answer:
Linux offers several tools to monitor system performance.
Unset
top
○
Disk Usage:
Unset
df -h # Show disk space
○
I/O Performance:
Unset
iostat
vmstat
○
Network Performance:
Unset
iftop # Real-time network usage
Unset
uptime # Shows load average
cat /proc/loadavg
3.
What Skills Required to Prepare This Question:
Unset
# Check memory usage
free -m
iostat -xz 1
iftop -i eth0
Question 43: How do you secure SSH access on a Linux server?
1. Question:
How do you secure SSH access on a Linux server?
2. Answer:
Securing SSH is crucial to prevent unauthorized access.
Unset
Port 2222
○
Then restart SSH:
Unset
sudo systemctl restart sshd
○
Disable Root Login:
In /etc/ssh/sshd_config:
Unset
PermitRootLogin no
○
Use SSH Key Authentication:
Generate SSH key pair on client:
Unset
ssh-keygen
○
Copy public key to server:
Unset
ssh-copy-id user@server_ip
○
Use a Firewall to Limit Access:
Unset
sudo ufw allow 2222/tcp
○
Disable Password Authentication:
In /etc/ssh/sshd_config:
Unset
PasswordAuthentication no
3.
What Skills Required to Prepare This Question:
Unset
# Connect to SSH on a custom port
2. Answer:
Disk partitioning can be done using tools like fdisk, parted, and lsblk.
Unset
lsblk
fdisk -l
○
Create a New Partition Using fdisk:
Unset
sudo fdisk /dev/sdb
○
Mount the Partition:
Unset
sudo mkdir /mnt/newdisk
○
Make the Mount Permanent:
Add to /etc/fstab:
Unset
/dev/sdb1 /mnt/newdisk ext4 defaults 0 2
3.
What Skills Required to Prepare This Question:
Unset
# Check disk space usage
df -h
# Check partition UUID
blkid
Question 45: How do you set up NFS (Network File System) on Linux?
1. Question:
How do you set up NFS (Network File System) on Linux?
2. Answer:
NFS allows sharing directories over a network.
Unset
sudo apt install nfs-kernel-server nfs-common
○
Configure NFS Exports:
Edit /etc/exports:
Unset
/srv/nfs/shared 192.168.1.0/24(rw,sync,no_subtree_check)
○
Apply Export Changes:
Unset
sudo exportfs -a
○
Allow NFS Through Firewall:
Unset
sudo ufw allow from 192.168.1.0/24 to any port nfs
○
Mount NFS Share on Client:
Unset
sudo mount server_ip:/srv/nfs/shared /mnt
○
Make Mount Permanent on Client:
Add to /etc/fstab:
Unset
server_ip:/srv/nfs/shared /mnt nfs defaults 0 0
3.
What Skills Required to Prepare This Question:
showmount -e server_ip
2. Answer:
RAID (Redundant Array of Independent Disks) can be configured using the mdadm tool.
○ Install mdadm:
Unset
sudo apt install mdadm
○
Create a RAID 1 Array (Mirroring):
Unset
sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2
/dev/sd[b-c]1
○
Verify RAID Status:
Unset
cat /proc/mdstat
○
Format the RAID Array:
Unset
sudo mkfs.ext4 /dev/md0
○
Mount the RAID Array:
Unset
sudo mkdir /mnt/raid
○
Save RAID Configuration:
Unset
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
sudo update-initramfs -u
3.
What Skills Required to Prepare This Question:
Unset
# Create RAID 0 (striping)
2. Answer:
SELinux (Security-Enhanced Linux) adds a security layer through mandatory access control.
Unset
sestatus
getenforce
○
Set SELinux Modes:
Unset
sudo setenforce 0 # Permissive
○
Change mode permanently (edit /etc/selinux/config):
Unset
SELINUX=enforcing
SELINUX=permissive
SELINUX=disabled
○
Manage SELinux Contexts:
Unset
ls -Z /var/www/html
○
Manage Policies with semanage:
Unset
sudo semanage port -a -t http_port_t -p tcp 8080
3.
What Skills Required to Prepare This Question:
Unset
# Allow Apache to connect to the network
getsebool -a
2. Answer:
Linux has multiple package managers based on the distribution.
○ Debian/Ubuntu (APT):
Unset
sudo apt update
■ Install a package:
Unset
sudo apt install nginx
■ Remove a package:
Unset
sudo apt remove nginx
Unset
sudo apt upgrade
○
RedHat/CentOS (YUM/DNF):
■ Install a package:
Unset
sudo dnf install httpd
■ Remove a package:
Unset
sudo dnf remove httpd
○
Universal Package Managers:
■ Snap:
Unset
sudo snap install vlc
■ Flatpak:
Unset
flatpak install flathub org.gimp.GIMP
3.
What Skills Required to Prepare This Question:
Unset
# Clean APT cache
2. Answer:
UFW (Uncomplicated Firewall) is a user-friendly interface for managing iptables firewall
rules.
○ Enable UFW:
Unset
sudo ufw enable
○
Check Firewall Status:
Unset
sudo ufw status verbose
○
Allow Specific Ports/Services:
Unset
sudo ufw allow 22/tcp # SSH
○
Deny Access:
Unset
sudo ufw deny 23/tcp # Deny Telnet
○
Allow Specific IPs:
Unset
sudo ufw allow from 192.168.1.100 to any port 22
○
Enable Logging:
Unset
sudo ufw logging on
○
Disable UFW:
Unset
sudo ufw disable
3.
What Skills Required to Prepare This Question:
Unset
# Allow a specific subnet
2. Answer:
The cron service is used to schedule repetitive tasks.
Unset
crontab -e
○
Crontab Syntax:
Unset
* * * * * command_to_run
| | | | |
○
Example Cron Jobs:
Unset
0 0 * * * /path/to/script.sh
Unset
*/5 * * * * /path/to/command
○
List Current Cron Jobs:
Unset
crontab -l
○
Remove Cron Jobs:
Unset
crontab -r
3.
What Skills Required to Prepare This Question:
Unset
# Run a backup script every Sunday at 2 AM
0 2 * * 0 /path/to/backup.sh
0 0 * * * rm -rf /tmp/*
Question 51: How do you check system performance and resource usage in Linux?
1. Question:
How do you check system performance and resource usage in Linux?
2. Answer:
Various commands can monitor system resources and performance.
○ CPU and Memory Usage:
Unset
top
○
Disk Usage:
Unset
df -h # Show disk space usage
○
I/O Performance:
Unset
iostat # Requires sysstat package
○
Network Usage:
Unset
iftop # Real-time bandwidth monitoring
netstat -tulnp
○
System Load:
Unset
uptime
○
Check Running Processes:
Unset
ps aux
3.
What Skills Required to Prepare This Question:
Unset
# Find top memory-consuming processes
ss -tuln
iotop