Linux Unit- 4
Linux Unit- 4
Linux Unit- 4
Linux administration involves managing and maintaining Linux-based systems and servers. It includes
tasks such as installing software, managing user accounts, configuring services, ensuring system security,
troubleshooting issues, and optimizing performance.
Managing Users
Managing users in Linux involves creating, modifying, and deleting user accounts, setting permissions,
and managing groups.
id: Displays user ID (UID), group ID (GID), and groups the user belongs to.
2. Adding Users
Create a New User: sudo useradd -m username
Add User with Specific Options: sudo useradd -m -d /custom/home -s /bin/bash -c "User Full
Name" username
3. Modifying Users
Change User Details: sudo usermod -c "New Full Name" username
Lock/Unlock a User:
5. Managing Groups
View Groups:groups username
6. Managing Permissions
Change File Ownership: sudo chown username:groupname filename
Root Account:
The root account is the default superuser account.
Direct login as root is discouraged for security reasons; use sudo instead.
1. Basic Usage
Prefix commands with sudo: sudo command
After entering your password, the command runs with superuser privileges.
Add a user to the sudo group: sudo usermod -aG sudo username
3. sudo Configuration
The sudo behavior is controlled by the file /etc/sudoers. Use visudo to edit it safely:
sudo visudo
Superuser Responsibilities
System Updates and Maintenance: Regularly update and patch the system to prevent
vulnerabilities.
3 Multi-user mode with networking Full multi-user mode with network services
enabled.
5 Multi-user mode with GUI Multi-user mode with a graphical user interface
(GUI).
Output example: N 3
0 poweroff.target
1 rescue.target
multi-
2, 3, 4
user.target
5 graphical.target
Run Level systemd Target
6 reboot.target
systemctl get-default
Examples of Use
1. Enter Maintenance Mode
Switch to single-user mode for maintenance tasks: sudo systemctl isolate rescue.target
Format as XFS:
5. Persistent Mounts
To make a mount persistent across reboots, edit the /etc/fstab file:
To download:
wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.x.x.tar.xz
cd linux-6.x.x
cd linux
Directory Purpose
tools/ Various tools for testing and debugging (e.g., perf, bpftool).
make menuconfig
o This command opens a menu-based interface to select features, drivers, and modules.
make -j$(nproc)
o Replace $(nproc) with the number of CPU cores for faster compilation.
Step 6: Reboot
Reboot the system to boot into the new kernel: sudo reboot
Applying a Patch
1. Obtain the patch file (e.g., patch-6.x.x).
2. git pull
4. make clean
1. Preparation
Install Required Tools
Before you begin, ensure the necessary development tools and dependencies are installed:
For Debian/Ubuntu:
For RHEL/CentOS:
Ensure you have enough space for the source code and build: df -h
You typically need at least 20 GB of free space.
cd linux-6.x.x
cd linux
Copy the current system's kernel configuration file: cp /boot/config-$(uname -r) .config
Customize the kernel by enabling/disabling features, adding modules, or optimizing for your
hardware.
sudo update-grub
sudo reboot
uname -r
For RHEL/CentOS:
sudo yum install kernel
sudo reboot
uname -r
cd linux-6.x.x
3. Configure Kernel:
make menuconfig
sudo update-grub
sudo reboot
uname -r
Virtualization in Linux
Virtualization refers to creating virtual instances (or virtual machines) of physical hardware, allowing
multiple operating systems to run on a single machine simultaneously. It provides flexibility, efficient
resource use, and isolation between environments.
1. Types of Virtualization
1. Full Virtualization:
2. Paravirtualization:
o The guest operating system is aware it's running in a virtualized environment and
communicates directly with the hypervisor.
2. Hypervisors
A hypervisor is the software layer that enables virtualization by managing virtual machines.
o Runs on top of an existing operating system and relies on it for resource management.
2. Xen:
3. QEMU:
o An emulator and virtualization tool that can run on top of KVM or by itself as a user-
space hypervisor.
o OS-level virtualization that allows running multiple isolated Linux containers on a single
host without the overhead of VMs.
4. Managing Virtualization
Install KVM (Example on Ubuntu/Debian):
kvm-ok
5. Benefits of Virtualization
Resource Utilization: Run multiple operating systems on a single physical machine.
1. Types of Backups
1. Full Backup:
2. Incremental Backup:
o Backs up only the files that have changed since the last backup (whether full or
incremental).
3. Differential Backup:
o Backs up all files that have changed since the last full backup.
4. Mirror Backup:
2. tar
A utility to create compressed archives of files or directories.
3. dd
A low-level tool used for making byte-for-byte copies of data, useful for creating disk images or
cloning disks.
Timeshift:
o Primarily used for creating and restoring system snapshots (similar to Windows Restore
Points).
3. Backup Strategies
1. Onsite vs. Offsite Backups
o Onsite: Store backups locally (e.g., on an external hard drive).
o Offsite: Store backups at a remote location (e.g., in the cloud or another physical
location) to protect against disasters like fire or theft.
2. Automated Backups
o Use cron jobs to automate backup tasks.
Edit crontab:
crontab -e
3. Backup Retention
o Implement a strategy to retain a certain number of backups and delete older ones.
o Example:
Keep daily backups for a week, weekly backups for a month, and monthly
backups for a year.
4. Cloud Backups
1. Rclone:
o A command-line tool to manage files on cloud storage (e.g., Google Drive, AWS S3).
o Example:
rclone config
tar restore:
Timeshift:
sudo update-grub
sudo reboot
uname -r
For RHEL/CentOS:
uname -r
wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.x.x.tar.xz
cd linux-6.x.x
3. Configure Kernel:
make menuconfig
make -j$(nproc)
sudo update-grub
sudo reboot
uname -r