DevOps Fundamental interview must know Q&A
DevOps Fundamental interview must know Q&A
1. What is GIT?
o Git is a distributed version control system (DVCS) that helps track changes in
source code during software development. It allows multiple developers to
collaborate on projects efficiently.
2. What is the difference between GIT & GitHub?
o Git is a version control tool used to manage code repositories, while GitHub
is a cloud-based hosting service for Git repositories that provides additional
collaboration features like pull requests, issue tracking, and CI/CD integration.
3. Why do we use GIT?
o Git is used for:
Tracking changes in code.
Collaboration among multiple developers.
Branching and merging for parallel development.
Maintaining version history and rollback options.
4. What is SCM & VCS?
o SCM (Software Configuration Management) is a discipline for managing
and tracking software changes.
o VCS (Version Control System) is a tool that helps manage changes in code.
Git is a type of VCS.
5. What are the steps for pushing code to a GitHub Repository?
o Initialize the repository: git init
o Add remote repository: git remote add origin <repo_URL>
o Add files: git add .
o Commit changes: git commit -m "commit message"
o Push changes: git push origin <branch-name>
6. Why do we commit?
o A commit saves changes in the repository history, allowing developers to track
modifications, revert to previous versions, and maintain a record of
contributions.
7. What are the Git commands to push the code?
o git init – Initialize a Git repository
o git add . – Stage changes
o git commit -m "Message" – Commit changes
o git push origin <branch-name> – Push changes to remote repository
8. How can you merge a Git repository with another?
o You can merge another repository using git remote add, git fetch, and
git merge. Example:
sql
CopyEdit
git remote add repo2 <URL-of-repo2>
git fetch repo2
git merge repo2/main
A merge conflict occurs when Git cannot automatically resolve differences between
two branches. This typically happens when two developers edit the same line of code.
12. How can you resolve a merge conflict in the same project and the same branch?
Jenkins Basics
1. What is Jenkins?
o Jenkins is an open-source automation server used to implement Continuous
Integration (CI) and Continuous Deployment (CD). It helps automate the
building, testing, and deployment of applications.
2. Why do we use Jenkins?
o Jenkins helps developers to:
Automate software builds.
Run tests to detect errors early.
Deploy applications automatically.
Integrate with various DevOps tools like Git, Docker, Kubernetes, etc.
3. What are the other tools for CI/CD besides Jenkins?
o TeamCity, Bamboo, GitLab CI/CD, CircleCI, TravisCI, ArgoCD,
Spinnaker, Azure DevOps, and GitHub Actions.
cpp
CopyEdit
H 0 * * * // Runs the job daily at midnight
*/5 * * * * // Runs every 5 minutes
groovy
CopyEdit
println "Hello, Jenkins!"
groovy
CopyEdit
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building the project'
}
}
stage('Test') {
steps {
echo 'Running tests'
}
}
}
}
Jenkins Tasks
Task 1: Jenkins Pipeline for Java & PHP Application
groovy
CopyEdit
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git 'https://github.com/example-repo.git'
}
}
stage('Build Java') {
steps {
sh 'mvn clean package'
}
}
stage('Build PHP') {
steps {
sh 'composer install'
}
}
stage('Deploy') {
steps {
echo 'Deploying the application...'
}
}
}
}
Task 2: Jenkinsfile for Java Application with Maven and Error Handling
groovy
CopyEdit
pipeline {
agent any
stages {
stage('Checkout') {
steps {
script {
try {
git 'https://github.com/example-repo.git'
} catch (Exception e) {
echo "Git Checkout Failed: ${e}"
}
}
}
}
stage('Build') {
steps {
script {
try {
sh 'mvn clean package'
} catch (Exception e) {
echo "Build Failed: ${e}"
error("Stopping pipeline due to build failure")
}
}
}
}
}
}
groovy
CopyEdit
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git 'https://github.com/example-repo.git'
}
}
stage('Build') {
steps {
sh 'mvn clean package'
}
}
stage('Deploy') {
steps {
ansiblePlaybook credentialsId: 'ansible-key', playbook:
'deploy.yml'
}
}
}
triggers {
pollSCM('* * * * *')
}
}
Ansible Basics
1. What is Ansible?
No, Ansible is also used for application deployment, orchestration, cloud provisioning, and
security automation.
Ansible Components & Working
Ansible runs from a control node and connects to remote managed nodes over SSH (or
WinRM for Windows) using inventory files.
csharp
CopyEdit
[webservers]
server1 ansible_host=192.168.1.10
server2 ansible_host=192.168.1.11
Dynamic inventory is used for cloud environments where hosts change frequently.
/etc/ansible/ansible.cfg or ~/.ansible.cfg.
- debug: var=result
Docker Basics
1. What is Docker?
Docker is a containerization platform that allows developers to package applications along
with their dependencies into a lightweight, portable, and isolated unit called a container.
Docker vs Virtualization
Docker Images
Layers are intermediate images that make up a Docker image, stored in read-only format.
8. What is OverlayFS?
In /var/lib/docker/overlay2/ directory.
Docker Networking
Inside:
bash
CopyEdit
docker exec -it <container_id> ps aux
Outside:
css
CopyEdit
docker top <container_id>
Docker Hub, AWS ECR, GCR, and private registries store Docker images.
Docker Commands: up vs run vs start
Command Purpose
Docker Task
Part 1: Dockerfile for WordPress
dockerfile
CopyEdit
FROM wordpress:latest
RUN apt-get update && apt-get install -y wget curl
EXPOSE 80
CMD ["apache2-foreground"]
Docker-Compose File
yaml
CopyEdit
version: '3.8'
services:
db:
build: ./db
restart: always
volumes:
- /etc/mysql:/etc/mysql
environment:
MYSQL_ROOT_PASSWORD: root
wordpress:
build: ./wordpress
restart: always
ports:
- "8080:80"
depends_on:
- db
Kubernetes Basics
1. What is Kubernetes?
Master Components:
o API Server: Handles communication via kubectl.
o etcd: Stores cluster data (key-value store).
o Controller Manager: Manages controllers (e.g., ReplicaSet, Node Controller).
o Scheduler: Assigns Pods to Nodes.
Node (Worker) Components:
o Kubelet: Manages containers on a node.
o Kube Proxy: Handles networking.
o Container Runtime: Runs containers (Docker, containerd, etc.).
3. What is etcd?
A highly available key-value store used by Kubernetes to store cluster state and
configuration.
7. What is Ingress?
Ingress Controller manages external access (HTTP/HTTPS) to services inside the cluster.
yaml
CopyEdit
livenessProbe:
httpGet:
path: /health
port: 8080
Via localhost.
Kubernetes Networking
Flannel is a CNI (Container Network Interface) that provides an overlay network for pod-to-
pod communication.
OpenShift
A Kubernetes distribution by Red Hat with built-in security, CI/CD, and developer tools.
OpenShift has a built-in authentication system, Image Registry, and Developer Console.
OpenShift's Networking Layer that provides services like Routes & Load Balancing.
OpenShift Workloads
Scheduler assigns Pod → Kubelet runs Pod → Checks health & logs.
42. What is Persistent Volume (PV) & Persistent Volume Claim (PVC)?
VPC (Virtual Private Cloud) is a logically isolated network where AWS resources run
securely.
Required to control networking, subnetting, routing, and security.
Yes! Vertical scaling means changing the instance type (e.g., t2.micro → t2.large).
Requires stopping the instance first:
css
CopyEdit
aws ec2 stop-instances --instance-ids i-12345678
aws ec2 modify-instance-attribute --instance-id i-12345678 --
instance-type m5.large
aws ec2 start-instances --instance-ids i-12345678
Scalability Vertical & Read Replicas Horizontally scalable Fully managed, auto-scaling
yaml
CopyEdit
Resources:
MyEC2Instance:
Type: "AWS::EC2::Instance"
Properties:
InstanceType: "t2.micro"
ImageId: "ami-123456"
bash
CopyEdit
top
free -m
df -h
iostat
vmstat
Create a snapshot:
pgsql
CopyEdit
aws ec2 create-snapshot --volume-id vol-12345678 --description
"Backup"
Create an AMI:
css
CopyEdit
aws ec2 create-image --instance-id i-12345678 --name "MyBackupAMI"
S3 Security
IAM Policies
Bucket Policies
ACLs
MFA Delete
Application Load Balancer (ALB) → Routes traffic based on URL paths & headers.
No, but you can create a new key and replace it using:
css
CopyEdit
aws ec2-instance-connect send-ssh-public-key --instance-id i-12345678
--availability-zone us-east-1a --instance-os-user ec2-user --ssh-
public-key file://new-key.pub
VPC (10.0.0.0/16)
o Public Subnet (Web Layer)
o Private Subnet (App Layer)
o Private Subnet (DB Layer)
ALB → Auto Scaling EC2 (PHP/Java/Python)
RDS for MySQL/PostgreSQL
S3 for Static Files
CloudFront for CDN
IAM Roles & Security Groups
Scripting
# Restart Apache
sudo systemctl restart apache2
# Give permissions
sudo chmod +x /opt/tomcat/bin/*.sh
sudo chown -R www-data:www-data /opt/tomcat
# Start Tomcat
sudo /opt/tomcat/bin/startup.sh
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
}
EOF'
bash
CopyEdit
chmod +x setup_wordpress.sh setup_java.sh
bash
CopyEdit
sudo ./setup_wordpress.sh
bash
CopyEdit
sudo ./setup_java.sh
These scripts will set up WordPress on Apache and Java (Tomcat) on Nginx.
CI/CD Overview
1. What is CI & CD?
Risk Level Lower risk, human review available Higher risk, but rapid feedback
2. CI/CD Tools
Jenkins, GitHub Actions, GitLab CI/CD, CircleCI, Travis CI
Terraform, CloudFormation
8. Cloud Providers
Linux
1. What is Linux?
Linux is an open-source, Unix-like operating system that manages hardware resources and
provides an environment for running applications. It is known for its stability, security, and
flexibility.
4. What is Kernel?
The kernel is the core of the Linux operating system that manages system resources (CPU,
memory, storage) and allows software to communicate with hardware.
Check with:
bash
CopyEdit
cat /etc/redhat-release
GRUB (Grand Unified Bootloader) is a bootloader that allows users to select and boot
operating systems.
A boot loader is a program that loads the operating system into memory when the system
starts. Example: GRUB, LILO, SYSLINUX.
.rpm is a package format for Red Hat-based distributions (RHEL, CentOS, Fedora).
.deb is a package format for Debian-based distributions (Ubuntu, Debian).
RPM (Red Hat Package Manager) is a tool to install, update, and remove .rpm packages.
bash
CopyEdit
rpm -ivh package.rpm # Install package
rpm -q package-name # Check if installed
rpm -e package-name # Remove package
14. What is YUM?
YUM (Yellowdog Updater, Modified) is a package manager for RHEL-based systems that
resolves dependencies automatically.
bash
CopyEdit
yum install httpd # Install Apache
yum remove httpd # Remove Apache
yum update # Update all packages
bash
CopyEdit
yum install package-name
bash
CopyEdit
rpm -ivh package.rpm
Bash (Bourne Again Shell) is the default command-line shell in most Linux distributions. It
executes commands and scripts.
A shell is a command-line interface that allows users to interact with the Linux system.
bash
CopyEdit
touch file.txt
1. touch file.txt
2. echo "content" > file.txt
3. cat > file.txt (Ctrl+D to save)
4. vim file.txt (Insert text, then save with :wq)
Example:
bash
CopyEdit
chmod 755 script.sh # Owner (rwx), Group (r-x), Others (r-x)
chmod u+x file.sh # Add execute permission for the user
bash
CopyEdit
chmod +t /tmp
bash
CopyEdit
ls -ld /tmp
Output:
bash
CopyEdit
drwxrwxrwt 10 root root 4096 Feb 23 /tmp
Commands:
bash
CopyEdit
setfacl -m u:john:rwx file.txt # Grant 'john' full access
getfacl file.txt # View ACLs
setfacl -x u:john file.txt # Remove ACL for user 'john'
Check:
bash
CopyEdit
ls -l /usr/bin/passwd # `s` in `-rwsr-xr-x`
Example:
bash
CopyEdit
cat /etc/passwd | grep username
cat /etc/shadow | grep username
Controlled by umask:
bash
CopyEdit
umask 022 # Default mask (removes write for group & others)
Example:
bash
CopyEdit
rm -rvf /tmp/test # Delete directory without confirmation
Term Description
PV (Physical Volume) Raw storage device (HDD/SSD partition).
VG (Volume Group) Combines multiple PVs into a single pool.
LV (Logical Volume) Partition-like structure created from VG.
Commands:
bash
CopyEdit
pvcreate /dev/sdb
vgcreate myvg /dev/sdb
lvcreate -L 10G -n mylv myvg
mkfs.xfs /dev/myvg/mylv
bash
CopyEdit
lvextend -L +5G /dev/myvg/mylv
xfs_growfs /mnt
Information Command
Running processes ps aux
RAM usage free -h
Disk usage df -h
CPU usage top or htop
CPU details lscpu
Command Function
ps aux Snapshot of running processes.
top Dynamic process viewer (updates in real time).
1. Create partition:
bash
CopyEdit
fdisk /dev/sdb
2. Format as XFS:
bash
CopyEdit
mkfs.xfs /dev/sdb1
3. Mount it:
bash
CopyEdit
mount /dev/sdb1 /mnt
kotlin
CopyEdit
rd.break
bash
CopyEdit
mount -o remount,rw /sysroot
6. Change root:
bash
CopyEdit
chroot /sysroot
bash
CopyEdit
passwd root
Change runlevel:
bash
CopyEdit
systemctl isolate multi-user.target
systemctl set-default graphical.target
Commands:
bash
CopyEdit
journalctl -xe # View system logs
tail -f /var/log/messages # Monitor logs in real-time
Command Function
journalctl Displays logs from systemd-journald
tail -f Shows real-time logs from a file
Example:
bash
CopyEdit
journalctl -u nginx # Logs for Nginx service
tail -f /var/log/nginx/access.log # Real-time web access logs
Example:
bash
CopyEdit
subscription-manager register --username=your_username --
password=your_password
subscription-manager list --available
subscription-manager attach --auto
bash
CopyEdit
tar -cvf archive.tar file1 file2
tar -xvf archive.tar # Extract
zip/unzip
bash
CopyEdit
zip archive.zip file1 file2
unzip archive.zip
Check umask:
bash
CopyEdit
umask
Set umask:
bash
CopyEdit
umask 027 # Files: 640, Directories: 750
bash
CopyEdit
ps aux | grep apache
kill -9 <PID>
Or use:
bash
CopyEdit
pkill apache # Kill by process name
Temporary:
bash
CopyEdit
ip addr add 192.168.1.100/24 dev eth0
bash
CopyEdit
vi /etc/sysconfig/network-scripts/ifcfg-eth0
Add:
ini
CopyEdit
BOOTPROTO=static
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
Restart network:
bash
CopyEdit
systemctl restart network
A zombie process has completed execution but still has an entry in the process table.
It usually occurs when the parent does not read the child’s exit status.
Find zombies:
bash
CopyEdit
ps aux | awk '{ print $8 " " $2 }' | grep -w Z
bash
CopyEdit
kill -9 <Parent_PID>
Kernel-based Virtual Machine (KVM) is a Type-1 hypervisor built into the Linux
kernel.
Allows running multiple VMs (Virtual Machines) on Linux.
bash
CopyEdit
egrep -c '(vmx|svm)' /proc/cpuinfo # vmx (Intel), svm (AMD)
lsmod | grep kvm
Type-1 (Bare Metal): Runs directly on hardware (e.g., KVM, VMware ESXi).
Type-2 (Hosted): Runs inside an OS (e.g., VirtualBox, VMware Workstation).
bash
CopyEdit
fdisk -l /dev/sda # MBR
gdisk -l /dev/sda # GPT
bash
CopyEdit
lsblk
bash
CopyEdit
mkdir /mnt/data
3. Mount manually:
bash
CopyEdit
mount /dev/sdb1 /mnt/data
5. Remount all:
bash
CopyEdit
mount -a
bash
CopyEdit
crontab -e
perl
CopyEdit
0 3 * * * /usr/bin/backup.sh # Run at 3 AM daily
*/5 * * * * /usr/bin/check.sh # Every 5 minutes
bash
CopyEdit
crontab -l
lua
CopyEdit
install
lang en_US
keyboard us
network --bootproto=dhcp
rootpw mypassword
clearpart --all
autopart
Start installation:
bash
CopyEdit
anaconda --kickstart=/path/to/ks.cfg
bash
CopyEdit
systemctl status firewalld
List rules:
bash
CopyEdit
firewall-cmd --list-all
Check status:
bash
CopyEdit
sestatus
bash
CopyEdit
setenforce 0 # Temporarily disable
vi /etc/selinux/config
SELINUX=disabled # Disable permanently
Verify Kerberos:
bash
CopyEdit
klist
bash
CopyEdit
yum install krb5-server krb5-libs nfs-utils
2. Configure /etc/exports:
arduino
CopyEdit
/export *(rw,sec=krb5)
3. Restart NFS:
bash
CopyEdit
systemctl restart nfs-server
Example:
bash
CopyEdit
telnet 192.168.1.100
bash
CopyEdit
ssh [email protected]
bash
CopyEdit
cat /var/lib/dhcpd/dhcpd.leases
bash
CopyEdit
systemctl restart dhcpd
NTP (Network Time Protocol) synchronizes system time with time servers.
Chrony is used in RHEL 8+ for time synchronization.
bash
CopyEdit
timedatectl
chronyc tracking
bash
CopyEdit
yum install chrony -y
vi /etc/chrony.conf # Set NTP server
systemctl enable --now chronyd
SSH (Secure Shell) is used for secure remote login and file transfer.
SSH Key-based authentication avoids passwords.
Generate SSH key pair:
bash
CopyEdit
ssh-keygen -t rsa -b 4096
bash
CopyEdit
ssh-copy-id user@remote-server
bash
CopyEdit
ssh user@remote-server
bash
CopyEdit
/etc/ssh/sshd_config
Key settings:
bash
CopyEdit
PermitRootLogin no # Disable root login
PasswordAuthentication no # Enforce key-based login
Port 2222 # Change default SSH port
bash
CopyEdit
systemctl restart sshd
bash
CopyEdit
ip link show eth0
bash
CopyEdit
ip link set dev eth0 down
ip link set dev eth0 address 00:11:22:33:44:55
ip link set dev eth0 up
bash
CopyEdit
vi /etc/httpd/conf.d/mywebsite.conf
Add:
php-template
CopyEdit
<VirtualHost *:80>
ServerName mywebsite.com
DocumentRoot /var/www/html/mywebsite
</VirtualHost>
Restart Apache:
bash
CopyEdit
systemctl restart httpd
List rules:
bash
CopyEdit
iptables -L -n -v
Block an IP:
bash
CopyEdit
iptables -A INPUT -s 192.168.1.100 -j DROP
Allow SSH:
bash
CopyEdit
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
Save rules:
bash
CopyEdit
service iptables save
Check status:
bash
CopyEdit
systemctl status firewalld
bash
CopyEdit
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --reload
bash
CopyEdit
ssh -L 8080:localhost:80 user@remote-server
1. Install Kerberos:
bash
CopyEdit
yum install -y krb5-server krb5-workstation nfs-utils
arduino
CopyEdit
/export *(rw,sec=krb5)
3. Restart NFS:
bash
CopyEdit
systemctl restart nfs-server
bash
CopyEdit
nmtui
bash
CopyEdit
vi /etc/sysconfig/network-scripts/ifcfg-eth0
Add:
ini
CopyEdit
BOOTPROTO=static
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
Restart network:
bash
CopyEdit
systemctl restart network
Example:
nginx
CopyEdit
nameserver 8.8.8.8
nameserver 8.8.4.4
bash
CopyEdit
cat /etc/resolv.conf
1. Ping a Host:
bash
CopyEdit
ping google.com
2. Check Routes:
bash
CopyEdit
ip route show
bash
CopyEdit
nc -zv google.com 443
bash
CopyEdit
lsblk
pvs # List physical volumes
vgs # List volume groups
lvs # List logical volumes
Steps:
bash
CopyEdit
fdisk /dev/sdb
bash
CopyEdit
pvcreate /dev/sdb1
bash
CopyEdit
vgcreate my_vg /dev/sdb1
bash
CopyEdit
lvcreate -L 5G -n my_lv my_vg
bash
CopyEdit
echo "/dev/my_vg/my_lv /mnt/mydata xfs defaults 0 0" >> /etc/fstab
bash
CopyEdit
lvextend -L +5G /dev/my_vg/my_lv
bash
CopyEdit
xfs_growfs /mnt/mydata
bash
CopyEdit
resize2fs /dev/my_vg/my_lv
bash
CopyEdit
umount /mnt/mydata
bash
CopyEdit
e2fsck -f /dev/my_vg/my_lv
resize2fs /dev/my_vg/my_lv 3G
3. Reduce LV:
bash
CopyEdit
lvreduce -L 3G /dev/my_vg/my_lv
4. Mount Again:
bash
CopyEdit
mount /dev/my_vg/my_lv /mnt/mydata
Command Description
df -h Shows disk usage per filesystem
du -sh /var/log Shows folder size
lsblk Lists block devices (disks, partitions)
fdisk -l Lists partitions
Extend XFS:
bash
CopyEdit
xfs_growfs /mnt/mydata
RAID (Redundant Array of Independent Disks) is used for fault tolerance &
performance.
Types of RAID:
o RAID 0 (Striping) → Fast, No Redundancy
o RAID 1 (Mirroring) → Data Duplication
o RAID 5 (Striping + Parity) → Fault Tolerance
o RAID 10 (RAID 1+0) → High Redundancy
Check RAID:
bash
CopyEdit
cat /proc/mdstat
bash
CopyEdit
yum install mdadm -y
2. Create RAID 1:
bash
CopyEdit
mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb
/dev/sdc
3. Format RAID:
bash
CopyEdit
mkfs.ext4 /dev/md0
4. Mount RAID:
bash
CopyEdit
mount /dev/md0 /mnt/raid1
1. Install NFS:
bash
CopyEdit
yum install nfs-utils -y
2. Configure NFS:
bash
CopyEdit
vi /etc/exports
Add:
bash
CopyEdit
/data 192.168.1.0/24(rw,sync,no_root_squash)
bash
CopyEdit
systemctl enable --now nfs-server
85. What is Samba? How is It Different from NFS?
Install Samba:
bash
CopyEdit
yum install samba -y
SSHFS (SSH File System) allows mounting remote directories via SSH.
bash
CopyEdit
sshfs user@remote-server:/var/www /mnt/sshfs
Unmount:
bash
CopyEdit
fusermount -u /mnt/sshfs
ISCSI (Internet Small Computer System Interface) allows block storage over IP.
targetcli is used to configure ISCSI targets.
bash
CopyEdit
iscsiadm -m session
89. What is Kerberos & How to Secure NFS with It?
bash
CopyEdit
/data *(rw,sec=krb5)
1. Edit /etc/fstab:
bash
CopyEdit
/dev/sdb1 /data ext4 defaults 0 0
2. Apply changes:
bash
CopyEdit
mount -a
Command Description
journalctl -xe View system logs
tail -f /var/log/messages Monitor logs in real-time
dmesg View kernel logs
bash
CopyEdit
crontab -e
arduino
CopyEdit
0 2 * * * /home/user/backup.sh
93. What is subscription-manager in RHEL?
bash
CopyEdit
subscription-manager list
bash
CopyEdit
top
bash
CopyEdit
htop
bash
CopyEdit
yum install sysstat -y
mpstat -P ALL
bash
CopyEdit
iostat -c 2 5
bash
CopyEdit
sar -u 5 10
96. How to Check Memory Usage in Linux?
bash
CopyEdit
free -h
bash
CopyEdit
vmstat 1 5
bash
CopyEdit
cat /proc/meminfo
bash
CopyEdit
df -h
bash
CopyEdit
du -sh /var/log
bash
CopyEdit
find / -type f -size +1G
Command Description
ps -aux Show all running processes
top Show real-time processes
Command Description
htop Interactive process viewer
pidstat CPU & memory usage per process
bash
CopyEdit
yum install iftop -y
iftop
bash
CopyEdit
yum install nload -y
nload
bash
CopyEdit
ss -tulnp
bash
CopyEdit
ip -s link
1. lscpu
bash
CopyEdit
lscpu
o Shows CPU architecture, cores, threads, etc.
2. cat /proc/cpuinfo
bash
CopyEdit
cat /proc/cpuinfo
bash
CopyEdit
yum install tuned -y
systemctl enable --now tuned
tuned-adm list
tuned-adm profile performance
bash
CopyEdit
sar -r 5 10 # Memory usage every 5 sec for 10 times
sar -u 5 10 # CPU usage every 5 sec for 10 times
bash
CopyEdit
yum install iotop -y
iotop
bash
CopyEdit
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head
bash
CopyEdit
kill -9 <PID>
bash
CopyEdit
cpulimit -p <PID> -l 30
bash
CopyEdit
ps aux | grep 'Z'
bash
CopyEdit
kill -9 <PARENT_PID>
bash
CopyEdit
free -h
bash
CopyEdit
dd if=/dev/zero of=/swapfile bs=1M count=1024
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
bash
CopyEdit
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab
OOM Killer (Out of Memory Killer) terminates processes when memory is low.
To prevent a process from being killed:
bash
CopyEdit
echo "-1000" > /proc/$(pgrep my_process)/oom_score_adj
107. What is systemd-analyze?
bash
CopyEdit
systemd-analyze
systemd-analyze blame
bash
CopyEdit
ulimit -a
bash
CopyEdit
ulimit -n 65535
System Logs:
bash
CopyEdit
journalctl -f
Kernel Logs:
bash
CopyEdit
dmesg -w
bash
CopyEdit
journalctl -u sshd -f
1. CPU Benchmark:
bash
CopyEdit
sysbench --test=cpu --cpu-max-prime=20000 run
2. Disk Benchmark:
bash
CopyEdit
dd if=/dev/zero of=testfile bs=1G count=1 oflag=direct
bash
CopyEdit
curl -s https://raw.githubusercontent.com/sivel/speedtest-
cli/master/speedtest.py | python
bash
CopyEdit
systemctl disable cups
bash
CopyEdit
echo "/dev/sdb1 /data ext4 defaults,noatime 0 0" >> /etc/fstab
bash
CopyEdit
echo "fs.file-max = 2097152" >> /etc/sysctl.conf
bash
CopyEdit
ip addr show
bash
CopyEdit
ifconfig
bash
CopyEdit
hostname -I
bash
CopyEdit
vi /etc/sysconfig/network-scripts/ifcfg-eth0
Add/Edit:
ini
CopyEdit
BOOTPROTO=static
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
bash
CopyEdit
systemctl restart NetworkManager
bash
CopyEdit
ss -tulnp
bash
CopyEdit
netstat -tulnp
Example:
bash
CopyEdit
ping -c 4 google.com
traceroute google.com
nc -zv google.com 443
curl -I https://google.com
bash
CopyEdit
ip route show
bash
CopyEdit
route -n
bash
CopyEdit
cat /etc/resolv.conf
bash
CopyEdit
echo "nameserver 8.8.8.8" > /etc/resolv.conf
bash
CopyEdit
systemctl restart NetworkManager
Type Purpose
�Security in Linux
Hardening SSH
bash
CopyEdit
vi /etc/ssh/sshd_config
Change:
yaml
CopyEdit
Port 2222
nginx
CopyEdit
PermitRootLogin no
nginx
CopyEdit
AllowUsers user1 user2
4. Restart SSH
bash
CopyEdit
systemctl restart sshd
bash
CopyEdit
ssh-keygen -t rsa -b 4096
bash
CopyEdit
ssh-copy-id user@remote-server
bash
CopyEdit
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
bash
CopyEdit
firewall-cmd --remove-port=22/tcp --permanent
firewall-cmd --reload
1. Using iptables
bash
CopyEdit
iptables -A INPUT -s 192.168.1.100 -j DROP
2. Using firewalld
bash
CopyEdit
firewall-cmd --add-rich-rule='rule family="ipv4" source
address="192.168.1.100" reject' --permanent
firewall-cmd --reload
1. Authentication Logs
bash
CopyEdit
cat /var/log/secure
2. System Logs
bash
CopyEdit
journalctl -xe
Add:
ini
CopyEdit
[sshd]
enabled = true
maxretry = 5
bantime = 600
Restart Fail2Ban
bash
CopyEdit
systemctl restart fail2ban
bash
CopyEdit
tcpdump -i eth0
bash
CopyEdit
tcpdump -i eth0 host 192.168.1.1
bash
CopyEdit
tcpdump -i eth0 -w capture.pcap
2. Network Security
Firewall Management:
o iptables vs firewalld
o Configuring zones, services, and ports in firewalld
Network Intrusion Detection and Prevention Systems (IDS/IPS):
o Tools: Snort, Suricata
TCP Wrappers and Host-Based Access Control
o /etc/hosts.allow and /etc/hosts.deny
Securing SSH:
o SSH key-based authentication
o Disabling root login (PermitRootLogin no)
o Changing default SSH port
o SSH tunneling and port forwarding
o Fail2Ban for brute force attack prevention
5. System Hardening
✅Infrastructure Monitoring:
CPU, Memory, Disk, and Network usage (top, htop, vmstat, iostat)
System logs (/var/log/syslog, /var/log/messages)
Process monitoring (ps, systemctl status)
Disk I/O monitoring (iostat, iotop)
Features of Prometheus:
Query
PromQL NRPE SQL-based API queries
Language
✅Use Case:
✅Grafana is a visualization and analytics platform that helps monitor logs, metrics, and
application data.
✅Basic Queries:
✅Alerting Example:
Grafana supports:
✅Time-series Graphs – Line charts for CPU, memory, and network usage.
✅Bar Charts – Comparing resource consumption.
✅Heatmaps – Showing anomalies in system performance.
✅Single-Stat Panels – Displaying CPU usage % in a single number.
✅Gauge & Progress Charts – Monitoring real-time metrics like disk space.
✅Geo Maps – Mapping logs or requests by geographic location.