Linux Administrator Interview Questions - Part2
Linux Administrator Interview Questions - Part2
How do file permissions work in Linux, and how can you modify them?
Linux file permissions define access levels for files and directories for three categories:
Unset
ls -l file.txt
Example output:
Unset
-rw-r--r-- 1 user group 1024 Feb 26 10:00 file.txt
Unset
chmod 755 script.sh
Unset
chmod +x my_script.sh
Unset
chmod 600 secret.txt
Unset
chmod go-w document.txt
Unset
ps aux
Unset
top
Unset
pgrep apache2
To terminate a process:
Unset
kill -9 <PID>
Example:
Unset
kill -9 1234
Unset
ps -u username
Unset
pkill nginx
Unset
renice -n 10 -p 5678
How do you create, modify, and delete users and groups in Linux?
Unset
sudo useradd -m newuser
To set a password:
Unset
sudo passwd newuser
To create a group:
Unset
sudo groupadd developers
Unset
sudo usermod -aG developers newuser
Unset
sudo userdel -r newuser
Unset
cut -d: -f1 /etc/passwd
Unset
sudo deluser newuser developers
Unset
df -h
Unset
du -sh /var/log
Unset
rm -rf /var/log/*.log
Unset
df -h /dev/sda1
Unset
find / -type f -size +100M -exec ls -lh {} \;
Unset
find /tmp -type f -mtime +7 -delete
Networking in Linux is managed using commands like ip, ifconfig, and nmcli.
Unset
ip a
or
Unset
ifconfig
To check connectivity:
Unset
ping -c 4 google.com
Unset
sudo nano /etc/network/interfaces
Unset
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
Unset
sudo systemctl restart networking
Unset
netstat -tulnp
or
Unset
ss -tulnp
Unset
ip route show
Unset
sudo dhclient -r && sudo dhclient
Unset
nslookup google.com
How do you configure and manage firewalls using iptables or ufw in Linux?
Unset
sudo iptables -L -v
Unset
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
To block an IP address:
Unset
sudo iptables -A INPUT -s 192.168.1.50 -j DROP
Unset
sudo iptables-save > /etc/iptables.rules
To use ufw:
Unset
sudo ufw enable
sudo ufw allow 80/tcp
sudo ufw deny 23/tcp
sudo ufw status
Unset
sudo iptables -S
Unset
sudo iptables -P INPUT DROP
sudo iptables -P OUTPUT ACCEPT
Unset
sudo ufw reset
How do you schedule and manage automated tasks using cron in Linux?
Unset
crontab -e
Unset
crontab -l
Unset
crontab -r
Unset
sudo systemctl status cron
Unset
*/5 * * * * /path/to/script.sh
Unset
0 8 * * * echo "Daily Reminder" | mail -s "Reminder" [email protected]
Unset
ls -lh /var/log
Unset
journalctl -xe
Unset
journalctl --since "1 hour ago"
Unset
tail -f /var/log/syslog
To rotate logs automatically, use logrotate:
Unset
sudo nano /etc/logrotate.d/custom
Example configuration:
Unset
/var/log/myapp.log {
weekly
rotate 4
compress
missingok
}
Unset
grep "ERROR" /var/log/syslog
Unset
grep "Failed password" /var/log/auth.log
How do you create, manage, and delete users and groups in Linux?
In Linux, user management is handled using commands like useradd, usermod, and userdel.
Unset
sudo useradd -m -s /bin/bash username
Unset
sudo passwd username
Unset
sudo usermod -aG sudo username
Unset
groups username
To delete a user:
Unset
sudo userdel -r username
Unset
sudo groupadd developers
Unset
sudo usermod -aG developers,sudo username
Unset
cut -d: -f1 /etc/passwd
Unset
sudo usermod -d /home/newhome username
File permissions in Linux are controlled using chmod, chown, and chgrp.
Unset
ls -l filename
Unset
chmod 755 filename
Unset
sudo chown user:group filename
Unset
chmod 600 filename
Unset
chmod +t /tmp
Unset
chmod +x script.sh
Unset
chmod 400 secret.txt
Unset
sudo chgrp developers filename
11. Managing Processes in Linux
Question:
Processes in Linux are managed using ps, top, htop, kill, and nice.
Unset
ps aux
Unset
top
Unset
ps aux | grep nginx
Unset
kill 1234
Unset
kill -9 1234
Unset
ps -o ppid= -p 1234
Unset
sudo pkill -u username
Unset
nice -n -10 ./my_script.sh
Unset
df -h
Unset
du -sh /home/user
Unset
find / -type f -size +100M
To mount a disk:
Unset
sudo mount /dev/sdb1 /mnt
Unset
lsblk -f
To format a disk:
Unset
sudo mkfs.ext4 /dev/sdb1
Unset
sudo umount /mnt
Unset
df -i
Unset
sudo resize2fs /dev/sdb1
Systemd is the default service manager for most modern Linux distributions. It provides control over
system services and processes.
Unset
systemctl status apache2
To start a service:
Unset
sudo systemctl start apache2
To stop a service:
Unset
sudo systemctl stop apache2
To restart a service:
Unset
sudo systemctl restart apache2
Unset
sudo systemctl enable apache2
Unset
sudo systemctl disable apache2
Unset
journalctl -u apache2
Unset
systemctl is-enabled apache2
Unset
sudo systemctl daemon-reload
Unset
systemctl --failed
Networking in Linux can be managed using tools like ip, ifconfig, netstat, and ping.
Unset
ip a
Unset
sudo ip addr add 192.168.1.100/24 dev eth0
Unset
netstat -tulnp
Unset
ping -c 4 google.com
Unset
nslookup google.com
Unset
sudo systemctl restart networking
Unset
netstat -s
Unset
ip route | grep default
Unset
ss -tulnp
How do you manage the firewall in Linux using UFW and IPTables?
Linux provides firewall management using UFW (Uncomplicated Firewall) and IPTables.
To enable UFW:
Unset
sudo ufw enable
Unset
sudo ufw allow 8080/tcp
Unset
sudo ufw deny 23
Unset
sudo ufw status verbose
To disable UFW:
Unset
sudo ufw disable
Unset
sudo iptables -L -v -n
Unset
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
Unset
sudo ufw reset
Unset
sudo iptables -D INPUT -p tcp --dport 22 -j ACCEPT
Unset
sudo iptables -A INPUT -j LOG --log-prefix "Dropped Packet: "
How do you analyze system logs and monitor system performance in Linux?
Linux logs system events in /var/log/ and can be monitored using journalctl and logrotate.
Unset
journalctl -u apache2
Unset
tail -f /var/log/syslog
Unset
last
Unset
cat /var/log/auth.log | grep "Failed password"
Unset
top
Unset
df -h
Unset
journalctl -b
Unset
dmesg | tail -20
Unset
sudo mkdir -p /var/log/journal
Linux allows user and group management using commands like useradd, usermod, passwd,
groupadd, and chage.
Unset
sudo passwd john
Unset
sudo usermod -aG sudo john
Unset
sudo groupadd developers
Unset
cut -d: -f1 /etc/passwd
Unset
groups john
To delete a user:
Unset
sudo userdel -r john
Unset
sudo passwd --expire john
Unset
sudo usermod -L john
Unset
sudo chage -M 90 john
File permissions determine access rights for users and groups. Linux uses chmod, chown, and ls -l
for permission management.
Unset
sudo chown john:developers file.txt
Unset
chmod 700 file.txt
Unset
chmod 660 file.txt
Unset
chmod 755 script.sh
Unset
umask 022
Unset
chmod a+x script.sh
Unset
chmod go-w file.txt
Unset
chmod 700 my_secure_folder
Linux provides tools like fdisk, parted, lsblk, and df for disk and partition management.
Unset
lsblk
Unset
sudo fdisk /dev/sdb
To format a partition:
Unset
sudo mkfs.ext4 /dev/sdb1
To mount a partition:
Unset
sudo mount /dev/sdb1 /mnt
Unset
mount | grep "^/dev"
Unset
iostat -x 1 5
Unset
sudo lvextend -L +10G /dev/vg01/lv01
Unset
sudo blkid /dev/sdb1
Unset
sudo umount /mnt
Processes in Linux can be managed using ps, top, htop, kill, and nice commands.
Unset
ps aux
Unset
ps aux | grep apache2
To terminate a process:
Unset
kill -9 <PID>
Unset
nice -n 10 myscript.sh
Unset
renice -n -5 -p <PID>
Unset
pidstat -p <PID>
Unset
ps aux --sort=-%mem | head -10
Unset
pkill -9 firefox
Unset
pstree -p <PID>
Network configuration in Linux is managed using tools like ifconfig, ip, nmcli, netstat, and ss.
Unset
ip a
Unset
sudo nano /etc/network/interfaces
Unset
iface eth0 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
Unset
sudo systemctl restart networking
Unset
ip route
Unset
ping 8.8.8.8
traceroute google.com
Unset
ss -tuln
Unset
cat /etc/resolv.conf
Unset
sudo ip addr add 192.168.1.15/24 dev eth0
Unset
ss -tuln | grep ':80'
22. System Monitoring and Logs in Linux
Question:
Linux provides tools like top, htop, vmstat, dmesg, and log files in /var/log for system
monitoring and troubleshooting.
Unset
top
Unset
free -h
Unset
vmstat 1 5
Unset
dmesg | tail
Unset
sudo tail -f /var/log/auth.log
Unset
sudo tail -n 10 /var/log/syslog
Unset
watch df -h
Unset
sudo dmesg | grep -i error
Unset
sudo apt update
To install a package:
Unset
sudo apt install apache2
To remove a package:
Unset
sudo apt remove apache2
Unset
sudo apt upgrade
Unset
dpkg -l
To install a package:
Unset
sudo yum install httpd
To remove a package:
Unset
sudo yum remove httpd
Unset
sudo apt install python3
Unset
sudo apt purge apache2
Unset
dpkg -l
Unset
sudo mkfs.ext4 /dev/sdb1
To mount a filesystem:
Unset
sudo mount /dev/sdb1 /mnt
Unset
sudo fsck /dev/sdb1
Unset
df -h
To unmount a filesystem:
Unset
sudo umount /mnt
Unset
sudo fsck -A
Unset
sudo mount -o ro /dev/sdb1 /mnt
Unset
lsblk
In Linux, users and groups are managed using commands like useradd, usermod, userdel,
groupadd, and groupdel. User and group information is stored in the /etc/passwd and
/etc/group files, respectively.
Unset
sudo useradd -m newuser
Unset
sudo usermod -aG groupname username
Unset
sudo userdel -r newuser
Unset
sudo groupadd newgroup
Unset
sudo groupdel newgroup
Unset
sudo userdel -r specialuser
Unset
sudo usermod -aG sudo username
Disk partitioning in Linux is handled by tools like fdisk, parted, and lsblk.
Unset
lsblk
Unset
sudo fdisk /dev/sda
Unset
sudo mount /dev/sda1 /mnt
Unset
df -h
Unset
sudo fdisk /dev/sda
● Practice using fdisk, parted, and lsblk in a safe environment (e.g., virtual machine)
● Learn about partition types (primary, extended, logical)
● Experiment with mounting and unmounting partitions
Unset
sudo mkswap /dev/sdb1
Unset
df -T
What happens during the Linux boot process, and how can you troubleshoot it?
1. BIOS/UEFI: The system's firmware initializes hardware and starts the bootloader.
2. Bootloader (GRUB): GRUB loads the kernel into memory.
3. Kernel: The Linux kernel initializes system resources and starts the init process.
4. Init System (systemd): systemd or init starts essential system services.
5. Runlevel or Target: The system reaches the default target (multi-user, graphical, etc.).
Unset
journalctl -xb
Unset
fsck /dev/sda1
● Study the boot process by reading documentation on GRUB, systemd, and init systems
● Experiment with bootloader options and recovery modes
● Understand how to analyze kernel and system logs for troubleshooting
Unset
dmesg | grep -i error
Unset
systemctl list-units --failed
Unset
ls -l /path/to/file
2. Example:
Unset
-rwxr-xr-x 1 user group 1234 Jan 1 12:00 file.txt
Unset
chmod +x file.txt
Unset
sudo chown user:group file.txt
Unset
sudo chgrp groupname file.txt
Linux also supports Access Control Lists (ACLs) for fine-grained permission control: 5. To set an ACL:
Unset
setfacl -m u:username:rwx file.txt
1. Change permissions to give read and write access to the owner and read access to others:
Unset
chmod 644 file.txt
Unset
sudo chown -R user:group /path/to/directory
In Linux, processes are managed using commands such as ps, top, kill, nice, renice, and
killall.
Unset
ps aux
2.
This shows all running processes with detailed information like CPU usage, memory usage, and
running time.
3. To view processes interactively:
Unset
top
4.
This shows real-time updates on running processes, with the option to sort by CPU or memory
usage.
Unset
kill PID
6.
Example:
Unset
kill 1234
7.
To kill all processes of a specific name:
Unset
killall process_name
8.
Example:
Unset
killall firefox
9.
To change the priority of a process (nice value):
Unset
nice -n 10 command
10.
This lowers the priority of a process. Use a negative number to increase the priority.
Unset
renice -n 5 -p PID
Unset
ps aux --sort=-%mem
Unset
killall apache2
○ To install a package:
Unset
sudo apt install package_name
Unset
sudo apt update
Unset
sudo apt upgrade
○ To remove a package:
Unset
sudo apt remove package_name
2.
In RedHat/CentOS-based systems (yum or dnf):
○ To install a package:
Unset
sudo yum install package_name
○ To update all installed packages:
Unset
sudo yum update
○ To remove a package:
Unset
sudo yum remove package_name
Unset
sudo apt install apache2
Unset
sudo apt autoremove package_name
Networking in Linux can be managed using various commands such as ifconfig, ip, netstat, and
ping.
Unset
ifconfig
2.
or
Unset
ip addr show
3.
This displays the network interfaces and their respective IP addresses.
4. To assign a static IP address: Edit the network configuration file (usually located in
/etc/network/interfaces for Debian/Ubuntu or
/etc/sysconfig/network-scripts/ifcfg-eth0 for RedHat/CentOS) and update the
address, netmask, and gateway fields.
Example for Ubuntu (/etc/network/interfaces):
Unset
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
5.
To restart the networking service:
Unset
sudo systemctl restart networking
6.
To check the network route:
Unset
netstat -r
7.
or
Unset
ip route show
8.
To test network connectivity:
Unset
ping 192.168.1.1
9.
To resolve DNS issues (check /etc/resolv.conf):
Unset
cat /etc/resolv.conf
Unset
ip addr show
Unset
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
In Linux, log files are typically stored in the /var/log/ directory. The system uses logging daemons
like rsyslog to manage and store logs.
Unset
cat /var/log/syslog
2.
or
Unset
tail -f /var/log/syslog
3.
To view authentication logs (login attempts):
Unset
cat /var/log/auth.log
4.
To rotate logs (using logrotate): Edit /etc/logrotate.conf to define policies like how
often to rotate logs, how many backups to keep, etc.
Unset
sudo truncate -s 0 /var/log/syslog
6.
To monitor log files in real-time:
Unset
tail -f /var/log/apache2/access.log
Unset
tail -f /var/log/syslog
2. Configure log rotation for Apache logs: Edit /etc/logrotate.d/apache2 and set
frequency and rotation policies.
Disk management in Linux is done using various tools like fdisk, parted, lsblk, mount, and df.
Unset
lsblk
2.
This command displays all block devices including hard drives, partitions, and their mount
points.
Unset
sudo fdisk /dev/sda
○
Inside the interactive session, you can create, delete, and modify partitions.
○ Use parted for GPT partitions:
Unset
sudo parted /dev/sda
4.
To format a partition:
Unset
sudo mkfs.ext4 /dev/sda1
5.
This command formats /dev/sda1 with the ext4 filesystem.
Unset
sudo mount /dev/sda1 /mnt
7.
This mounts the partition /dev/sda1 to the directory /mnt.
Unset
df -h
9.
This command shows the disk usage and free space of mounted filesystems in human-readable
form.
11.
To unmount a partition:
Unset
sudo umount /mnt
Unset
df -h
Unset
sudo fdisk /dev/sda
User and group management in Linux is done using commands such as useradd, usermod,
groupadd, passwd, chown, and chgrp.
Unset
sudo useradd username
2.
To assign a password to a user:
Unset
sudo passwd username
3.
To add a user to a group:
Unset
sudo usermod -aG groupname username
4.
To create a group:
Unset
sudo groupadd groupname
5.
To delete a user:
Unset
sudo userdel username
6.
To change the owner of a file:
Unset
sudo chown username:groupname filename
7.
To change the group of a file:
Unset
sudo chgrp groupname filename
8.
To list all users and groups:
○ List users:
Unset
cat /etc/passwd
○ List groups:
Unset
cat /etc/group
Unset
sudo useradd newuser
2.
Add an existing user to a new group:
Unset
sudo usermod -aG admin newuser
Cron is a Linux utility for scheduling tasks. Cron jobs are defined in the crontab file, where you
specify the commands to be executed at scheduled times.
Unset
crontab -l
2.
To edit the cron jobs:
Unset
crontab -e
3.
This opens the cron file in an editor where you can add new jobs.
4. Cron job format: The cron job syntax consists of five fields:
Unset
* * * * * command_to_execute
│ │ │ │ │
│ │ │ │ │
5.
Example: Run a script every day at 2 AM:
Unset
0 2 * * * /path/to/script.sh
6.
To remove a cron job:
Unset
crontab -r
7.
To schedule a cron job as a specific user (requires sudo):
Unset
sudo crontab -u username -e
Unset
0 0 * * * /path/to/backup.sh
Unset
0 15 * * 0 /path/to/script.sh
In Linux, file permissions determine who can read, write, and execute files. They are represented as
a combination of user, group, and other permissions. You can manage file permissions using
commands like chmod, chown, and chgrp.
Unset
ls -l filename
2.
This shows the permissions in the format:
-rwxr-xr-- 1 user group 1234 Jan 1 12:00 filename
○ Numeric mode:
Unset
chmod 755 filename
○
This assigns rwx to the owner, and rx to the group and others.
○ Symbolic mode:
Unset
chmod u+x filename
○
This gives the owner (u) execute permission (+x).
Unset
sudo chown user:group filename
5.
This changes the owner and group of the file to user and group.
6. To change the group of a file:
Unset
sudo chgrp group filename
7.
This changes the group ownership of the file.
Unset
chmod o-w filename
9.
To give executable permissions to a file:
Unset
chmod +x filename
1. Make a file readable and writable for the owner, and readable for others:
Unset
chmod 644 filename
2.
Give execute permissions to the owner and group for a file:
Unset
chmod 770 filename
Network configuration in Linux can be done using tools like ip, ifconfig, nmcli, and editing
network configuration files.
Unset
ip a
2.
or
Unset
ifconfig
3.
To assign an IP address to an interface:
Unset
sudo ip addr add 192.168.1.100/24 dev eth0
4.
To bring up an interface:
Unset
sudo ip link set eth0 up
5.
To configure a static IP address on a network interface (e.g., eth0): Edit the
/etc/network/interfaces file (Debian-based systems):
Unset
sudo nano /etc/network/interfaces
6.
Example configuration:
Unset
auto eth0
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
7.
To configure DNS: Edit the /etc/resolv.conf file:
Unset
sudo nano /etc/resolv.conf
8.
Example:
Unset
nameserver 8.8.8.8
nameserver 8.8.4.4
9.
To check the network route:
Unset
ip route show
10.
To restart networking service:
Unset
sudo systemctl restart networking
2.
Configure DNS using Google DNS servers: Edit /etc/resolv.conf:
Unset
nameserver 8.8.8.8
nameserver 8.8.4.4
Linux distributions use package managers like apt, yum, or dnf to install, remove, and update
software packages.
○ To install a package:
Unset
sudo apt install package_name
○
To update package list:
Unset
sudo apt update
○
To upgrade all installed packages:
Unset
sudo apt upgrade
○
To remove a package:
Unset
sudo apt remove package_name
○
To search for a package:
Unset
apt search package_name
2.
For RedHat-based systems (RHEL, CentOS):
○ To install a package:
Unset
sudo yum install package_name
○
To update package list:
Unset
sudo yum check-update
○
To upgrade all installed packages:
Unset
sudo yum update
○
To remove a package:
Unset
sudo yum remove package_name
3.
For Fedora:
○ To install a package:
Unset
sudo dnf install package_name
Unset
sudo apt install curl
2.
Remove nginx from CentOS:
Unset
sudo yum remove nginx
Process management in Linux is crucial for monitoring and controlling running programs. The key
tools used for managing processes are ps, top, htop, kill, nice, and renice.
Unset
ps aux
○
This lists all processes running on the system with details like user, PID (Process ID),
CPU and memory usage.
Unset
top
○
This shows processes and their resource usage, updating the display continuously.
2.
Killing a process:
Unset
kill <PID>
○
To forcefully kill a process:
Unset
kill -9 <PID>
3.
Changing the priority of a process:
Unset
nice -n 10 command
○
The higher the number, the lower the priority.
Unset
renice -n 10 -p <PID>
4.
Viewing the process tree:
Unset
pstree
Unset
ps aux
2.
Kill a process with PID 1234:
Unset
kill 1234
3.
View processes in a tree structure:
Unset
pstree
40. Disk Management in Linux
Question:
Disk management in Linux involves tasks such as partitioning disks, formatting them, and mounting
file systems. Key tools include fdisk, mkfs, and mount.
Unset
sudo fdisk -l
Unset
sudo fdisk /dev/sda
Unset
sudo mkfs.ext4 /dev/sda1
4.
Mounting a file system:
5.
Adding an entry to /etc/fstab for automatic mounting: Edit the /etc/fstab file:
Unset
sudo nano /etc/fstab
6.
Add an entry for the partition:
Unset
/dev/sda1 /mnt ext4 defaults 0 2
7.
Checking disk usage:
Unset
df -h
8.
Checking disk space on individual files and directories:
Unset
du -sh /path/to/directory
● Practice partitioning disks and formatting them with various file systems
● Learn how to mount file systems manually and configure them for automatic mounting
● Explore disk space management with df and du
Unset
sudo mkfs.ext4 /dev/sda1
2.
Mount /dev/sda1 to /mnt:
Unset
sudo mount /dev/sda1 /mnt
System logs in Linux provide vital information about system events, errors, and services. The main log
directory is /var/log, and common tools used for viewing and managing logs are journalctl,
tail, and grep.
Unset
journalctl
○
To view logs for a specific service:
Unset
journalctl -u service_name
○
To view logs in real-time (similar to tail):
Unset
journalctl -f
2.
Viewing logs in /var/log:
○ Most system logs are stored in /var/log. Some key logs include:
■ /var/log/syslog: General system log
■ /var/log/auth.log: Authentication logs
■ /var/log/dmesg: Boot messages
3. To view logs:
Unset
tail -f /var/log/syslog
4.
Searching logs with grep:
Unset
grep "error" /var/log/syslog
5.
Rotating logs:
○ Log rotation is managed by the logrotate utility, which helps to manage log files by
rotating, compressing, and removing old logs.
○ You can configure it by editing the /etc/logrotate.conf file.
● Explore the /var/log directory and study the different log files
● Practice searching and viewing logs using journalctl, tail, and grep
● Learn how log rotation works and practice configuring it with logrotate
Unset
journalctl
2.
View logs for the SSH service:
Unset
journalctl -u ssh
Managing users and groups is a fundamental aspect of Linux administration. Linux allows you to add,
modify, and delete users and groups using commands like useradd, usermod, userdel, groupadd,
and groupdel.
Unset
sudo useradd username
Unset
sudo useradd -m -s /bin/bash username
2.
Setting a Password for the User:
Unset
sudo passwd username
3.
Modifying a User:
Unset
sudo usermod -s /bin/zsh username
4.
Deleting a User:
Unset
sudo userdel -r username
5.
Adding a Group:
6.
Adding a User to a Group:
Unset
sudo usermod -aG groupname username
7.
Viewing User Information:
Unset
id username
8.
Viewing Groups:
Unset
cat /etc/group
Unset
sudo useradd -m -s /bin/bash john
2.
Set a password for the user john:
Unset
sudo passwd john
3.
Add the user john to the sudo group:
Unset
sudo usermod -aG sudo john
4.
Delete the user john and their home directory:
Unset
sudo userdel -r john
Networking configuration in Linux involves setting up IP addresses, DNS, routing, and more. Key tools
include ifconfig, ip, netstat, and configuration files like /etc/network/interfaces and
/etc/netplan/.
1. Viewing Network Interfaces:
Unset
ifconfig
○ Or
Unset
ip a
2.
Configuring an IP Address:
Unset
sudo ip addr add 192.168.1.100/24 dev eth0
○
To set a default gateway:
Unset
sudo ip route add default via 192.168.1.1
3.
Managing Network Interfaces:
Unset
sudo ifconfig eth0 up
Unset
sudo ip link set eth0 up
4.
Configuring DNS:
Unset
sudo nano /etc/resolv.conf
Unset
nameserver 8.8.8.8
nameserver 8.8.4.4
5.
Using Netplan (for newer Ubuntu systems):
○ For systems using Netplan (such as Ubuntu 18.04+), configure network settings in
/etc/netplan/:
Unset
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: true
6.
Viewing Network Connections:
Unset
netstat -tuln
7.
Testing Network Connectivity:
Unset
ping 8.8.8.8
Unset
sudo ip addr add 192.168.1.100/24 dev eth0
2.
Set the default gateway:
Unset
sudo ip route add default via 192.168.1.1
3.
Edit /etc/resolv.conf to add Google DNS:
Unset
sudo nano /etc/resolv.conf
4.
Add:
Unset
nameserver 8.8.8.8
nameserver 8.8.4.4
File permissions in Linux control who can read, write, or execute a file. Linux uses the chmod,
chown, and chgrp commands for managing permissions.
Unset
ls -l file.txt
2.
Example output:
Unset
-rwxr-xr-x 1 user group 0 Feb 1 12:00 file.txt
3.
Changing Permissions with chmod:
○ To set read, write, and execute permissions for the owner, group, and others:
Unset
chmod 755 file.txt
Unset
sudo chown user file.txt
○
To change both owner and group:
Unset
sudo chown user:group file.txt
5.
Changing Group Ownership with chgrp:
● Practice changing file permissions and ownership with chmod, chown, and chgrp
● Study the symbolic and numeric representations of file permissions
● Understand how file permissions affect file access and security
Unset
chmod 755 file.txt
2.
Change the owner of file.txt to john:
Unset
sudo chown john file.txt
3.
Change the group of file.txt to admin:
Unset
sudo chgrp admin file.txt
Process management is crucial in Linux as it allows you to control and monitor running processes,
which are instances of programs in execution. Commands like ps, top, kill, nice, and htop are
commonly used.
Unset
ps aux
○
This displays detailed information about all processes.
Unset
top
○
For real-time updates with enhanced features, use htop:
Unset
htop
2.
Killing a Process:
○ To terminate a process, use the kill command with the process ID (PID):
Unset
kill PID
○ To forcefully kill a process:
Unset
kill -9 PID
3.
Finding a Process by Name:
Unset
pgrep process_name
4.
Changing Process Priority (Nice Value):
Unset
nice -n 10 command
Unset
renice -n 5 -p PID
5.
Background and Foreground Processes:
Unset
command &
● Learn how to monitor and manage processes using ps, top, and htop
● Practice terminating and modifying process priorities
● Study process states and how to handle them (zombie processes, orphan processes, etc.)
Unset
ps aux
2.
Terminate a process with PID 1234:
Unset
kill 1234
3.
Start a process in the background:
Unset
sleep 60 &
4.
Change the priority of process 1234 to a nice value of 5:
Unset
renice -n 5 -p 1234
Disk management in Linux includes tasks like mounting and unmounting filesystems, partitioning
disks, and checking disk usage. Tools like fdisk, lsblk, mount, umount, and df are commonly
used.
Unset
lsblk
○
Use fdisk to view partitions:
Unset
sudo fdisk -l
2.
Creating Partitions:
Unset
sudo fdisk /dev/sda
○ Inside fdisk, use the following commands:
■ n for a new partition
■ p for primary partition
■ w to write changes
3. Formatting Partitions:
Unset
sudo mkfs.ext4 /dev/sda1
4.
Mounting a Filesystem:
Unset
sudo mount /dev/sda1 /mnt
5.
Unmounting a Filesystem:
○ To unmount a partition:
Unset
sudo umount /mnt
6.
Checking Disk Usage:
Unset
df -h
7.
Checking Disk Health (SMART):
Unset
lsblk
2.
Create a new partition on /dev/sda:
Unset
sudo fdisk /dev/sda
3.
Format partition /dev/sda1 with ext4:
Unset
sudo mkfs.ext4 /dev/sda1
4.
Mount partition /dev/sda1 to /mnt:
Unset
sudo mount /dev/sda1 /mnt
5.
Check disk usage in human-readable format:
Unset
df -h
Package management in Linux allows you to install, update, and remove software packages. Different
Linux distributions use different package managers, such as apt for Debian-based distributions (e.g.,
Ubuntu) and yum or dnf for Red Hat-based distributions (e.g., CentOS, Fedora).
Unset
sudo apt update
○
On Red Hat-based systems (using yum):
Unset
sudo yum install package_name
2.
Removing Software:
○ On Debian-based systems:
Unset
sudo apt remove package_name
○
On Red Hat-based systems:
Unset
sudo yum remove package_name
3.
Updating Software:
○ On Debian-based systems:
Unset
sudo apt update
○
On Red Hat-based systems:
Unset
sudo yum update
4.
Searching for Packages:
○ On Debian-based systems:
Unset
apt search package_name
○
On Red Hat-based systems:
Unset
yum search package_name
5.
Listing Installed Packages:
○ On Debian-based systems:
Unset
dpkg -l
○
On Red Hat-based systems:
Unset
rpm -qa
● Practice installing, updating, and removing software packages on both Debian-based and Red
Hat-based systems
● Learn how to search for and list installed packages
● Study the differences between package managers like apt, yum, and dnf
Unset
sudo apt install curl
2.
Remove the curl package on CentOS:
Unset
sudo yum remove curl
3.
Update all packages on Ubuntu:
Unset
sudo apt update && sudo apt upgrade
4.
Search for the nginx package on CentOS:
Unset
yum search nginx
User and group management in Linux is essential for managing access and permissions. Linux provides
several commands to create, modify, and delete users and groups. The most common commands are
useradd, usermod, userdel, groupadd, groupdel, passwd, and id.
1. Creating a User:
Unset
sudo useradd username
Unset
sudo useradd -m -s /bin/bash username
2.
Setting a Password for a User:
Unset
sudo passwd username
3.
Creating a Group:
Unset
sudo groupadd groupname
4.
Adding a User to a Group:
Unset
sudo usermod -aG groupname username
5.
Modifying User Information:
○ To modify a user's information, such as the home directory or shell:
Unset
sudo usermod -d /new/home/directory -s /bin/bash username
6.
Deleting a User:
○ To delete a user:
Unset
sudo userdel username
Unset
sudo userdel -r username
7.
Deleting a Group:
○ To delete a group:
Unset
sudo groupdel groupname
8.
Viewing User and Group Information:
Unset
id username
Unset
sudo useradd john
2.
Set a password for john:
Unset
sudo passwd john
3.
Create a new group admins:
Unset
sudo groupadd admins
4.
Add john to the admins group:
Unset
sudo usermod -aG admins john
5.
Delete the user john and their home directory:
Unset
sudo userdel -r john
File permissions in Linux control who can read, write, or execute a file. Permissions are set using the
chmod, chown, and chgrp commands. Linux uses a system of three types of permissions (read,
write, and execute) for three types of users (owner, group, and others).
Unset
ls -l filename
2.
Changing File Permissions (chmod):
○ Use chmod to modify file permissions. You can specify permissions using either
symbolic or octal mode.
○ Symbolic mode:
Unset
chmod o-w filename
○
Octal mode:
Unset
chmod 644 filename
3.
Changing Ownership (chown):
Unset
sudo chown user filename
○
To change both the owner and group:
Unset
sudo chown user:group filename
4.
Changing Group Ownership (chgrp):
5.
Special Permissions:
○ Setuid: When applied to an executable file, it allows the program to run with the
privileges of the file owner.
Unset
chmod u+s filename
○
Setgid: When applied to a directory, it ensures that files created within it inherit the
group of the directory.
Unset
chmod g+s directory
○
Sticky Bit: When applied to a directory, it ensures that only the file owner can delete
or rename the files in that directory.
Unset
chmod +t directory
Unset
ls -l file1
2.
Add execute permission for the user john:
Unset
chmod u+x file1
3.
Change the owner of file1 to john:
Unset
sudo chown john file1
4.
Change the group of file1 to admins:
Unset
sudo chgrp admins file1
5.
Set the sticky bit on the /tmp directory:
Unset
sudo chmod +t /tmp
50. Networking in Linux
Question:
Unset
ifconfig
2.
Configuring IP Address (ip command):
Unset
sudo ip addr add 192.168.1.100/24 dev eth0
○
To bring an interface up or down:
Unset
sudo ip link set eth0 up
3.
Checking Network Connectivity (ping):
4.
Checking Network Routes (netstat):
Unset
netstat -r
5.
Viewing Open Ports (ss):
Unset
ss -tuln
6.
Configuring DNS (resolv.conf):
Unset
sudo nano /etc/resolv.conf
○ Add nameservers:
Unset
nameserver 8.8.8.8
nameserver 8.8.4.4
7.
Network Troubleshooting (traceroute):
Unset
ifconfig
2.
Assign IP 192.168.1.100/24 to eth0:
Unset
sudo ip addr add 192.168.1.100/24 dev eth0
3.
Ping google.com:
Unset
ping google.com
4.
View open ports:
Unset
ss -tuln