Initial Commit - Taking my own code to my repository - No longer a fork of LinuxLightHouse
This commit is contained in:
parent
d64d7d7b11
commit
07eaea381b
182
01 - Introduction to Linux/Basic Linux Commands.md
Normal file
182
01 - Introduction to Linux/Basic Linux Commands.md
Normal file
@ -0,0 +1,182 @@
|
||||
|
||||
# Basic Linux Commands
|
||||
|
||||
## 1. Navigation and File Management:
|
||||
|
||||
### a) pwd (Print Working Directory)
|
||||
- Shows the current directory path
|
||||
- Usage: pwd
|
||||
|
||||
### b) ls (List)
|
||||
- Lists files and directories in the current directory
|
||||
- Common options:
|
||||
-l: Long format with details
|
||||
-a: Show hidden files
|
||||
-h: Human-readable file sizes
|
||||
- Usage: ls [options] [directory]
|
||||
|
||||
### c) cd (Change Directory)
|
||||
- Changes the current directory
|
||||
- Usage:
|
||||
cd [directory]
|
||||
cd .. (move up one directory)
|
||||
cd ~ (go to home directory)
|
||||
|
||||
### d) mkdir (Make Directory)
|
||||
- Creates a new directory
|
||||
- Usage: mkdir [directory_name]
|
||||
|
||||
### e) rmdir (Remove Directory)
|
||||
- Removes an empty directory
|
||||
- Usage: rmdir [directory_name]
|
||||
|
||||
### f) touch
|
||||
- Creates an empty file or updates timestamps
|
||||
- Usage: touch [filename]
|
||||
|
||||
### g) cp (Copy)
|
||||
- Copies files or directories
|
||||
- Usage: cp [source] [destination]
|
||||
- Options:
|
||||
-r: Recursive (for directories)
|
||||
|
||||
### h) mv (Move)
|
||||
- Moves or renames files and directories
|
||||
- Usage: mv [source] [destination]
|
||||
|
||||
### i) rm (Remove)
|
||||
- Deletes files or directories
|
||||
- Usage: rm [options] [file/directory]
|
||||
- Options:
|
||||
-r: Recursive (for directories)
|
||||
-f: Force deletion without prompting
|
||||
|
||||
## 2. File Viewing and Editing:
|
||||
|
||||
### a) cat (Concatenate)
|
||||
- Displays file contents
|
||||
- Usage: cat [filename]
|
||||
|
||||
### b) less
|
||||
- Views file contents page by page
|
||||
- Usage: less [filename]
|
||||
|
||||
### c) head
|
||||
- Displays the first few lines of a file
|
||||
- Usage: head [options] [filename]
|
||||
- Options:
|
||||
-n [number]: Specify number of lines
|
||||
|
||||
### d) tail
|
||||
- Displays the last few lines of a file
|
||||
- Usage: tail [options] [filename]
|
||||
- Options:
|
||||
-n [number]: Specify number of lines
|
||||
-f: Follow file updates in real-time
|
||||
|
||||
### e) nano
|
||||
- Simple text editor
|
||||
- Usage: nano [filename]
|
||||
|
||||
## 3. File Permissions and Ownership:
|
||||
|
||||
### a) chmod (Change Mode)
|
||||
- Modifies file permissions
|
||||
- Usage: chmod [options] [mode] [file/directory]
|
||||
- Example: chmod 755 file.txt
|
||||
|
||||
### b) chown (Change Owner)
|
||||
- Changes file ownership
|
||||
- Usage: chown [user]:[group] [file/directory]
|
||||
|
||||
## 4. System Information:
|
||||
|
||||
### a) uname
|
||||
- Displays system information
|
||||
- Usage: uname [options]
|
||||
- Options:
|
||||
-a: All information
|
||||
|
||||
### b) df (Disk Free)
|
||||
- Shows disk space usage
|
||||
- Usage: df [options]
|
||||
- Options:
|
||||
-h: Human-readable sizes
|
||||
|
||||
### c) du (Disk Usage)
|
||||
- Estimates file and directory space usage
|
||||
- Usage: du [options] [directory]
|
||||
- Options:
|
||||
-h: Human-readable sizes
|
||||
-s: Summary for directory
|
||||
|
||||
## 5. Process Management:
|
||||
|
||||
### a) ps (Process Status)
|
||||
- Lists running processes
|
||||
- Usage: ps [options]
|
||||
- Common options:
|
||||
aux: Detailed information for all processes
|
||||
|
||||
### b) top
|
||||
- Displays real-time system process information
|
||||
- Usage: top
|
||||
|
||||
### c) kill
|
||||
- Terminates processes
|
||||
- Usage: kill [options] [PID]
|
||||
- Options:
|
||||
-9: Force kill
|
||||
|
||||
## 6. Network Commands:
|
||||
|
||||
### a) ping
|
||||
- Tests network connectivity
|
||||
- Usage: ping [options] [destination]
|
||||
|
||||
### b) ifconfig
|
||||
- Displays network interface information
|
||||
- Usage: ifconfig
|
||||
|
||||
### c) ssh (Secure Shell)
|
||||
- Connects to remote systems securely
|
||||
- Usage: ssh [user]@[host]
|
||||
|
||||
## 7. Package Management (for Debian-based systems):
|
||||
|
||||
### a) apt-get update
|
||||
- Updates package lists
|
||||
- Usage: sudo apt-get update
|
||||
|
||||
### b) apt-get upgrade
|
||||
- Upgrades installed packages
|
||||
- Usage: sudo apt-get upgrade
|
||||
|
||||
### c) apt-get install
|
||||
- Installs new packages
|
||||
- Usage: sudo apt-get install [package_name]
|
||||
|
||||
## 8. File Compression:
|
||||
|
||||
### a) tar
|
||||
- Archives files
|
||||
- Usage: tar [options] [archive_name] [files/directories]
|
||||
- Common options:
|
||||
-c: Create archive
|
||||
-x: Extract archive
|
||||
-v: Verbose
|
||||
-f: Specify archive file
|
||||
- Example: tar -cvf archive.tar files/
|
||||
|
||||
### b) gzip
|
||||
- Compresses files
|
||||
- Usage: gzip [filename]
|
||||
|
||||
### c) gunzip
|
||||
- Decompresses gzip files
|
||||
- Usage: gunzip [filename.gz]
|
||||
|
||||
- [(1) The beginner’s guide to using terminal on Linux Mint - FOSS Linux.](https://www.fosslinux.com/103546/the-beginners-guide-to-using-terminal-on-linux-mint.htm.)
|
||||
- [(2) Official User Guide - Linux Mint.](https://www.linuxmint.com/documentation/user-guide/Cinnamon/english_18.0.pdf.)
|
||||
- [(3) BEGINNER'S GUIDE FOR LINUX - Start Learning Linux in Minutes - Tecmint.](https://www.tecmint.com/free-online-linux-learning-guide-for-beginners/.)
|
||||
- [(4) Useful Basic Terminal Commands On Linux Mint 11 - HowtoForge.](https://www.howtoforge.com/useful-basic-terminal-commands-on-linux-mint-11.)
|
||||
@ -0,0 +1,69 @@
|
||||
# Configuring and Customizing Linux Mint
|
||||
|
||||
## **Introduction to Linux Mint**
|
||||
Linux Mint is a popular, user-friendly Ubuntu-based distribution that is known for its simplicity, stability, and wide range of customization options. It comes with a variety of desktop environments, including Cinnamon, MATE, and Xfce, each with its own unique features and layouts.
|
||||
|
||||
## **Configuring Linux Mint**
|
||||
### 1. **Initial Setup**:
|
||||
- When you first boot into Linux Mint, you'll be greeted with the welcome screen. Here, you can choose your preferred language, keyboard layout, and timezone.
|
||||
- Next, you'll be asked to create a user account. It's recommended to use a strong and unique password for this account.
|
||||
- During the setup process, you can also enable automatic updates, which will keep your system secure and up-to-date.
|
||||
|
||||
### 2. **Software Management**:
|
||||
- Linux Mint comes with a wide range of pre-installed applications, but you may want to install additional software to suit your needs.
|
||||
- The built-in Software Manager provides an easy-to-use interface for browsing, installing, and removing applications.
|
||||
- You can also use the command line package manager, `apt`, to install, update, and remove software packages.
|
||||
|
||||
### 3. **System Settings**:
|
||||
- The System Settings application allows you to customize various aspects of your Linux Mint installation, such as the appearance, desktop behavior, and hardware settings.
|
||||
- You can change the desktop wallpaper, adjust the font settings, and configure the panel and menu layout.
|
||||
- The Display settings allow you to manage your screen resolution, refresh rate, and multi-monitor configurations.
|
||||
- The Input Devices section lets you configure your mouse, keyboard, and touchpad settings.
|
||||
|
||||
### 4. **Drivers and Hardware**:
|
||||
- Linux Mint generally does a good job of automatically detecting and installing the necessary drivers for your hardware.
|
||||
- However, you may need to install additional drivers for specific hardware, such as graphics cards or wireless network adapters.
|
||||
- The Driver Manager tool can help you identify and install the appropriate drivers for your system.
|
||||
|
||||
### 5. **User Accounts and Permissions**:
|
||||
- Linux Mint allows you to create and manage multiple user accounts with different levels of access and permissions.
|
||||
- You can add new users, change passwords, and configure user groups through the User Accounts section of the System Settings.
|
||||
- It's a good practice to create a separate user account for daily use and use the root account only when necessary.
|
||||
|
||||
### 6. **Backup and Restore**:
|
||||
- Regular backups are essential to protect your data in case of system failures or other issues.
|
||||
- Linux Mint includes a built-in backup tool, called Timeshift, which allows you to create system snapshots and restore your system to a previous state if needed.
|
||||
- You can also use third-party backup tools, such as Duplicati or Rsync, to create more comprehensive backup strategies.
|
||||
|
||||
## **Customizing Linux Mint**
|
||||
### 1. **Desktop Environments**:
|
||||
- Linux Mint supports several desktop environments, including Cinnamon, MATE, and Xfce.
|
||||
- Each desktop environment has its own unique look and feel, as well as a set of pre-installed applications and tools.
|
||||
- You can switch between desktop environments by logging out and selecting the desired option from the login screen.
|
||||
|
||||
### 2. **Themes and Appearances**:
|
||||
- Linux Mint offers a wide range of themes and customization options to change the look and feel of your desktop.
|
||||
- You can find and install new themes, icons, and cursors through the Themes section of the System Settings.
|
||||
- There are numerous community-created themes and customization packs available online that you can download and install.
|
||||
|
||||
### 3. **Applets and Desklets**:
|
||||
- Applets and desklets are small applications that can be added to your desktop or panel to provide additional functionality and information.
|
||||
- The Cinnamon desktop environment, in particular, offers a rich ecosystem of applets and desklets that you can browse and install through the Applets and Desklets sections of the System Settings.
|
||||
|
||||
### 4. **Extensions and Plugins**:
|
||||
- Linux Mint supports various extensions and plugins that can enhance the functionality of your desktop environment and applications.
|
||||
- For example, you can install browser extensions to add new features to your web browsing experience.
|
||||
- The available extensions and plugins will depend on the desktop environment you're using and the software you have installed.
|
||||
|
||||
### 5. **Command Line Customization**:
|
||||
- While Linux Mint is known for its user-friendly graphical interface, you can also customize your system using the command line.
|
||||
- This includes modifying system configuration files, creating custom scripts, and utilizing advanced command-line tools.
|
||||
- Some popular command-line customization options include setting up aliases, configuring the shell (e.g., Bash, Zsh), and installing and configuring system utilities.
|
||||
|
||||
### 6. **Scripting and Automation**:
|
||||
- Linux Mint's flexibility allows you to automate various tasks and workflows using scripts.
|
||||
- You can create shell scripts (e.g., Bash, Zsh) to automate routine tasks, system maintenance, and more.
|
||||
- Additionally, you can explore tools like cron for scheduling recurring tasks and systemd for managing system services.
|
||||
|
||||
## **Conclusion**
|
||||
Linux Mint is a highly customizable operating system that offers a wide range of configuration and personalization options. By exploring the various settings, tools, and community resources, you can create a Linux Mint installation that perfectly suits your needs and preferences. Remember to always back up your system before making significant changes, and enjoy the process of tailoring your Linux Mint experience.
|
||||
142
01 - Introduction to Linux/Different Distros.md
Normal file
142
01 - Introduction to Linux/Different Distros.md
Normal file
@ -0,0 +1,142 @@
|
||||
# Introduction to Linux Distributions
|
||||
|
||||
A Linux distribution, or "distro," is an operating system based on the Linux kernel, combined with a package management system and various software packages. Each distro has its own characteristics, target audience, and philosophy.
|
||||
|
||||
Major Categories of Linux Distributions:
|
||||
|
||||
## 1. Desktop-Oriented Distributions:
|
||||
These are designed for personal computers and laptops, focusing on user-friendliness and productivity.
|
||||
|
||||
### a) Ubuntu:
|
||||
- One of the most popular distros
|
||||
- Based on Debian
|
||||
- Known for ease of use and regular updates
|
||||
- Large community and extensive software repositories
|
||||
- Various flavors available (Kubuntu, Xubuntu, Lubuntu)
|
||||
|
||||
### b) Linux Mint:
|
||||
- Based on Ubuntu
|
||||
- Aims to be more user-friendly for newcomers
|
||||
- Comes with proprietary software and codecs pre-installed
|
||||
- Offers Cinnamon, MATE, and Xfce desktop environments
|
||||
|
||||
### c) Fedora:
|
||||
- Sponsored by Red Hat
|
||||
- Focuses on innovation and latest technologies
|
||||
- Uses cutting-edge software versions
|
||||
- Workstation version for desktop users, Server and IoT editions available
|
||||
|
||||
### d) elementary OS:
|
||||
- Based on Ubuntu
|
||||
- Emphasizes aesthetic design and user experience
|
||||
- Custom desktop environment called Pantheon
|
||||
- Aims to be a replacement for macOS and Windows
|
||||
|
||||
### e) Manjaro:
|
||||
- Based on Arch Linux
|
||||
- User-friendly approach to Arch's rolling release model
|
||||
- Offers multiple desktop environments
|
||||
- Hardware detection and driver installation out of the box
|
||||
|
||||
## 2. Server-Oriented Distributions:
|
||||
These focus on stability, security, and performance for server environments.
|
||||
|
||||
### a) Red Hat Enterprise Linux (RHEL):
|
||||
- Commercial, enterprise-grade distribution
|
||||
- Known for stability and long-term support
|
||||
- Widely used in corporate environments
|
||||
|
||||
### b) CentOS:
|
||||
- Free, community-supported version of RHEL
|
||||
- Recently shifted to CentOS Stream, which is upstream of RHEL
|
||||
|
||||
### c) Debian:
|
||||
- Known for its stability and large software repositories
|
||||
- Forms the base for many other distributions
|
||||
- Strict adherence to free software principles
|
||||
|
||||
### d) Ubuntu Server:
|
||||
- Server version of Ubuntu
|
||||
- Popular for cloud deployments and container hosts
|
||||
- Regular releases and long-term support options
|
||||
|
||||
## 3. Security-Focused Distributions:
|
||||
These prioritize privacy, anonymity, and security features.
|
||||
|
||||
### a) Kali Linux:
|
||||
- Designed for penetration testing and security auditing
|
||||
- Comes with numerous security and hacking tools pre-installed
|
||||
- Based on Debian
|
||||
|
||||
### b) Tails:
|
||||
- Focuses on privacy and anonymity
|
||||
- Runs from a live USB or DVD
|
||||
- Routes all internet traffic through Tor network
|
||||
|
||||
### c) Qubes OS:
|
||||
- Uses virtualization for security
|
||||
- Compartmentalizes different activities into separate VMs
|
||||
- Complex but highly secure
|
||||
|
||||
## 4. Lightweight Distributions:
|
||||
Designed to run on older or low-spec hardware.
|
||||
|
||||
### a) Lubuntu:
|
||||
- Official Ubuntu flavor using the LXQt desktop
|
||||
- Lightweight and fast, suitable for older computers
|
||||
|
||||
### b) Puppy Linux:
|
||||
- Extremely lightweight, can run entirely in RAM
|
||||
- Various versions based on different distros (Ubuntu, Slackware)
|
||||
|
||||
### c) Tiny Core Linux:
|
||||
- Minimalist distribution, very small core system
|
||||
- Modular approach for adding functionality
|
||||
|
||||
## 5. Specialized Distributions:
|
||||
Designed for specific use cases or hardware.
|
||||
|
||||
### a) Raspberry Pi OS:
|
||||
- Optimized for Raspberry Pi hardware
|
||||
- Based on Debian
|
||||
- Comes with educational and development tools
|
||||
|
||||
### b) Ubuntu Studio:
|
||||
- Focused on multimedia production
|
||||
- Comes with audio, video, and graphics software pre-installed
|
||||
|
||||
## c) SteamOS:
|
||||
- Developed by Valve for gaming
|
||||
- Based on Debian, optimized for Steam and gaming performance
|
||||
|
||||
## Key Factors in Choosing a Distribution:
|
||||
- Purpose (desktop, server, security, etc.)
|
||||
- Hardware compatibility and requirements
|
||||
- User experience and ease of use
|
||||
- Software availability and package management
|
||||
- Release cycle (fixed vs. rolling release)
|
||||
- Community support and documentation
|
||||
- Stability vs. bleeding-edge software
|
||||
|
||||
## Package Management Systems:
|
||||
Different distributions use various package management systems:
|
||||
- Debian-based: APT (dpkg)
|
||||
- Red Hat-based: DNF (formerly YUM)
|
||||
- Arch-based: Pacman
|
||||
- SUSE: Zypper
|
||||
|
||||
These systems handle software installation, updates, and dependencies.
|
||||
|
||||
## Desktop Environments:
|
||||
Linux distributions often offer multiple desktop environments, including:
|
||||
- GNOME
|
||||
- KDE Plasma
|
||||
- Xfce
|
||||
- MATE
|
||||
- Cinnamon
|
||||
- LXDE/LXQt
|
||||
|
||||
Each offers different features, resource usage, and customization options.
|
||||
|
||||
## In conclusion:
|
||||
The Linux ecosystem offers a wide variety of distributions catering to different needs, preferences, and hardware configurations. Users can choose based on their specific requirements, whether it's ease of use, performance, security, or specialized functionality. The open-source nature of Linux allows for extensive customization and community-driven development, continually improving and expanding the options available to users.
|
||||
15
01 - Introduction to Linux/History of Linux.md
Normal file
15
01 - Introduction to Linux/History of Linux.md
Normal file
@ -0,0 +1,15 @@
|
||||
# Linux has a fascinating history that dates back to the early 1990s.
|
||||
|
||||
1. **Origins**: Linux began as a personal project by Linus Torvalds, a Finnish student, in 1991. He aimed to create a free operating system kernel¹².
|
||||
2. **Unix Influence**: The development of Linux was heavily influenced by Unix, an operating system created by Ken Thompson and Dennis Ritchie at AT&T Bell Labs in 1969¹².
|
||||
3. **GNU Project**: In 1983, Richard Stallman started the GNU Project to create a free Unix-like operating system. Although the GNU kernel (Hurd) was incomplete, the project provided many essential tools for Linux¹².
|
||||
4. **Release of Linux**: Linus Torvalds released the first version of the Linux kernel on September 17, 1991. It quickly gained popularity among developers and the open-source community¹².
|
||||
5. **Growth and Development**: Over the years, Linux has grown significantly, with contributions from developers worldwide. It has become the foundation for many operating systems, including popular distributions like Ubuntu, Fedora, and Debian¹².
|
||||
|
||||
- [Wikipedia: History of Linux](https://en.wikipedia.org/wiki/History_of_Linux)¹
|
||||
- [LinuxSimply: History of Linux](https://linuxsimply.com/linux-basics/introduction/history-of-linux/)²
|
||||
|
||||
- [(1) History of Linux - Wikipedia.](https://en.wikipedia.org/wiki/History_of_Linux.)
|
||||
- [(2) History of Linux [A Complete Overview] - LinuxSimply.](https://linuxsimply.com/linux-basics/introduction/history-of-linux/.)
|
||||
= [(3) History of Linux - GeeksforGeeks.](https://www.geeksforgeeks.org/linux-history/.)
|
||||
- [(4) The Complete History of Linux: Everything You Need to Know.](https://www.historytools.org/companies/the-complete-history-of-linux-everything-you-need-to-know.)
|
||||
@ -0,0 +1,44 @@
|
||||
# Installing Linux Mint
|
||||
|
||||
## **Step 1: Download Linux Mint**
|
||||
- Go to the official Linux Mint website (https://www.linuxmint.com/) and download the latest version of Linux Mint for your system (e.g., 64-bit or 32-bit).
|
||||
- The download will be an ISO file, which is an image of the Linux Mint operating system.
|
||||
|
||||
## **Step 2: Create a Bootable USB or DVD**
|
||||
- You'll need to create a bootable USB drive or DVD to install Linux Mint. There are several tools you can use for this, such as Balena Etcher, Rufus, or the built-in tool in Windows 10/11.
|
||||
- Insert a blank USB drive or DVD, and use your preferred tool to write the Linux Mint ISO file to the media.
|
||||
|
||||
## **Step 3: Boot from the Bootable Media**
|
||||
- Insert the bootable USB drive or DVD into your computer.
|
||||
- Restart your computer and enter the boot menu. This is usually done by pressing a specific key during the boot process, such as F2, F12, or Del, depending on your computer's manufacturer.
|
||||
- Select the option to boot from the USB drive or DVD.
|
||||
|
||||
## **Step 4: Start the Installation**
|
||||
- Once your computer boots from the bootable media, you'll see the Linux Mint live environment.
|
||||
- Click on the "Install Linux Mint" icon on the desktop to begin the installation process.
|
||||
|
||||
## **Step 5: Choose Your Installation Type**
|
||||
- The installer will guide you through the installation process.
|
||||
- You'll be asked to choose the type of installation:
|
||||
- **Erase disk and install Linux Mint**: This will delete all existing data on your hard drive and install Linux Mint.
|
||||
- **Install Linux Mint alongside Windows**: This will create a dual-boot setup, allowing you to choose between Windows and Linux Mint at startup.
|
||||
- **Something else**: This option allows you to manually partition your hard drive and customize the installation.
|
||||
|
||||
## **Step 6: Configure Your Installation**
|
||||
- Choose your preferred language, time zone, and keyboard layout.
|
||||
- Create a username and password for your user account.
|
||||
|
||||
## **Step 7: Install Linux Mint**
|
||||
- Review the installation settings and click "Install" to start the installation process.
|
||||
- The installation may take several minutes, depending on the speed of your computer and the selected installation options.
|
||||
|
||||
## **Step 8: Finish the Installation**
|
||||
- Once the installation is complete, the installer will prompt you to remove the bootable media and restart your computer.
|
||||
- After the restart, you'll be greeted with the Linux Mint login screen, where you can enter the username and password you created earlier.
|
||||
|
||||
## **Step 9: Explore Linux Mint**
|
||||
- Congratulations! You've successfully installed Linux Mint on your computer.
|
||||
- Take some time to explore the Linux Mint desktop environment, installed applications, and various settings.
|
||||
- You can also install additional software, configure your system preferences, and customize the appearance to your liking.
|
||||
|
||||
Remember, the installation process may vary slightly depending on your hardware and personal preferences, but this guide should provide a comprehensive overview of the steps involved in installing Linux Mint. If you encounter any issues or have additional questions, don't hesitate to consult the Linux Mint documentation or reach out to the community for support.
|
||||
@ -0,0 +1,87 @@
|
||||
## 1. Introduction to the Linux CLI
|
||||
- What is the CLI?
|
||||
- Why use CLI over GUI?
|
||||
- Accessing the terminal
|
||||
|
||||
## 2. Basic CLI Navigation and File Management
|
||||
- pwd (print working directory)
|
||||
- ls (list directory contents)
|
||||
- cd (change directory)
|
||||
- mkdir (make directory)
|
||||
- touch (create empty file)
|
||||
- cp (copy)
|
||||
- mv (move/rename)
|
||||
- rm (remove)
|
||||
|
||||
## 3. Viewing and Editing Files
|
||||
- cat (concatenate and display file content)
|
||||
- less (view file contents page by page)
|
||||
- head and tail (view beginning or end of file)
|
||||
- nano and vim (text editors)
|
||||
|
||||
## 4. File Permissions and Ownership
|
||||
- chmod (change file permissions)
|
||||
- chown (change file ownership)
|
||||
- Understanding permission notation (rwx)
|
||||
|
||||
## 5. Process Management
|
||||
- ps (list processes)
|
||||
- top (dynamic process viewer)
|
||||
- kill (terminate processes)
|
||||
- jobs, bg, and fg (background and foreground processes)
|
||||
|
||||
## 6. System Information and Management
|
||||
- uname (system information)
|
||||
- df (disk space usage)
|
||||
- du (directory space usage)
|
||||
- free (memory usage)
|
||||
- shutdown and reboot
|
||||
|
||||
## 7. Package Management
|
||||
- apt (Debian/Ubuntu)
|
||||
- yum (Red Hat/CentOS)
|
||||
- pacman (Arch Linux)
|
||||
|
||||
## 8. Networking
|
||||
- ifconfig / ip (network interface configuration)
|
||||
- ping (test network connectivity)
|
||||
- ssh (secure shell)
|
||||
- scp (secure copy)
|
||||
- wget (download files)
|
||||
|
||||
## 9. Text Processing and Searching
|
||||
- grep (search for patterns in files)
|
||||
- sed (stream editor for filtering and transforming text)
|
||||
- awk (pattern scanning and text processing)
|
||||
- find (search for files and directories)
|
||||
|
||||
## 10. Piping and Redirection
|
||||
- | (pipe operator)
|
||||
- > and >> (output redirection)
|
||||
- < (input redirection)
|
||||
|
||||
## 11. Shell Scripting Basics
|
||||
- Creating and running shell scripts
|
||||
- Variables and environment variables
|
||||
- Conditional statements (if, else, elif)
|
||||
- Loops (for, while)
|
||||
|
||||
## 12. Advanced CLI Features
|
||||
- Command history and shortcuts
|
||||
- Tab completion
|
||||
- Aliases
|
||||
- Regular expressions
|
||||
|
||||
## 13. System Logs and Troubleshooting
|
||||
- journalctl (view system logs)
|
||||
- dmesg (display kernel messages)
|
||||
- lsof (list open files)
|
||||
|
||||
4. **Superuser Powers**:
|
||||
- Some tasks require administrator privileges. To execute commands as the superuser (root), prefix them with `sudo`.
|
||||
- Be cautious with superuser access—it's powerful!
|
||||
|
||||
|
||||
- [(1) The Linux command line for beginners | Ubuntu.](https://ubuntu.com/tutorials/command-line-for-beginners.)
|
||||
- [(2) What is Terminal in Linux? The Ultimate Guide LinuxSimply.](https://linuxsimply.com/what-is-terminal-in-linux/.)
|
||||
- [(3) Ubuntu Terminal Beginner's Guide to Command Line Interface - FOSS Linux.](https://www.fosslinux.com/101137/the-ubuntu-terminal-getting-started-with-the-command-line-interface.htm.)
|
||||
@ -0,0 +1,3 @@
|
||||
# Linux Filesystem Hierarchy Standard (LFHS)
|
||||
|
||||
[LFHS](https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html)
|
||||
75
01 - Introduction to Linux/Linux History.md
Normal file
75
01 - Introduction to Linux/Linux History.md
Normal file
@ -0,0 +1,75 @@
|
||||
#
|
||||
|
||||
## - 1. Pre-Linux Era (1960s-1991)
|
||||
## - 2. Birth of Linux (1991-1994)
|
||||
## - 3. Early Growth and Development (1994-2000)
|
||||
## - 4. Mainstream Adoption (2000-2010)
|
||||
## - 5. Modern Era (2010-Present)
|
||||
|
||||
|
||||
## 1. Pre-Linux Era (1960s-1991):
|
||||
|
||||
To understand Linux, we need to start with UNIX, its predecessor:
|
||||
|
||||
- 1969: Ken Thompson and Dennis Ritchie at Bell Labs develop UNIX.
|
||||
- 1973: UNIX is rewritten in C, making it more portable.
|
||||
- 1983: Richard Stallman announces the GNU Project, aiming to create a free UNIX-like operating system.
|
||||
- 1987: Andrew Tanenbaum creates MINIX, a simplified UNIX-like OS for educational purposes.
|
||||
|
||||
## 2. Birth of Linux (1991-1994):
|
||||
|
||||
- August 25, 1991: Linus Torvalds, a Finnish computer science student, announces his project on the comp.os.minix newsgroup:
|
||||
|
||||
"I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones."
|
||||
|
||||
- September 17, 1991: Torvalds releases Linux 0.01, the first version.
|
||||
- 1992: Linux is relicensed under the GNU General Public License (GPL).
|
||||
- 1993: Over 100 developers are working on the Linux kernel.
|
||||
- 1994: Linux 1.0 is released, featuring a complete operating system.
|
||||
|
||||
## 3. Early Growth and Development (1994-2000):
|
||||
|
||||
- 1995: Linux is ported to the DEC Alpha and Sun SPARC architectures.
|
||||
- 1996: Linux 2.0 is released, adding support for multiple processors.
|
||||
- 1998: Major companies like IBM, Compaq, and Oracle announce support for Linux.
|
||||
- 1999: Red Hat and VA Linux go public, demonstrating Linux's commercial potential.
|
||||
|
||||
## 4. Mainstream Adoption (2000-2010):
|
||||
|
||||
- 2000: IBM announces it will invest $1 billion in Linux development.
|
||||
- 2003: Linux 2.6 is released, greatly improving scalability and performance.
|
||||
- 2005: Linus Torvalds creates Git, a version control system, to manage Linux kernel development.
|
||||
- 2007: Major smartphone manufacturers begin adopting Linux-based Android.
|
||||
- 2008: Linux is used in 60% of web servers worldwide.
|
||||
|
||||
## 5. Modern Era (2010-Present):
|
||||
|
||||
- 2011: Linux 3.0 is released, mainly as a time-based release.
|
||||
- 2015: Linux 4.0 introduces live kernel patching.
|
||||
- 2019: Microsoft releases Windows Subsystem for Linux 2 (WSL 2), integrating Linux more deeply with Windows.
|
||||
- 2020: Linux 5.10 is designated as a Long Term Support (LTS) release.
|
||||
- 2021: Linux celebrates its 30th anniversary.
|
||||
- 2023: Linux 6.x series continues to evolve, focusing on improved hardware support and security features.
|
||||
|
||||
## Current State (as of 2024):
|
||||
|
||||
Linux has become ubiquitous in many areas:
|
||||
|
||||
- Powers most of the world's supercomputers
|
||||
- Dominates the server market
|
||||
- Forms the basis of Android, the most popular mobile OS
|
||||
- Widely used in embedded systems and IoT devices
|
||||
- Gaining traction in desktop environments, especially among developers and tech enthusiasts
|
||||
|
||||
## Key Factors in Linux's Success:
|
||||
|
||||
- Open-source model: Allowing anyone to view, modify, and distribute the source code.
|
||||
- Modular design: Enabling easy customization and adaptation.
|
||||
- Community development: Leveraging global talent and diverse perspectives.
|
||||
- Corporate adoption: Major tech companies investing in and supporting Linux.
|
||||
- Versatility: Used in everything from embedded systems to supercomputers.
|
||||
|
||||
|
||||
The Linux kernel continues to evolve rapidly, with new versions released approximately every 9-10 weeks. It remains a collaborative effort, with thousands of developers worldwide contributing to its development.
|
||||
|
||||
Linux has grown from a hobby project to a critical component of the global technology infrastructure, demonstrating the power of open-source development and community collaboration.
|
||||
@ -0,0 +1,84 @@
|
||||
# Linux Operating System Structure
|
||||
|
||||
## 1. **Kernel**:
|
||||
- The kernel is the core of the Linux operating system.
|
||||
- It is responsible for managing the system's hardware resources, such as the CPU, memory, and I/O devices.
|
||||
- The kernel provides an abstraction layer between the hardware and the software, allowing applications to interact with the hardware without needing to know the specific details of the underlying hardware.
|
||||
- The kernel is responsible for tasks such as process management, memory management, file management, and device management.
|
||||
- The Linux kernel is typically monolithic, meaning that all the kernel functions are in a single, large executable.
|
||||
- The kernel can be customized and configured to meet the specific needs of the system.
|
||||
|
||||
## 2. **User Space**:
|
||||
- The user space is the area of the operating system where user-level applications and processes run.
|
||||
- User-level applications, such as web browsers, email clients, and text editors, are not part of the kernel and run in the user space.
|
||||
- The user space is where most of the day-to-day activities of the system take place.
|
||||
- User-level applications interact with the kernel through system calls, which are a set of interfaces provided by the kernel.
|
||||
|
||||
## 3. **File System**:
|
||||
- The file system is the way in which files and directories are organized and stored on the storage devices.
|
||||
- Linux supports various file systems, such as ext4, XFS, Btrfs, and more.
|
||||
- The file system is responsible for managing the storage, retrieval, and organization of files and directories.
|
||||
- The file system provides a hierarchical structure, where files and directories are organized in a tree-like structure, with the root directory at the top.
|
||||
- The file system also manages permissions and access control to files and directories.
|
||||
|
||||
## 4. **Boot Process**:
|
||||
- The boot process is the sequence of events that occurs when the system is powered on or restarted.
|
||||
- The boot process starts with the BIOS (Basic Input/Output System) or UEFI (Unified Extensible Firmware Interface), which performs hardware checks and loads the boot loader.
|
||||
- The boot loader, such as GRUB (Grand Unified Bootloader) or systemd-boot, is responsible for loading the kernel and the initial ramdisk (initrd) into memory.
|
||||
- The kernel then takes over and initializes the system, loading various kernel modules and starting the init system (such as systemd or SysVinit).
|
||||
- The init system is responsible for starting and managing the various services and processes that make up the operating system.
|
||||
|
||||
## 5. **Process Management**:
|
||||
- The process management subsystem is responsible for managing the execution of processes and threads.
|
||||
- Processes are instances of running programs, and threads are lightweight processes that share the same memory space.
|
||||
- The kernel is responsible for creating, scheduling, and terminating processes and threads.
|
||||
- The process management subsystem also includes features like inter-process communication (IPC), which allows processes to exchange data and synchronize their execution.
|
||||
|
||||
## 6. **Memory Management**:
|
||||
- The memory management subsystem is responsible for managing the system's physical and virtual memory.
|
||||
- The kernel provides a virtual memory system, which allows applications to use more memory than is physically available on the system.
|
||||
- The memory management subsystem is responsible for allocating and freeing memory, as well as implementing techniques like paging and swapping to manage the virtual memory system.
|
||||
|
||||
## 7. **Device Management**:
|
||||
- The device management subsystem is responsible for managing the various hardware devices connected to the system.
|
||||
- The kernel provides a uniform interface for interacting with devices, abstracting away the details of the underlying hardware.
|
||||
- The device management subsystem includes drivers for different types of devices, such as storage devices, network devices, and input/output devices.
|
||||
- The device management subsystem also includes a plug-and-play system, which allows devices to be automatically detected and configured when they are connected to the system.
|
||||
|
||||
## 8. **Network Stack**:
|
||||
- The network stack is the set of protocols and services that enable network communication in the Linux operating system.
|
||||
- The network stack includes protocols like TCP/IP, UDP, and ICMP, as well as higher-level protocols like HTTP, FTP, and SSH.
|
||||
- The network stack is responsible for sending and receiving network packets, as well as managing network interfaces and routing.
|
||||
- The network stack also includes features like firewalling, network address translation (NAT), and virtual private networks (VPNs).
|
||||
|
||||
This covers the major components and subsystems of the Linux operating system structure. Each of these components plays a crucial role in the overall functioning of the system, providing the foundation for the applications and services that run on top of the Linux platform.
|
||||
=======
|
||||
#
|
||||
|
||||
1. **Root Directory (`/`)**:
|
||||
- The root directory is the starting point for all files and directories in Linux. It's analogous to a plant's root system. Everything else is organized under this root.
|
||||
- Absolute paths of files are traced back from the root. For instance, if you have a file at `/home/user/documents`, the directory structure goes: root → home → user → documents.
|
||||
- Fun fact: There's a famous (but dangerous) joke about running `rm -rf /`—it would theoretically delete everything in your Linux system! 😅
|
||||
|
||||
2. **/bin (Binaries)**:
|
||||
- `/bin` contains essential executable files for basic shell commands like `ls`, `cp`, and `cd`.
|
||||
- These programs are typically in binary format and are accessible to all users on the system.
|
||||
|
||||
3. **/dev (Device Files)**:
|
||||
- `/dev` houses special files related to devices. These files are virtual and don't physically exist on the disk.
|
||||
- Examples:
|
||||
- `/dev/null`: Used to discard data
|
||||
- `/dev/zero`: Contains an infinite sequence of zeros
|
||||
- `/dev/random`: Provides random values
|
||||
|
||||
4. **/etc (Configuration Files)**:
|
||||
- `/etc` holds core configuration files used by the system administrator and services.
|
||||
- Examples include password files and networking configurations.
|
||||
- When you need to tweak system settings (like changing the hostname), you'll find the relevant files here¹.
|
||||
|
||||
|
||||
- [(1) Linux Directory Structure Explained for Beginners.](https://linuxhandbook.com/linux-directory-structure/.)
|
||||
- [(2) What is Linux? {Understanding Linux Operating System} - phoenixNAP.](https://phoenixnap.com/kb/what-is-linux.)
|
||||
- [(3) Architecture of Linux Operating System - LinuxSimply.](https://linuxsimply.com/linux-basics/introduction/architecture-of-linux-operating-system/.)
|
||||
- [(4) What is Linux? - Red Hat.](https://www.redhat.com/en/topics/linux/what-is-linux.)
|
||||
- [(5) en.wikipedia.org.](https://en.wikipedia.org/wiki/Linux.)
|
||||
197
02 - Basic System Operations/File and Directory Management.md
Normal file
197
02 - Basic System Operations/File and Directory Management.md
Normal file
@ -0,0 +1,197 @@
|
||||
# Linux File and Directory management
|
||||
|
||||
## 1. File System Hierarchy:
|
||||
Linux follows a hierarchical file system structure, starting with the root directory (/). Key directories include:
|
||||
|
||||
- /home: User home directories
|
||||
- /etc: System configuration files
|
||||
- /var: Variable data (logs, temporary files)
|
||||
- /usr: User binaries and program files
|
||||
- /bin: Essential command binaries
|
||||
- /sbin: System binaries
|
||||
- /tmp: Temporary files
|
||||
|
||||
## 2. Basic Commands:
|
||||
|
||||
### - Listing files and directories:
|
||||
```
|
||||
ls [options] [directory]
|
||||
```
|
||||
Common options:
|
||||
- -l: Long format
|
||||
- -a: Show hidden files
|
||||
- -h: Human-readable file sizes
|
||||
|
||||
### - Changing directories:
|
||||
```
|
||||
cd [directory]
|
||||
```
|
||||
- cd ..: Move up one directory
|
||||
- cd ~: Go to home directory
|
||||
- cd /: Go to root directory
|
||||
|
||||
### - Creating directories:
|
||||
```
|
||||
mkdir [options] directory_name
|
||||
```
|
||||
Common options:
|
||||
- mkdir -p: Create parent directories if they don't exist
|
||||
|
||||
### - Removing directories:
|
||||
```
|
||||
rmdir [options] directory_name
|
||||
```
|
||||
Common options:
|
||||
- rm -r directory_name: Remove non-empty directories
|
||||
|
||||
### - Creating files:
|
||||
```
|
||||
touch file_name
|
||||
```
|
||||
|
||||
### - Copying files and directories:
|
||||
```
|
||||
cp [options] source destination
|
||||
```
|
||||
Common options:
|
||||
- cp -r: Copy directories recursively
|
||||
|
||||
### - Moving/renaming files and directories:
|
||||
```
|
||||
mv source destination
|
||||
```
|
||||
|
||||
### - Removing files:
|
||||
```
|
||||
rm [options] file_name
|
||||
```
|
||||
Common options:
|
||||
- rm -f: Force removal without prompting
|
||||
|
||||
## 3. File Permissions:
|
||||
|
||||
Linux uses a permission system with read (r), write (w), and execute (x) permissions for owner, group, and others.
|
||||
|
||||
### Viewing permissions:
|
||||
```
|
||||
ls -l
|
||||
```
|
||||
|
||||
### Changing permissions:
|
||||
```
|
||||
chmod [options] mode file
|
||||
```
|
||||
Example: chmod 755 file_name
|
||||
|
||||
### Changing ownership:
|
||||
```
|
||||
chown [options] user:group file
|
||||
```
|
||||
|
||||
## 4. File Manipulation:
|
||||
|
||||
### Viewing file contents:
|
||||
```
|
||||
cat file_name #Print entire file at once
|
||||
less file_name #View file in a pager format
|
||||
more file_name #View file in a pager format
|
||||
head file_name #View top 10 lines (default) of a file
|
||||
tail file_name #View last 10 lines (default) of a file
|
||||
```
|
||||
|
||||
### Searching file contents:
|
||||
```
|
||||
grep [options] pattern file
|
||||
```
|
||||
Common options:
|
||||
- -i: Insensitive Case Search
|
||||
- -R: search recursively in parent Directory, as well as all child directories.
|
||||
|
||||
### Comparing files:
|
||||
```
|
||||
diff file1 file2
|
||||
```
|
||||
|
||||
## 5. Advanced File Management:
|
||||
|
||||
### Finding files:
|
||||
```
|
||||
find [path] [expression]
|
||||
```
|
||||
Example: find /home -name "*.txt"
|
||||
|
||||
### Disk usage:
|
||||
```
|
||||
du [options] [directory]
|
||||
```
|
||||
Common options:
|
||||
- -h: Print disk usage in human-readable format
|
||||
- -s: Summarize disk usage information
|
||||
|
||||
### File compression and archiving:
|
||||
```
|
||||
tar [options] archive_name files
|
||||
gzip file_name
|
||||
gunzip file_name.gz
|
||||
```
|
||||
|
||||
### Symbolic links:
|
||||
```
|
||||
ln -s target_file link_name
|
||||
```
|
||||
|
||||
## 6. Text Editors:
|
||||
|
||||
- nano: Simple and user-friendly
|
||||
- vim: Advanced and powerful
|
||||
- emacs: Extensible and feature-rich
|
||||
|
||||
## 7. File System Management:
|
||||
|
||||
### Mounting file systems:
|
||||
```
|
||||
mount [options] device directory
|
||||
```
|
||||
|
||||
### Unmounting file systems:
|
||||
```
|
||||
umount [options] directory
|
||||
```
|
||||
|
||||
### Checking disk space:
|
||||
```
|
||||
df [options]
|
||||
```
|
||||
- df -h: Human-readable output
|
||||
|
||||
## 8. File System Maintenance:
|
||||
|
||||
### Checking and repairing file systems:
|
||||
```
|
||||
fsck [options] device
|
||||
```
|
||||
|
||||
### Creating file systems:
|
||||
```
|
||||
mkfs [options] device
|
||||
```
|
||||
|
||||
## 9. Access Control Lists (ACLs):
|
||||
|
||||
### For more fine-grained permission control:
|
||||
```
|
||||
getfacl file
|
||||
setfacl -m u:user:rwx file
|
||||
```
|
||||
|
||||
## 10. Inode Information:
|
||||
|
||||
### View detailed file information:
|
||||
```
|
||||
stat file_name
|
||||
```
|
||||
|
||||
- [(1) How to Perform File and Directory Management (Part 3) - Tecmint.](https://www.tecmint.com/file-and-directory-management-in-linux/.)
|
||||
- [(2) How to Manage Files from the Linux Terminal: 11 Commands ... - How-To Geek.](https://www.howtogeek.com/107808/how-to-manage-files-from-the-linux-terminal-11-commands-you-need-to-know/.)
|
||||
- [(3) Linux File Management Series for Beginners - Linux Shell Tips.](https://www.ubuntumint.com/linux-file-management/.)
|
||||
- [(4) Linux Commands Cheat Sheet {with Free Downloadable PDF} - phoenixNAP.](https://phoenixnap.com/kb/linux-commands-cheat-sheet.)
|
||||
11
02 - Basic System Operations/Filesystem Navigation.md
Normal file
11
02 - Basic System Operations/Filesystem Navigation.md
Normal file
@ -0,0 +1,11 @@
|
||||
#
|
||||
|
||||
1. **Print Working Directory (pwd):** Use `pwd` to display your current location in the filesystem. It shows the absolute path from the root directory (e.g., `/home/user`). Absolute paths are crucial for scripts.
|
||||
|
||||
2. **Change Directory (cd):**
|
||||
- To move up one level (e.g., from `/home/user/docs` to `/home/user`), use `cd ..`.
|
||||
- To go directly to a specific directory (e.g., `/home/user/music`), provide the absolute path: `cd /home/user/music`.
|
||||
- To return home from any location, use `cd ~`.
|
||||
|
||||
|
||||
- [10 Linux commands for navigating the file system - FOSS Linux.](https://www.fosslinux.com/136854/10-linux-commands-for-navigating-the-file-system.htm.)
|
||||
72
02 - Basic System Operations/System Shutdown and Restart.md
Normal file
72
02 - Basic System Operations/System Shutdown and Restart.md
Normal file
@ -0,0 +1,72 @@
|
||||
# Linux Shutdown and reboot/restart procedure
|
||||
|
||||
## 1. Command Line Methods:
|
||||
|
||||
### a) Shutdown:
|
||||
- To shut down immediately: `sudo shutdown -h now`
|
||||
- To shut down after a delay: `sudo shutdown -h +m` (replace m with minutes)
|
||||
- To shut down at a specific time: `sudo shutdown -h HH:MM` (24-hour format)
|
||||
|
||||
### b) Restart:
|
||||
- To restart immediately: `sudo shutdown -r now` or `sudo reboot`
|
||||
- To restart after a delay: `sudo shutdown -r +m` (replace m with minutes)
|
||||
- To restart at a specific time: `sudo shutdown -r HH:MM` (24-hour format)
|
||||
|
||||
### c) Cancel a scheduled shutdown or restart:
|
||||
- `sudo shutdown -c`
|
||||
|
||||
## 2. Using systemctl (for systemd-based distributions):
|
||||
|
||||
- Shutdown: `sudo systemctl poweroff`
|
||||
- Restart: `sudo systemctl reboot`
|
||||
|
||||
## 3. Legacy commands (still work on most systems):
|
||||
|
||||
- Shutdown: `sudo halt` or `sudo poweroff`
|
||||
- Restart: `sudo reboot`
|
||||
|
||||
## 4. GUI Methods:
|
||||
|
||||
Most desktop environments (GNOME, KDE, Xfce, etc.) have a menu option for shutting down or restarting. Usually found in the main menu or by clicking on the user name/icon.
|
||||
|
||||
## 5. Emergency Immediate Shutdown:
|
||||
|
||||
In case of an unresponsive system, you can use the magic SysRq key combinations:
|
||||
- Hold Alt + SysRq (usually Print Screen), then press these keys in sequence: R E I S U B
|
||||
- This safely syncs data, unmounts filesystems, and reboots the system
|
||||
|
||||
## 6. Sending Signals:
|
||||
|
||||
You can use the `kill` command to send signals to the init process:
|
||||
- Shutdown: `sudo kill -s SIGINT 1`
|
||||
- Restart: `sudo kill -s SIGTERM 1`
|
||||
|
||||
## 7. Additional Options and Considerations:
|
||||
|
||||
a) Force shutdown (use cautiously): `sudo shutdown -h -f now`
|
||||
b) Schedule a shutdown message: `sudo shutdown -h +m "System will shutdown in m minutes"`
|
||||
c) Shut down without sudo (if configured): `shutdown -h now`
|
||||
|
||||
## 8. Shutting down remote systems:
|
||||
|
||||
- SSH into the system and use any of the above commands
|
||||
- Use `ssh user@host "sudo shutdown -h now"` from another machine
|
||||
|
||||
## 9. Checking shutdown/restart history:
|
||||
|
||||
- View last shutdown: `last -x shutdown`
|
||||
- View last reboot: `last reboot`
|
||||
- Check system logs: `journalctl --since "1 hour ago" | grep -i "shut down\|reboot"`
|
||||
|
||||
## 10. Best Practices:
|
||||
|
||||
- Always ensure all important data is saved before shutting down or restarting
|
||||
- Close all running applications to prevent data loss
|
||||
- For servers, notify users before scheduling a shutdown or restart
|
||||
- Use delayed shutdowns to give time for important processes to complete
|
||||
- Regularly check system logs for any shutdown/restart issues
|
||||
|
||||
- [(1) How to Reboot or Shut Down Linux Using the Command Line.)](https://www.howtogeek.com/411925/how-to-reboot-or-shut-down-linux-using-the-command-line/.)
|
||||
- [(2) How to reboot, shutdown, log off PC from Terminal by command line in](https://www.fosslinux.com/1115/how-to-reboot-shutdown-log-off-pc-from-terminal-by-command-line-in-ubuntu-and-linux-mint.htm.)
|
||||
- [(3) How do I shut down or reboot from a terminal? - Ask Ubuntu.](https://askubuntu.com/questions/187071/how-do-i-shut-down-or-reboot-from-a-terminal.)
|
||||
- [(4) 5 Linux Commands to Shutdown and Reboot the System.](https://www.binarytides.com/linux-command-shutdown-reboot-restart-system/.)
|
||||
27
02 - Basic System Operations/Terminal text editor.md
Normal file
27
02 - Basic System Operations/Terminal text editor.md
Normal file
@ -0,0 +1,27 @@
|
||||
#
|
||||
|
||||
1. **Opening and Creating Files**:
|
||||
- To open an existing file or create a new one, type:
|
||||
```
|
||||
nano filename
|
||||
```
|
||||
- Replace `filename` with the actual name of the file you want to edit. Nano will open the file in a new editor window.
|
||||
|
||||
2. **Basic Editing**:
|
||||
- Nano is modeless, meaning you can start typing and editing immediately.
|
||||
- To move the cursor to a specific line and character number, use `Ctrl+_`. Enter the line and column numbers when prompted.
|
||||
- To save your changes and exit, press `Ctrl+x`.
|
||||
|
||||
3. **Searching and Replacing**:
|
||||
- To search for text, press `Ctrl+w`, type your search term, and press `Enter`.
|
||||
- To move to the next match, press `Alt+w`.
|
||||
- For search and replace, press `Ctrl+\`. Enter the search term and the replacement text.
|
||||
|
||||
|
||||
|
||||
- [(1) Editing Files With Nano in Linux [With Cheat Sheet] - It's FOSS.](https://itsfoss.com/nano-editor-guide/.)
|
||||
- [(2) The Beginner's Guide to Nano, the Linux Command-Line Text Editor.](https://www.howtogeek.com/42980/the-beginners-guide-to-nano-the-linux-command-line-text-editor/.)
|
||||
- [(3) nano Command Guide | Linux Text Editor Explained.](https://ioflood.com/blog/nano-linux-command/.)
|
||||
- [(4) Getting Started With Nano Editor - Linux Handbook.](https://linuxhandbook.com/nano/.)
|
||||
- [(5) First steps with the Nano text editor - PragmaticLinux.](https://www.pragmaticlinux.com/2020/05/first-steps-with-the-nano-text-editor/.)
|
||||
- [(6) How to Use Nano Text Editor: From Installation to Editing - Hostinger.](https://www.hostinger.com/tutorials/how-to-install-and-use-nano-text-editor.)
|
||||
97
02 - Basic System Operations/Text Editors (Nano).md
Normal file
97
02 - Basic System Operations/Text Editors (Nano).md
Normal file
@ -0,0 +1,97 @@
|
||||
# Basic Text Editing (Nano)
|
||||
|
||||
Nano is a simple, user-friendly text editor for Unix-like operating systems. It's designed to be easy to use, especially for beginners, while still offering powerful features for more advanced users.
|
||||
|
||||
## 1. Installation:
|
||||
- On most Linux distributions, Nano is pre-installed.
|
||||
- If not, you can install it using your package manager:
|
||||
- For Ubuntu/Debian: `sudo apt-get install nano`
|
||||
- For Fedora: `sudo dnf install nano`
|
||||
- For macOS (using Homebrew): `brew install nano`
|
||||
|
||||
## 2. Basic Usage:
|
||||
- To open Nano: Type `nano` in the terminal.
|
||||
- To open a specific file: `nano filename`
|
||||
- To create a new file: `nano newfilename`
|
||||
|
||||
## 3. Interface:
|
||||
- The top line shows the version and file name.
|
||||
- The main area is for text editing.
|
||||
- The bottom two lines show available commands.
|
||||
|
||||
## 4. Navigation:
|
||||
- Use arrow keys to move the cursor.
|
||||
- Page Up/Down: Move one screen at a time.
|
||||
- Home/End: Move to start/end of a line.
|
||||
- Alt+/ or Ctrl+_: Move to a specific line number.
|
||||
|
||||
## 5. Editing:
|
||||
- Type to insert text at the cursor position.
|
||||
- Backspace: Delete character before cursor.
|
||||
- Delete: Remove character at cursor.
|
||||
- Ctrl+K: Cut the current line.
|
||||
- Ctrl+U: Paste the cut text.
|
||||
- Alt+6: Copy the current line.
|
||||
- Ctrl+^: Mark text (use arrow keys to select).
|
||||
|
||||
## 6. File Operations:
|
||||
- Ctrl+O: Save the file.
|
||||
- Ctrl+X: Exit Nano (prompts to save if changes made).
|
||||
- Ctrl+R: Insert another file into the current one.
|
||||
|
||||
## 7. Search and Replace:
|
||||
- Ctrl+W: Search for text.
|
||||
- Alt+W: Repeat last search.
|
||||
- Ctrl+\: Search and replace.
|
||||
|
||||
## 8. Advanced Features:
|
||||
- Syntax Highlighting:
|
||||
- Enabled by default for many file types.
|
||||
- Customize in `/etc/nanorc` or `~/.nanorc`.
|
||||
- Auto-indentation:
|
||||
- Enable with `-i` option or `set autoindent` in config.
|
||||
- Line Numbers:
|
||||
- Show with `-l` option or `set linenumbers` in config.
|
||||
- Soft Wrapping:
|
||||
- Enable with `-$` option or `set softwrap` in config.
|
||||
|
||||
## 9. Configuration:
|
||||
- Global config: `/etc/nanorc`
|
||||
- User config: `~/.nanorc`
|
||||
- Common settings:
|
||||
```
|
||||
set autoindent
|
||||
set linenumbers
|
||||
set mouse
|
||||
set tabsize 4
|
||||
```
|
||||
|
||||
## 10. Helpful Commands:
|
||||
- Ctrl+G: Display help text.
|
||||
- Alt+X: Enable/disable mouse support.
|
||||
- Alt+N: Enable/disable line numbers.
|
||||
- Ctrl+J: Justify the current paragraph.
|
||||
|
||||
## 11. Multiple Buffers:
|
||||
- Ctrl+R: Open a file in a new buffer.
|
||||
- Alt+< and Alt+>: Switch between buffers.
|
||||
|
||||
## 12. Macros:
|
||||
- Ctrl+]: Start/stop macro recording.
|
||||
- Ctrl+A: Play back the macro.
|
||||
|
||||
## 13. Spell Checking:
|
||||
- Enable with `-s` option or `set speller "aspell -x -c"` in config.
|
||||
- Alt+S: Activate spell checker (if enabled).
|
||||
|
||||
## 14. Customizing Shortcuts:
|
||||
- In `.nanorc`, you can bind keys to functions:
|
||||
```
|
||||
bind ^Z undo main
|
||||
bind ^Y redo main
|
||||
```
|
||||
|
||||
## 15. Colored Text:
|
||||
- Use `set titlecolor`, `set statuscolor`, etc. in `.nanorc` to customize colors.
|
||||
|
||||
Nano is an excellent choice for quick edits and for users who prefer a straightforward, non-modal text editor. While it may not have all the features of more complex editors like Vim or Emacs, its simplicity and ease of use make it a popular choice for many users.
|
||||
@ -0,0 +1,89 @@
|
||||
# Using the Linux Terminal (BASH Shell)
|
||||
|
||||
## 1. Basic Navigation:
|
||||
- pwd: Print working directory
|
||||
- ls: List files and directories
|
||||
- cd: Change directory
|
||||
- mkdir: Create a new directory
|
||||
- rmdir: Remove an empty directory
|
||||
- touch: Create an empty file
|
||||
|
||||
## 2. File Operations:
|
||||
- cp: Copy files or directories
|
||||
- mv: Move or rename files/directories
|
||||
- rm: Remove files or directories
|
||||
- cat: Display file contents
|
||||
- less: View file contents page by page
|
||||
- head/tail: View beginning/end of a file
|
||||
|
||||
## 3. Text Editing:
|
||||
- nano: Simple text editor
|
||||
- vim: Advanced text editor
|
||||
- emacs: Another advanced text editor
|
||||
|
||||
## 4. File Permissions:
|
||||
- chmod: Change file permissions
|
||||
- chown: Change file owner
|
||||
- chgrp: Change group ownership
|
||||
|
||||
## 5. Process Management:
|
||||
- ps: List running processes
|
||||
- top: Dynamic view of system processes
|
||||
- kill: Terminate a process
|
||||
- fg/bg: Bring process to foreground/background
|
||||
|
||||
## 6. System Information:
|
||||
- uname: Display system information
|
||||
- df: Show disk usage
|
||||
- du: Display directory space usage
|
||||
- free: Show memory usage
|
||||
|
||||
## 7. Network Commands:
|
||||
- ifconfig: Configure network interfaces
|
||||
- ping: Test network connectivity
|
||||
- ssh: Secure shell for remote access
|
||||
- scp: Securely copy files between hosts
|
||||
|
||||
## 8. Package Management:
|
||||
- apt-get (Debian/Ubuntu): Install, update, remove packages
|
||||
- yum (CentOS/Fedora): Similar to apt-get
|
||||
- dnf (Fedora): Next-generation package manager
|
||||
|
||||
## 9. File Compression:
|
||||
- tar: Archive files
|
||||
- gzip/gunzip: Compress/decompress files
|
||||
- zip/unzip: Create/extract zip archives
|
||||
|
||||
## 10. Text Processing:
|
||||
- grep: Search for patterns in files
|
||||
- sed: Stream editor for text manipulation
|
||||
- awk: Pattern scanning and text processing
|
||||
|
||||
## 11. Redirection and Pipes:
|
||||
- >: Redirect output to a file
|
||||
- >>: Append output to a file
|
||||
- <: Read input from a file
|
||||
- |: Pipe output of one command to another
|
||||
|
||||
## 12. User Management:
|
||||
- useradd: Add a new user
|
||||
- userdel: Delete a user
|
||||
- passwd: Change user password
|
||||
|
||||
## 13. Advanced Commands:
|
||||
- find: Search for files in a directory hierarchy
|
||||
- xargs: Build and execute command lines from standard input
|
||||
- sort: Sort lines of text
|
||||
- uniq: Report or omit repeated lines
|
||||
|
||||
## 14. Shell Scripting:
|
||||
- Variables: var_name=value
|
||||
- Conditionals: if, elif, else
|
||||
- Loops: for, while
|
||||
- Functions: function_name() { commands; }
|
||||
|
||||
## 15. Job Control:
|
||||
- jobs: List active jobs
|
||||
- &: Run a command in the background
|
||||
- Ctrl+Z: Suspend a running process
|
||||
- Ctrl+C: Terminate a running process
|
||||
30
02 - Basic System Operations/Using Terminal and Shell.md
Normal file
30
02 - Basic System Operations/Using Terminal and Shell.md
Normal file
@ -0,0 +1,30 @@
|
||||
#
|
||||
|
||||
1. **Opening the Terminal**:
|
||||
- You can open the terminal in various ways:
|
||||
- **Shortcut**: Press `Ctrl + Alt + T`.
|
||||
- **Specific Directory**: Open the terminal in a specific directory.
|
||||
- **Application Menu**: Search for "Terminal" in your applications.
|
||||
- **Command**: Use the `gnome-terminal` command.
|
||||
|
||||
2. **Basic Commands**:
|
||||
- Once you're in the terminal, try these commands:
|
||||
- `pwd`: Print the current working directory.
|
||||
- `ls`: List files and directories.
|
||||
- `cd`: Change directory.
|
||||
- `mkdir`: Create a new directory.
|
||||
- `cp`: Copy files or directories.
|
||||
- `mv`: Move files or rename them.
|
||||
- `rm`: Remove files or directories.
|
||||
- `clear`: Clear the terminal screen.
|
||||
|
||||
3. **Superuser Powers**:
|
||||
- Some tasks require administrator privileges. Use `sudo` before a command to execute it as the superuser.
|
||||
- Be cautious with superuser access—it's powerful!
|
||||
|
||||
- [(1) Beginner's Guide To The Linux Terminal.](https://www.youtube.com/watch?v=s3ii48qYBxA.)
|
||||
- [(2) Linux Terminal Introduction.](https://www.youtube.com/watch?v=SkB-eRCzWIU.)
|
||||
- [(3) Linux Terminal Basics | Navigate the File System on Ubuntu.](https://www.youtube.com/watch?v=jgcXclSXnVo.)
|
||||
- [(4) The Linux command line for beginners | Ubuntu.](https://ubuntu.com/tutorials/command-line-for-beginners.)
|
||||
- [(5) What is Terminal in Linux? [The Ultimate Guide] - LinuxSimply.](https://linuxsimply.com/what-is-terminal-in-linux/.)
|
||||
|
||||
134
03 - Package and Process Management/Basic Shell (Bash).md
Normal file
134
03 - Package and Process Management/Basic Shell (Bash).md
Normal file
@ -0,0 +1,134 @@
|
||||
# Basic Shell (Bash)
|
||||
|
||||
### 1. Introduction to Bash and the command line
|
||||
|
||||
Bash (Bourne Again SHell) is a command-line interface and scripting language used in Unix-like operating systems, including Linux. It's an improved version of the original Bourne Shell (sh).
|
||||
|
||||
Key points about Bash:
|
||||
- It's the default shell in most Linux distributions.
|
||||
- It allows users to interact with the operating system through text commands.
|
||||
- It's both an interactive shell and a scripting language.
|
||||
|
||||
To start using Bash:
|
||||
1. Open a terminal window in your Linux distribution.
|
||||
2. You'll see a prompt, typically ending with a $ symbol for regular users or # for root users.
|
||||
|
||||
Basic syntax:
|
||||
```
|
||||
command [options] [arguments]
|
||||
```
|
||||
|
||||
For example:
|
||||
```bash
|
||||
ls -l /home/user
|
||||
```
|
||||
Here, 'ls' is the command, '-l' is an option, and '/home/user' is an argument.
|
||||
|
||||
Some essential commands to get started:
|
||||
- `echo`: Prints text to the screen
|
||||
Example: `echo "Hello, World!"`
|
||||
|
||||
- `date`: Displays the current date and time
|
||||
Example: `date`
|
||||
|
||||
- `cal`: Shows a calendar
|
||||
Example: `cal` or `cal 2024` for a specific year
|
||||
|
||||
- `man`: Displays the manual page for a command
|
||||
Example: `man ls` (Use 'q' to exit)
|
||||
|
||||
### 2. Basic navigation and file management
|
||||
|
||||
Linux file system hierarchy:
|
||||
The file system in Linux is organized in a tree-like structure, starting from the root directory (/).
|
||||
|
||||
Key directories:
|
||||
- /: Root directory
|
||||
- /home: User home directories
|
||||
- /etc: System configuration files
|
||||
- /var: Variable data (logs, temporary files)
|
||||
- /bin: Essential command binaries
|
||||
- /usr: User programs and data
|
||||
|
||||
Navigation commands:
|
||||
- `pwd`: Print Working Directory
|
||||
Example: ```bash
|
||||
pwd
|
||||
```
|
||||
|
||||
- `cd`: Change Directory
|
||||
Examples:
|
||||
```bash
|
||||
cd /home/user
|
||||
```
|
||||
cd .. # Move up one directory
|
||||
cd ~ # Move to home directory
|
||||
cd - # Move to previous directory
|
||||
```
|
||||
|
||||
- `ls`: List directory contents
|
||||
Examples:
|
||||
```bash
|
||||
ls
|
||||
ls -l # Long format
|
||||
ls -a # Show hidden files
|
||||
ls -lh # Human-readable file sizes
|
||||
```
|
||||
|
||||
File and directory management:
|
||||
- `mkdir`: Create a new directory
|
||||
Example: `mkdir new_folder`
|
||||
|
||||
- `touch`: Create an empty file or update timestamp
|
||||
Example: `touch newfile.txt`
|
||||
|
||||
- `cp`: Copy files or directories
|
||||
Examples:
|
||||
```bash
|
||||
cp file.txt /path/to/destination/
|
||||
cp -r folder/ /path/to/destination/ # Recursive copy for directories
|
||||
```
|
||||
|
||||
- `mv`: Move or rename files/directories
|
||||
Examples:
|
||||
```bash
|
||||
mv file.txt newname.txt # Rename
|
||||
mv file.txt /new/location/ # Move
|
||||
```
|
||||
|
||||
- `rm`: Remove files or directories
|
||||
Examples:
|
||||
```bash
|
||||
rm file.txt
|
||||
rm -r folder/ # Remove directory and contents
|
||||
rm -i file.txt # Interactive mode (asks before deleting)
|
||||
```
|
||||
|
||||
- `cat`: Concatenate and display file contents
|
||||
Example: `cat file.txt`
|
||||
|
||||
- `less`: View file contents page by page
|
||||
Example: `less longfile.txt` (Use 'q' to exit)
|
||||
|
||||
- `head` and `tail`: View the beginning or end of a file
|
||||
Examples:
|
||||
```bash
|
||||
head -n 5 file.txt # First 5 lines
|
||||
tail -n 10 file.txt # Last 10 lines
|
||||
```
|
||||
|
||||
File permissions:
|
||||
Linux uses a permission system for files and directories. You can view permissions with `ls -l`:
|
||||
```
|
||||
-rw-r--r-- 1 user group 1234 Jan 1 12:00 file.txt
|
||||
```
|
||||
|
||||
The first 10 characters represent:
|
||||
- File type (- for regular file, d for directory)
|
||||
- Read (r), Write (w), and Execute (x) permissions for Owner, Group, and Others
|
||||
|
||||
To change permissions, use the `chmod` command:
|
||||
```bash
|
||||
chmod u+x script.sh # Add execute permission for the owner
|
||||
chmod 644 file.txt # Set specific permissions (rw-r--r--)
|
||||
```
|
||||
54
03 - Package and Process Management/Basics of Kernel.md
Normal file
54
03 - Package and Process Management/Basics of Kernel.md
Normal file
@ -0,0 +1,54 @@
|
||||
# Understanding the Linux Kernel:
|
||||
|
||||
### 1. Definition:
|
||||
The Linux kernel is the core component of Linux operating systems. It's a piece of software that provides a bridge between applications and the actual data processing done at the hardware level. The kernel is responsible for managing the system's resources and the communication between hardware and software components.
|
||||
|
||||
### 2. Key Functions:
|
||||
- Process Management: Schedules and manages processes (running programs).
|
||||
- Memory Management: Controls system memory allocation and usage.
|
||||
- Device Drivers: Manages hardware devices and their drivers.
|
||||
- System Calls and Security: Provides an interface for user-space applications to request kernel services.
|
||||
- Networking: Manages network connections and protocols.
|
||||
- File Systems: Handles file storage and retrieval.
|
||||
|
||||
### 3. Kernel Architecture:
|
||||
The Linux kernel follows a monolithic architecture, which means it runs in a single memory space for better performance. However, it's modular, allowing components to be loaded and unloaded at runtime.
|
||||
|
||||
### 4. Kernel Space vs User Space:
|
||||
- Kernel Space: Where the kernel code executes with unrestricted access to the hardware.
|
||||
- User Space: Where user applications run with limited privileges.
|
||||
|
||||
### 5. Kernel Versions:
|
||||
Linux kernel versions are denoted as x.y.z, where:
|
||||
- x: Major version (rarely changes)
|
||||
- y: Minor version (even numbers are stable, odd are development)
|
||||
- z: Patch level
|
||||
|
||||
### 6. Kernel Source Tree:
|
||||
The kernel source code is organized into directories:
|
||||
- /arch: Architecture-specific code
|
||||
- /drivers: Device drivers
|
||||
- /fs: File system code
|
||||
- /kernel: Core kernel functions
|
||||
- /mm: Memory management code
|
||||
- /net: Networking code
|
||||
|
||||
### 7. Kernel Modules:
|
||||
These are pieces of code that can be loaded and unloaded into the kernel upon demand. They extend the functionality of the kernel without needing to reboot the system.
|
||||
|
||||
### 8. Kernel Configuration:
|
||||
This involves selecting which features and drivers to include in the kernel. It allows customization for specific hardware and use cases.
|
||||
|
||||
### 9. Kernel Compilation:
|
||||
The process of building the kernel from source code after configuration. Kernel source code traditionally stored at `/usr/src/linux` .
|
||||
|
||||
### 10. Boot Process:
|
||||
- Bootloader loads the kernel into memory
|
||||
- Kernel initializes hardware and memory
|
||||
- Kernel mounts the root file system
|
||||
- Kernel starts the init process (first user-space process)
|
||||
|
||||
### 11. Kernel Development Model:
|
||||
The Linux kernel follows an open-source development model. Linus Torvalds oversees the project, with numerous contributors worldwide.
|
||||
|
||||
Understanding these aspects of the Linux kernel provides a solid foundation for kernel configuration. It helps in making informed decisions about which components to include or exclude based on your system's requirements.
|
||||
@ -0,0 +1,205 @@
|
||||
# Package Management with Yum (RHEL Based)
|
||||
|
||||
###1. Introduction to Yum
|
||||
|
||||
Yum (Yellowdog Updater Modified) is the primary package management tool for Red Hat Enterprise Linux (RHEL) and its derivatives like CentOS and Fedora. It allows you to install, update, and remove software packages while automatically handling dependencies.
|
||||
|
||||
### 2. Basic Yum Commands
|
||||
|
||||
- Searching for packages:
|
||||
```
|
||||
yum search keyword
|
||||
```
|
||||
|
||||
- Getting information about a package:
|
||||
```
|
||||
yum info package_name
|
||||
```
|
||||
|
||||
- Installing a package:
|
||||
```
|
||||
sudo yum install package_name
|
||||
```
|
||||
|
||||
- Removing a package:
|
||||
```
|
||||
sudo yum remove package_name
|
||||
```
|
||||
|
||||
- Updating all packages:
|
||||
```
|
||||
sudo yum update
|
||||
```
|
||||
|
||||
- Updating a specific package:
|
||||
```
|
||||
sudo yum update package_name
|
||||
```
|
||||
|
||||
### 3. Working with Repositories
|
||||
|
||||
Yum uses repositories to fetch package information and the packages themselves.
|
||||
|
||||
- Listing enabled repositories:
|
||||
```
|
||||
yum repolist
|
||||
```
|
||||
|
||||
- Listing all repositories (including disabled):
|
||||
```
|
||||
yum repolist all
|
||||
```
|
||||
|
||||
- Adding a new repository:
|
||||
Create a .repo file in /etc/yum.repos.d/ with the following structure:
|
||||
|
||||
```
|
||||
[repository_id]
|
||||
name=Repository Name
|
||||
baseurl=http://repository.url
|
||||
enabled=1
|
||||
gpgcheck=1
|
||||
gpgkey=http://repository.url/RPM-GPG-KEY
|
||||
```
|
||||
|
||||
- Enabling/disabling a repository:
|
||||
```
|
||||
sudo yum-config-manager --enable repository_id
|
||||
sudo yum-config-manager --disable repository_id
|
||||
```
|
||||
|
||||
### 4. Managing Package Groups
|
||||
|
||||
Yum can install predefined groups of packages.
|
||||
|
||||
- Listing available groups:
|
||||
```
|
||||
yum group list
|
||||
```
|
||||
|
||||
- Getting info about a group:
|
||||
```
|
||||
yum group info "group_name"
|
||||
```
|
||||
|
||||
- Installing a group:
|
||||
```
|
||||
sudo yum group install "group_name"
|
||||
```
|
||||
|
||||
- Removing a group:
|
||||
```
|
||||
sudo yum group remove "group_name"
|
||||
```
|
||||
|
||||
### 5. Yum Cache Management
|
||||
|
||||
Yum maintains a cache to speed up operations.
|
||||
|
||||
- Cleaning all cached packages and metadata:
|
||||
```
|
||||
sudo yum clean all
|
||||
```
|
||||
|
||||
- Cleaning only cached packages:
|
||||
```
|
||||
sudo yum clean packages
|
||||
```
|
||||
|
||||
- Cleaning only cached metadata:
|
||||
```
|
||||
sudo yum clean metadata
|
||||
```
|
||||
|
||||
### 6. Advanced Yum Features
|
||||
|
||||
- Downloading a package without installing:
|
||||
```
|
||||
yumdownloader package_name
|
||||
```
|
||||
|
||||
- Installing a local RPM package with Yum (to resolve dependencies):
|
||||
```
|
||||
sudo yum localinstall package_name.rpm
|
||||
```
|
||||
|
||||
- Checking for available updates:
|
||||
```
|
||||
yum check-update
|
||||
```
|
||||
|
||||
- Listing installed packages:
|
||||
```
|
||||
yum list installed
|
||||
```
|
||||
|
||||
- Listing available packages:
|
||||
```
|
||||
yum list available
|
||||
```
|
||||
|
||||
### 7. Yum History
|
||||
|
||||
Yum keeps a history of transactions, allowing you to undo or redo actions.
|
||||
|
||||
- Viewing Yum history:
|
||||
```
|
||||
yum history list
|
||||
```
|
||||
|
||||
- Undoing a transaction:
|
||||
```
|
||||
sudo yum history undo transaction_id
|
||||
```
|
||||
|
||||
- Redoing a transaction:
|
||||
```
|
||||
sudo yum history redo transaction_id
|
||||
```
|
||||
|
||||
### 8. Yum Configuration
|
||||
|
||||
The main Yum configuration file is `/etc/yum.conf` Here are some important settings:
|
||||
|
||||
- cachedir: Directory where Yum stores its cache files
|
||||
- keepcache: Whether to keep the cache after successful operations
|
||||
- debuglevel: Level of debugging output
|
||||
- gpgcheck: Whether to perform GPG signature checking on packages
|
||||
- plugins: Whether to enable Yum plugins
|
||||
|
||||
### 9. Yum Plugins
|
||||
|
||||
Yum's functionality can be extended with plugins. Some useful plugins include:
|
||||
|
||||
- yum-plugin-fastestmirror: Finds the fastest mirror for downloads
|
||||
- yum-plugin-security: Allows security-related operations
|
||||
- yum-plugin-versionlock: Locks specified packages to a particular version
|
||||
|
||||
To install a plugin:
|
||||
```
|
||||
sudo yum install plugin_name
|
||||
```
|
||||
|
||||
### 10. Troubleshooting
|
||||
|
||||
If you encounter issues with Yum, try these steps:
|
||||
|
||||
- Clear the Yum cache:
|
||||
```
|
||||
sudo yum clean all
|
||||
```
|
||||
|
||||
- Rebuild the Yum cache:
|
||||
```
|
||||
sudo yum makecache
|
||||
```
|
||||
|
||||
- Check for conflicting transactions:
|
||||
```
|
||||
sudo yum-complete-transaction --cleanup-only
|
||||
```
|
||||
|
||||
- Verify the package database:
|
||||
```
|
||||
sudo yum check
|
||||
```
|
||||
@ -0,0 +1,129 @@
|
||||
# Package Management with apt-get (Debian-Based Systems)
|
||||
|
||||
### 1. Introduction to apt-get
|
||||
|
||||
apt-get is a command-line tool for handling packages in Debian-based Linux distributions. It's part of the APT (Advanced Package Tool) system, which manages software installation, upgrade, and removal.
|
||||
|
||||
### 2. Updating Package Lists
|
||||
|
||||
Before installing or upgrading packages, it's important to update your local package lists:
|
||||
|
||||
```bash
|
||||
sudo apt-get update
|
||||
```
|
||||
|
||||
This command synchronizes your package lists with the repositories.
|
||||
|
||||
### 3. Upgrading Installed Packages
|
||||
|
||||
To upgrade all installed packages to their latest versions:
|
||||
|
||||
```bash
|
||||
sudo apt-get upgrade
|
||||
```
|
||||
|
||||
For a more aggressive upgrade that might remove obsolete packages:
|
||||
|
||||
```bash
|
||||
sudo apt-get dist-upgrade
|
||||
```
|
||||
|
||||
### 4. Installing Packages
|
||||
|
||||
To install a new package:
|
||||
|
||||
```bash
|
||||
sudo apt-get install package_name
|
||||
```
|
||||
|
||||
You can install multiple packages at once:
|
||||
|
||||
```bash
|
||||
sudo apt-get install package1 package2 package3
|
||||
```
|
||||
|
||||
### 5. Removing Packages
|
||||
|
||||
To remove a package:
|
||||
|
||||
```bash
|
||||
sudo apt-get remove package_name
|
||||
```
|
||||
|
||||
To remove the package along with its configuration files:
|
||||
|
||||
```bash
|
||||
sudo apt-get purge package_name
|
||||
```
|
||||
|
||||
### 6. Searching for Packages
|
||||
|
||||
To search for a package:
|
||||
|
||||
```bash
|
||||
apt-cache search keyword
|
||||
```
|
||||
|
||||
### 7. Displaying Package Information
|
||||
|
||||
To show detailed information about a package:
|
||||
|
||||
```bash
|
||||
apt-cache show package_name
|
||||
```
|
||||
|
||||
### 8. Cleaning Up
|
||||
|
||||
To remove unnecessary packages:
|
||||
|
||||
```bash
|
||||
sudo apt-get autoremove
|
||||
```
|
||||
|
||||
To clear out the local repository of retrieved package files:
|
||||
|
||||
```bash
|
||||
sudo apt-get clean
|
||||
```
|
||||
|
||||
### 9. Handling Dependencies
|
||||
|
||||
apt-get automatically handles dependencies. When you install a package, it will also install any required dependencies.
|
||||
|
||||
### 10. Working with Package Sources
|
||||
|
||||
Package sources are defined in `/etc/apt/sources.list` and in files under `/etc/apt/sources.list.d/`. You may need to edit these to add or remove repositories.
|
||||
|
||||
### 11. Holding Packages
|
||||
|
||||
To prevent a package from being automatically upgraded:
|
||||
|
||||
```bash
|
||||
sudo apt-mark hold package_name
|
||||
```
|
||||
|
||||
To remove the hold:
|
||||
|
||||
```bash
|
||||
sudo apt-mark unhold package_name
|
||||
```
|
||||
|
||||
### 12. Simulating Operations
|
||||
|
||||
You can simulate operations without actually performing them using the `-s` flag:
|
||||
|
||||
```bash
|
||||
sudo apt-get -s install package_name
|
||||
```
|
||||
|
||||
This is useful for seeing what would happen without making any changes.
|
||||
|
||||
### 13. Troubleshooting
|
||||
|
||||
If you encounter issues, you can try:
|
||||
|
||||
- Updating package lists: `sudo apt-get update`
|
||||
- Fixing broken dependencies: `sudo apt-get -f install`
|
||||
- Reconfiguring packages: `sudo dpkg-reconfigure package_name`
|
||||
|
||||
Remember to always be cautious when using sudo, as these commands can affect your system's stability if used incorrectly.
|
||||
@ -0,0 +1,193 @@
|
||||
# Process Monitoring and Management in Linux
|
||||
|
||||
### 1. Viewing Running Processes
|
||||
|
||||
Let's start with the basic commands to view running processes:
|
||||
|
||||
- ps - Process Status
|
||||
The 'ps' command provides a snapshot of current processes.
|
||||
|
||||
Basic usage:
|
||||
```
|
||||
ps
|
||||
```
|
||||
|
||||
Common options:
|
||||
- `ps aux`: Shows all processes for all users
|
||||
- `ps -ef`: Similar to aux, but in a different format
|
||||
- `ps lax`: Provides more detailed information
|
||||
|
||||
- top - Table of Processes
|
||||
'top' provides a real-time, dynamic view of running processes.
|
||||
|
||||
Basic usage:
|
||||
```
|
||||
top
|
||||
```
|
||||
|
||||
In top, you can use:
|
||||
- 'q' to quit
|
||||
- 'k' to kill a process (you'll be prompted for the PID)
|
||||
- 'r' to renice (change priority) of a process
|
||||
|
||||
- htop - Interactive Process Viewer
|
||||
'htop' is an improved version of 'top' with a more user-friendly interface.
|
||||
|
||||
Install it (if not already installed):
|
||||
```
|
||||
sudo apt install htop # For Debian/Ubuntu
|
||||
sudo yum install htop # For CentOS/RHEL
|
||||
```
|
||||
|
||||
Run it:
|
||||
```
|
||||
htop
|
||||
```
|
||||
|
||||
### 2. Process Management
|
||||
|
||||
- kill - Terminate a Process
|
||||
The 'kill' command sends a signal to a process, by default the TERM signal.
|
||||
|
||||
Basic usage:
|
||||
```
|
||||
kill PID
|
||||
```
|
||||
|
||||
Common signals:
|
||||
- SIGTERM (15): Graceful termination
|
||||
- SIGKILL (9): Forceful termination
|
||||
|
||||
Example:
|
||||
```
|
||||
kill -9 1234
|
||||
```
|
||||
|
||||
- killall - Kill Processes by Name
|
||||
'killall' allows you to kill all processes with a given name.
|
||||
|
||||
Example:
|
||||
```
|
||||
killall firefox
|
||||
```
|
||||
|
||||
- pkill - Kill Processes Based on Name and Other Attributes
|
||||
'pkill' is more flexible than killall, allowing you to kill processes based on various attributes.
|
||||
|
||||
Example:
|
||||
```
|
||||
pkill -u username firefox
|
||||
```
|
||||
|
||||
- nice and renice - Adjust Process Priority
|
||||
'nice' starts a process with a specified priority, while 'renice' changes the priority of a running process.
|
||||
|
||||
Nice values range from -20 (highest priority) to 19 (lowest priority).
|
||||
|
||||
Example:
|
||||
```
|
||||
nice -n 10 command # Start 'command' with lower priority
|
||||
renice -n 5 -p PID # Change priority of running process
|
||||
```
|
||||
|
||||
### 3. Background and Foreground Processes
|
||||
|
||||
- Start a process in the background:
|
||||
```
|
||||
command &
|
||||
```
|
||||
|
||||
- Move a running process to the background:
|
||||
Press Ctrl+Z
|
||||
|
||||
- Bring a background process to the foreground:
|
||||
```
|
||||
fg %job_number
|
||||
```
|
||||
|
||||
- List background jobs:
|
||||
```
|
||||
jobs
|
||||
```
|
||||
|
||||
### 4. Advanced Monitoring Tools
|
||||
|
||||
- iotop - I/O Monitoring
|
||||
'iotop' shows I/O usage by processes.
|
||||
|
||||
Install:
|
||||
```
|
||||
sudo apt install iotop # For Debian/Ubuntu
|
||||
sudo yum install iotop # For CentOS/RHEL
|
||||
```
|
||||
|
||||
Run:
|
||||
```
|
||||
sudo iotop
|
||||
```
|
||||
|
||||
- nethogs - Network Monitoring
|
||||
'nethogs' shows network usage by process.
|
||||
|
||||
Install:
|
||||
```
|
||||
sudo apt install nethogs # For Debian/Ubuntu
|
||||
sudo yum install nethogs # For CentOS/RHEL
|
||||
```
|
||||
|
||||
Run:
|
||||
```
|
||||
sudo nethogs
|
||||
```
|
||||
|
||||
- lsof - List Open Files
|
||||
'lsof' lists open files and the processes using them.
|
||||
|
||||
Example (list all network connections):
|
||||
```
|
||||
sudo lsof -i
|
||||
```
|
||||
|
||||
### 5. System Monitoring
|
||||
|
||||
- free - Display Amount of Free and Used Memory
|
||||
```
|
||||
free -h # -h for human-readable format
|
||||
```
|
||||
|
||||
- vmstat - Report Virtual Memory Statistics
|
||||
```
|
||||
vmstat 1 # Report every second
|
||||
```
|
||||
|
||||
- iostat - Report CPU Statistics and I/O Statistics
|
||||
```
|
||||
iostat 1 # Report every second
|
||||
```
|
||||
|
||||
### 6. Process Tracking and Analysis
|
||||
|
||||
- strace - Trace System Calls and Signals
|
||||
'strace' is useful for diagnosing problems with processes.
|
||||
|
||||
Example:
|
||||
```
|
||||
strace command
|
||||
```
|
||||
|
||||
- ltrace - Library Call Tracer
|
||||
'ltrace' is similar to strace but for library calls.
|
||||
|
||||
Example:
|
||||
```
|
||||
ltrace command
|
||||
```
|
||||
|
||||
### 7. Continuous Monitoring with watch
|
||||
|
||||
The 'watch' command allows you to run any command periodically, showing output in fullscreen.
|
||||
|
||||
Example (update process list every 2 seconds):
|
||||
```
|
||||
watch -n 2 'ps aux | sort -nrk 3,3 | head -n 5'
|
||||
```
|
||||
@ -0,0 +1,104 @@
|
||||
# Understanding and Using SystemD
|
||||
|
||||
### 1. Introduction to systemd
|
||||
|
||||
systemd is an init system and system manager that has become the standard for many Linux distributions. It was designed to overcome limitations in the traditional SysV init system, providing faster boot times, dependency-based service control, and a unified interface for managing system services.
|
||||
|
||||
### 2. Core Concepts
|
||||
|
||||
- Units: The basic building blocks of systemd. Units can represent services, devices, mount points, and more.
|
||||
- Dependencies: systemd manages relationships between units, ensuring they start in the correct order.
|
||||
- Targets: Groups of units that represent a specific system state (similar to runlevels in SysV init).
|
||||
- Sockets: Allow for service activation on demand.
|
||||
- Timers: Provide cron-like functionality for scheduling tasks.
|
||||
|
||||
### 3. Unit Files
|
||||
|
||||
Unit files are configuration files that define how systemd should manage a unit. They are typically located in /etc/systemd/system/ or /usr/lib/systemd/system/.
|
||||
|
||||
Structure of a basic service unit file:
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=My Custom Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/path/to/your/script.sh
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
### 4. Basic systemd Commands
|
||||
|
||||
- systemctl: The main command for interacting with systemd
|
||||
- journalctl: Used for viewing logs
|
||||
- systemd-analyze: Analyzes system boot-up performance
|
||||
|
||||
Common systemctl commands:
|
||||
```
|
||||
systemctl start service-name
|
||||
systemctl stop service-name
|
||||
systemctl restart service-name
|
||||
systemctl status service-name
|
||||
systemctl enable service-name
|
||||
systemctl disable service-name
|
||||
```
|
||||
|
||||
### 5. Managing Services
|
||||
|
||||
To create a new service:
|
||||
1. Create a unit file in /etc/systemd/system/ (e.g., myservice.service)
|
||||
2. Define the service using the structure shown earlier
|
||||
3. Reload the systemd manager: `systemctl daemon-reload`
|
||||
4. Start and enable the service: `systemctl start myservice && systemctl enable myservice`
|
||||
|
||||
### 6. System Boot and Target Units
|
||||
|
||||
systemd uses target units to manage the boot process. Key targets include:
|
||||
- poweroff.target
|
||||
- rescue.target
|
||||
- multi-user.target
|
||||
- graphical.target
|
||||
|
||||
To change the default target:
|
||||
```
|
||||
systemctl set-default graphical.target
|
||||
```
|
||||
|
||||
### 7. Logging with journald
|
||||
|
||||
journald is systemd's logging system. Key features:
|
||||
- Collects messages from the kernel, services, and applications
|
||||
- Indexes logs for fast searching
|
||||
- Supports structured logging
|
||||
|
||||
Basic journalctl usage:
|
||||
```
|
||||
journalctl -u service-name # View logs for a specific service
|
||||
journalctl -f # Follow new log entries
|
||||
journalctl --since "1 hour ago" # View recent logs
|
||||
```
|
||||
|
||||
### 8. Advanced Features
|
||||
|
||||
- Socket Activation: Services start on-demand when a client connects to their socket.
|
||||
- Resource Control: Limit CPU, memory, and other resources for services.
|
||||
- Security Features: Restrict service permissions and access.
|
||||
|
||||
Example of resource control in a unit file:
|
||||
```ini
|
||||
[Service]
|
||||
ExecStart=/path/to/your/script.sh
|
||||
CPUQuota=20%
|
||||
MemoryLimit=100M
|
||||
```
|
||||
|
||||
### 9. Troubleshooting
|
||||
|
||||
- Check service status: `systemctl status service-name`
|
||||
- View recent logs: `journalctl -u service-name -n 50 --no-pager`
|
||||
- List failed units: `systemctl --failed`
|
||||
- Check boot time: `systemd-analyze`
|
||||
176
04 - Networking in Linux/Basic Network Configuration.md
Normal file
176
04 - Networking in Linux/Basic Network Configuration.md
Normal file
@ -0,0 +1,176 @@
|
||||
# Linux Basic Network Configuration
|
||||
|
||||
## 1. Network Interfaces
|
||||
|
||||
Linux uses network interfaces to communicate with networks. Common interfaces include:
|
||||
|
||||
- eth0, eth1, etc.: Ethernet interfaces
|
||||
- wlan0, wlan1, etc.: Wireless interfaces
|
||||
- lo: Loopback interface
|
||||
|
||||
To list network interfaces:
|
||||
|
||||
```
|
||||
ip link show
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```
|
||||
ifconfig -a
|
||||
```
|
||||
|
||||
## 2. IP Address Configuration
|
||||
|
||||
### Temporary IP configuration:
|
||||
|
||||
- To set an IP address temporarily:
|
||||
|
||||
```
|
||||
sudo ip addr add 192.168.1.100/24 dev eth0
|
||||
```
|
||||
|
||||
- To remove an IP address:
|
||||
|
||||
```
|
||||
sudo ip addr del 192.168.1.100/24 dev eth0
|
||||
```
|
||||
|
||||
### Permanent IP configuration:
|
||||
|
||||
Edit the network configuration file (location varies by distribution):
|
||||
|
||||
- Ubuntu/Debian: /etc/network/interfaces
|
||||
- CentOS/RHEL: /etc/sysconfig/network-scripts/ifcfg-eth0
|
||||
|
||||
Example configuration:
|
||||
|
||||
```
|
||||
auto eth0
|
||||
iface eth0 inet static
|
||||
address 192.168.1.100
|
||||
netmask 255.255.255.0
|
||||
gateway 192.168.1.1
|
||||
dns-nameservers 8.8.8.8 8.8.4.4
|
||||
```
|
||||
|
||||
## 3. DHCP Configuration
|
||||
|
||||
For dynamic IP assignment, use DHCP:
|
||||
|
||||
```
|
||||
auto eth0
|
||||
iface eth0 inet dhcp
|
||||
```
|
||||
|
||||
## 4. Network Manager
|
||||
|
||||
Many modern Linux distributions use Network Manager for easier network configuration. You can use the command-line tool 'nmcli' or GUI tools to manage connections.
|
||||
|
||||
## 5. Hostname Configuration
|
||||
|
||||
Set the hostname:
|
||||
|
||||
```
|
||||
sudo hostnamectl set-hostname new-hostname
|
||||
```
|
||||
|
||||
Update /etc/hosts file to include the new hostname.
|
||||
|
||||
## 6. DNS Configuration
|
||||
|
||||
Edit /etc/resolv.conf to set DNS servers:
|
||||
|
||||
```
|
||||
nameserver 8.8.8.8
|
||||
nameserver 8.8.4.4
|
||||
```
|
||||
|
||||
Note: This file may be overwritten by DHCP. For permanent changes, configure your network manager or DHCP client.
|
||||
|
||||
## 7. Routing
|
||||
|
||||
View routing table:
|
||||
|
||||
```
|
||||
ip route show
|
||||
```
|
||||
|
||||
Add a static route:
|
||||
|
||||
```
|
||||
sudo ip route add 10.0.0.0/24 via 192.168.1.1 dev eth0
|
||||
```
|
||||
|
||||
## 8. Firewall Configuration
|
||||
|
||||
Most Linux distributions use iptables or nftables. Ubuntu uses ufw (Uncomplicated Firewall) as a frontend.
|
||||
|
||||
Enable UFW:
|
||||
|
||||
```
|
||||
sudo ufw enable
|
||||
```
|
||||
|
||||
Allow incoming SSH:
|
||||
|
||||
```
|
||||
sudo ufw allow ssh
|
||||
```
|
||||
|
||||
## 9. Network Diagnostics
|
||||
|
||||
- ping: Test connectivity
|
||||
- traceroute: Trace packet route
|
||||
- netstat or ss: Display network connections
|
||||
- tcpdump: Capture and analyze network traffic
|
||||
|
||||
## 10. Network Service Management
|
||||
|
||||
Start/stop network service:
|
||||
|
||||
```
|
||||
sudo systemctl start networking
|
||||
sudo systemctl stop networking
|
||||
```
|
||||
|
||||
Enable/disable network service at boot:
|
||||
|
||||
```
|
||||
sudo systemctl enable networking
|
||||
sudo systemctl disable networking
|
||||
```
|
||||
|
||||
## 11. Wireless Network Configuration
|
||||
|
||||
Use 'iwconfig' to configure wireless interfaces:
|
||||
|
||||
```
|
||||
sudo iwconfig wlan0 essid "NetworkName" key s:password
|
||||
```
|
||||
|
||||
For WPA networks, use 'wpa_supplicant'.
|
||||
|
||||
## 12. Network Bonding
|
||||
|
||||
Combine multiple network interfaces for redundancy or increased throughput. Edit /etc/network/interfaces:
|
||||
|
||||
```
|
||||
auto bond0
|
||||
iface bond0 inet static
|
||||
address 192.168.1.100
|
||||
netmask 255.255.255.0
|
||||
gateway 192.168.1.1
|
||||
bond-slaves eth0 eth1
|
||||
bond-mode active-backup
|
||||
bond-miimon 100
|
||||
bond-primary eth0
|
||||
```
|
||||
|
||||
|
||||
- [(1) The Ultimate Guide to Linux Mint Network Configuration.](https://www.fosslinux.com/105545/the-ultimate-guide-to-linux-mint-network-configuration.htm.)
|
||||
- [(2) How to set up an Internet Connection in Linux Mint?.](https://unix.stackexchange.com/questions/132747/how-to-set-up-an-internet-connection-in-linux-mint.)
|
||||
- [(3) How to Share Files and Folders on a Linux Mint Network.](https://www.fosslinux.com/103443/how-to-easily-share-files-and-folders-on-a-linux-mint-network.htm.)
|
||||
- [(4) Linux Mint - Community.](https://community.linuxmint.com/tutorial/view/1966.)
|
||||
- [(5) Configure Network in Debian / Ubuntu / LinuxMint - ITzGeek.](https://www.itzgeek.com/how-tos/linux/ubuntu-how-tos/configure-network-in-ubuntu-14-04-linux-mint.html.)
|
||||
|
||||
94
04 - Networking in Linux/Firewalls (UFW and FirewallD).md
Normal file
94
04 - Networking in Linux/Firewalls (UFW and FirewallD).md
Normal file
@ -0,0 +1,94 @@
|
||||
# Linux firewalls, focusing on UFW (Uncomplicated Firewall) and firewalld(systemd):
|
||||
|
||||
## 1. Introduction to Linux Firewalls
|
||||
Linux firewalls are essential security tools that control incoming and outgoing network traffic based on predetermined security rules. They act as a barrier between trusted internal networks and untrusted external networks, such as the Internet.
|
||||
|
||||
## 2. Iptables: The Foundation
|
||||
At the core of most Linux firewall solutions is iptables, a command-line utility for configuring the Linux kernel firewall. It works by defining chains of rules that filter packets based on various criteria.
|
||||
|
||||
Key concepts:
|
||||
- Tables: filter, nat, mangle, raw
|
||||
- Chains: INPUT, OUTPUT, FORWARD
|
||||
- Rules: match criteria and target actions
|
||||
|
||||
While powerful, iptables can be complex for beginners, which led to the development of more user-friendly front-ends like UFW and firewalld.
|
||||
|
||||
## 3. UFW (Uncomplicated Firewall)
|
||||
|
||||
UFW is a simplified interface for managing iptables. It's designed to be easy to use while still providing robust firewall capabilities.
|
||||
|
||||
Key features:
|
||||
- Simple command-line syntax
|
||||
- Application profiles
|
||||
- IPv6 support
|
||||
|
||||
Basic UFW commands:
|
||||
```
|
||||
sudo ufw enable # Enable the firewall
|
||||
sudo ufw disable # Disable the firewall
|
||||
sudo ufw status # Check firewall status
|
||||
sudo ufw allow 22 # Allow incoming traffic on port 22 (SSH)
|
||||
sudo ufw deny 80 # Deny incoming traffic on port 80 (HTTP)
|
||||
sudo ufw allow from 192.168.1.0/24 # Allow traffic from a specific subnet
|
||||
```
|
||||
|
||||
Advanced usage:
|
||||
- Rate limiting: `sudo ufw limit 22/tcp`
|
||||
- Logging: `sudo ufw logging on`
|
||||
- Application profiles: `sudo ufw allow 'Apache Full'`
|
||||
|
||||
## 4. firewalld
|
||||
|
||||
firewalld is a dynamic firewall manager, primarily used in Red Hat-based distributions. It introduces the concept of zones, making it easier to manage complex network environments.
|
||||
|
||||
Key features:
|
||||
- Zone-based configuration
|
||||
- Runtime and permanent configuration options
|
||||
- D-Bus interface for easy integration with other applications
|
||||
|
||||
Basic firewalld commands:
|
||||
```
|
||||
sudo systemctl start firewalld # Start firewalld
|
||||
sudo systemctl enable firewalld # Enable firewalld to start on boot
|
||||
sudo firewall-cmd --state # Check firewalld status
|
||||
sudo firewall-cmd --zone=public --add-service=http # Allow HTTP traffic in the public zone
|
||||
sudo firewall-cmd --zone=internal --add-source=192.168.1.0/24 # Add a source to the internal zone
|
||||
```
|
||||
|
||||
Advanced usage:
|
||||
- Custom services: `sudo firewall-cmd --new-service=myapp`
|
||||
- Rich rules: `sudo firewall-cmd --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" port port="80" protocol="tcp" accept'`
|
||||
- Direct interface (for complex iptables rules): `sudo firewall-cmd --direct --add-rule ipv4 filter INPUT 0 -p tcp --dport 22 -j ACCEPT`
|
||||
|
||||
## 5. Comparing UFW and firewalld
|
||||
|
||||
### UFW:
|
||||
- Simpler, more straightforward for basic setups
|
||||
- Ideal for single-host systems or simple network configurations
|
||||
- Easier to learn for beginners
|
||||
|
||||
### firewalld:
|
||||
- More flexible and powerful for complex network setups
|
||||
- Better suited for enterprise environments with multiple network zones
|
||||
- Offers runtime and permanent configuration options
|
||||
|
||||
## 6. Best Practices
|
||||
- Use the principle of least privilege: only open ports that are necessary
|
||||
- Regularly review and update firewall rules
|
||||
- Use logging to monitor firewall activity
|
||||
- Combine firewall rules with other security measures (e.g., fail2ban for intrusion prevention)
|
||||
- Keep your firewall software updated
|
||||
|
||||
## 7. Troubleshooting
|
||||
- Check firewall logs: `/var/log/ufw.log` for UFW, `journalctl -u firewalld` for firewalld
|
||||
- Use `iptables -L -v` to view current rules (works for both UFW and firewalld)
|
||||
- Test connections with tools like `netcat` or `telnet`
|
||||
- Temporarily disable the firewall to isolate issues
|
||||
|
||||
## 8. Advanced Topics
|
||||
- Stateful vs. stateless firewalls
|
||||
- Network Address Translation (NAT) configuration
|
||||
- Setting up DMZ (Demilitarized Zone)
|
||||
- Integrating with intrusion detection/prevention systems (IDS/IPS)
|
||||
|
||||
This guide provides a comprehensive overview of Linux firewalls, focusing on UFW and firewalld. Each tool has its strengths, and the choice between them often depends on the specific requirements of your system and network configuration.
|
||||
36
04 - Networking in Linux/Firewalls.md
Normal file
36
04 - Networking in Linux/Firewalls.md
Normal file
@ -0,0 +1,36 @@
|
||||
Certainly! Let's explore how to manage firewalls in **Linux Mint** using the terminal. There are a couple of options available:
|
||||
|
||||
## 1. **UFW (Uncomplicated Firewall)**:
|
||||
- UFW is a straightforward and reliable firewall interface with both command-line and graphical tools.
|
||||
- To install UFW, open the terminal and run:
|
||||
```
|
||||
sudo apt install ufw
|
||||
```
|
||||
- Verify if UFW is active with:
|
||||
```
|
||||
sudo systemctl status ufw
|
||||
```
|
||||
- To allow specific ports (e.g., OpenSSH), use:
|
||||
```
|
||||
sudo ufw allow 22/tcp
|
||||
```
|
||||
- To disable a port, run:
|
||||
```
|
||||
sudo ufw deny 22/tcp
|
||||
```
|
||||
|
||||
2. **Gufw (GUI for UFW)**:
|
||||
- Gufw provides a graphical interface for managing UFW.
|
||||
- Install it with:
|
||||
```
|
||||
sudo apt install gufw
|
||||
```
|
||||
- Open it from the menu: "Firewall Configuration."
|
||||
|
||||
Remember, firewalls protect your network by filtering traffic based on predefined rules. Choose the method that suits your preference! 😊🔥
|
||||
|
||||
Source: Conversation with Copilot, 7/12/2024
|
||||
- [(1) How to open a firewall on Linux Mint | FOSS Linux.](https://www.fosslinux.com/50961/open-a-firewall-on-linux-mint.htm.)
|
||||
- [(2) Linux Mint - Community.](https://community.linuxmint.com/tutorial/view/1899.)
|
||||
- [(3) LINUX Firewall - GeeksforGeeks.](https://www.geeksforgeeks.org/linux-firewall/.)
|
||||
- [(4) firewalld-cmd Command in Linux: 24 Examples.](https://linuxhandbook.com/firewalld-cmd/.)
|
||||
222
04 - Networking in Linux/Network Troubleshooting.md
Normal file
222
04 - Networking in Linux/Network Troubleshooting.md
Normal file
@ -0,0 +1,222 @@
|
||||
# Linux Network Troubleshooting Guide
|
||||
|
||||
## 1. Basic Network Configuration Check:
|
||||
|
||||
- Check IP address and network interface status:
|
||||
```
|
||||
ip addr show
|
||||
```
|
||||
This command displays all network interfaces, their IP addresses, and status.
|
||||
|
||||
- Verify default gateway:
|
||||
```
|
||||
ip route show
|
||||
```
|
||||
Ensures your system knows how to route traffic outside the local network.
|
||||
|
||||
- Check DNS configuration:
|
||||
```
|
||||
cat /etc/resolv.conf
|
||||
```
|
||||
Displays the DNS servers your system is using.
|
||||
|
||||
## 2. Connectivity Tests:
|
||||
|
||||
- Ping test:
|
||||
```
|
||||
ping -c 4 8.8.8.8
|
||||
```
|
||||
Tests basic connectivity to Google's DNS server (or any other IP).
|
||||
|
||||
- Traceroute:
|
||||
```
|
||||
traceroute google.com
|
||||
```
|
||||
Shows the path packets take to reach a destination.
|
||||
|
||||
- DNS resolution test:
|
||||
```
|
||||
nslookup google.com
|
||||
```
|
||||
or
|
||||
```
|
||||
dig google.com
|
||||
```
|
||||
These test DNS resolution capabilities.
|
||||
|
||||
## 3. Advanced Diagnostic Tools:
|
||||
|
||||
- netstat or ss:
|
||||
```
|
||||
netstat -tuln
|
||||
```
|
||||
or
|
||||
```
|
||||
ss -tuln
|
||||
```
|
||||
Display active network connections and listening ports.
|
||||
|
||||
- tcpdump:
|
||||
```
|
||||
sudo tcpdump -i eth0
|
||||
```
|
||||
Captures and displays packet data on a specified interface.
|
||||
|
||||
- nmap:
|
||||
```
|
||||
nmap -p- localhost
|
||||
```
|
||||
Scans for open ports on the local machine (or any specified target).
|
||||
|
||||
## 4. Firewall Configuration:
|
||||
|
||||
- Check iptables rules:
|
||||
```
|
||||
sudo iptables -L -v -n
|
||||
```
|
||||
Displays current firewall rules.
|
||||
|
||||
- Temporarily disable firewall (for testing):
|
||||
```
|
||||
sudo systemctl stop firewalld # for systems using firewalld
|
||||
```
|
||||
or
|
||||
```
|
||||
sudo ufw disable # for systems using ufw
|
||||
```
|
||||
|
||||
## 5. Network Service Diagnostics:
|
||||
|
||||
- Check service status:
|
||||
```
|
||||
systemctl status networking
|
||||
```
|
||||
or
|
||||
```
|
||||
systemctl status NetworkManager
|
||||
```
|
||||
|
||||
- Restart network service:
|
||||
```
|
||||
sudo systemctl restart networking
|
||||
```
|
||||
or
|
||||
```
|
||||
sudo systemctl restart NetworkManager
|
||||
```
|
||||
|
||||
## 6. Network Interface Configuration:
|
||||
|
||||
- Edit network interface configuration:
|
||||
```
|
||||
sudo nano /etc/network/interfaces # for Debian-based systems
|
||||
```
|
||||
or
|
||||
```
|
||||
sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0 # for Red Hat-based systems
|
||||
```
|
||||
|
||||
- Restart specific network interface:
|
||||
```
|
||||
sudo ifdown eth0 && sudo ifup eth0
|
||||
```
|
||||
or
|
||||
```
|
||||
sudo ip link set eth0 down && sudo ip link set eth0 up
|
||||
```
|
||||
|
||||
## 7. Wireless Network Troubleshooting:
|
||||
|
||||
- List available wireless networks:
|
||||
```
|
||||
sudo iwlist wlan0 scan
|
||||
```
|
||||
|
||||
- Check wireless interface details:
|
||||
```
|
||||
iwconfig
|
||||
```
|
||||
|
||||
- Monitor wireless connection in real-time:
|
||||
```
|
||||
watch -n 1 iwconfig
|
||||
```
|
||||
|
||||
## 8. Advanced Network Analysis:
|
||||
|
||||
- Wireshark: GUI-based packet analyzer
|
||||
Install with:
|
||||
```
|
||||
sudo apt-get install wireshark # on Debian-based systems
|
||||
```
|
||||
or
|
||||
```
|
||||
sudo yum install wireshark # on Red Hat-based systems
|
||||
```
|
||||
|
||||
- iftop: Displays bandwidth usage on an interface
|
||||
```
|
||||
sudo iftop -i eth0
|
||||
```
|
||||
|
||||
- nethogs: Groups bandwidth by process
|
||||
```
|
||||
sudo nethogs eth0
|
||||
```
|
||||
|
||||
## 9. Performance Testing:
|
||||
|
||||
- iperf: Network performance measurement tool
|
||||
```
|
||||
iperf -s # on server
|
||||
iperf -c server_ip # on client
|
||||
```
|
||||
|
||||
- speedtest-cli: Command-line interface for testing internet speed
|
||||
```
|
||||
speedtest-cli
|
||||
```
|
||||
|
||||
## 10. Log Analysis:
|
||||
|
||||
- System logs:
|
||||
```
|
||||
sudo tail -f /var/log/syslog # on Debian-based systems
|
||||
```
|
||||
or
|
||||
```
|
||||
sudo tail -f /var/log/messages # on Red Hat-based systems
|
||||
```
|
||||
or
|
||||
```
|
||||
sudo journalctl -b0
|
||||
```
|
||||
or
|
||||
```
|
||||
sudo dmesg -k
|
||||
```
|
||||
|
||||
- Network-specific logs:
|
||||
```
|
||||
sudo tail -f /var/log/daemon.log
|
||||
```
|
||||
|
||||
## 11. Network Configuration Backup and Restore:
|
||||
|
||||
- Backup network configuration:
|
||||
```
|
||||
sudo tar -czvf network_config_backup.tar.gz /etc/network
|
||||
```
|
||||
|
||||
- Restore network configuration:
|
||||
```
|
||||
sudo tar -xzvf network_config_backup.tar.gz -C /
|
||||
```
|
||||
|
||||
## 12. Troubleshooting Specific Issues:
|
||||
|
||||
- High latency: Use ping and traceroute to identify where delays occur.
|
||||
- Packet loss: Use mtr (My TraceRoute) for a combination of ping and traceroute.
|
||||
- DNS issues: Check /etc/hosts file and DNS server configurations.
|
||||
- IP conflicts: Use arping to detect duplicate IP addresses on the network.
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
## Certainly! To use SSH in **Linux Mint**, follow these steps:
|
||||
|
||||
1. **Install OpenSSH Server**:
|
||||
- Open a terminal by clicking the terminal icon in the taskbar.
|
||||
- Install the OpenSSH server package with this command (use root privileges): `sudo apt-get install openssh-server -y`.
|
||||
|
||||
2. **Check SSH Status**:
|
||||
- SSH should be configured to start automatically on boot. Confirm this with:
|
||||
```
|
||||
systemctl is-enabled ssh
|
||||
```
|
||||
- If it's disabled, enable it using: `sudo systemctl enable ssh`.
|
||||
|
||||
3. **Test SSH Access**:
|
||||
- Find your Linux Mint machine's IP address (e.g., `192.168.1.20`) using `ip a`.
|
||||
- Use PuTTY or any SSH client to connect: `ssh username@192.168.1.20`.
|
||||
- Enter your password when prompted¹.
|
||||
|
||||
Feel free to ask if you need further assistance! 😊🚀
|
||||
|
||||
Source: Conversation with Copilot, 7/12/2024
|
||||
- [(1) How To Enable SSH in Linux Mint - RootUsers.](https://www.rootusers.com/enable-ssh-linux-mint/.)
|
||||
- [(2) How-to Guide Linux Networking with SSH - Linux Mint Forums.](https://forums.linuxmint.com/viewtopic.php?t=13695.)
|
||||
- [(3) Linux Mint - Community.]( https://community.linuxmint.com/tutorial/view/83.)
|
||||
- [(4) How to Install and Enable SSH on Linux Mint 21 – LinuxWays.](https://linuxways.net/mint/install-enable-ssh-linux-mint-21/.)
|
||||
- [(5) Linux Mint - Community.](https://community.linuxmint.com/tutorial/view/244.)
|
||||
- [(6) en.wikipedia.org.](https://en.wikipedia.org/wiki/Linux_Mint.)
|
||||
90
04 - Networking in Linux/Secure Shell (SSH).md
Normal file
90
04 - Networking in Linux/Secure Shell (SSH).md
Normal file
@ -0,0 +1,90 @@
|
||||
# Secure Shell (SSH):
|
||||
|
||||
## 1. Introduction to SSH
|
||||
|
||||
Secure Shell (SSH) is a cryptographic network protocol used for secure communication over an unsecured network. It provides a secure channel for data exchange between two networked devices, typically used for remote command-line login and remote command execution.
|
||||
|
||||
## 2. Key Features of SSH
|
||||
|
||||
- Encryption: All communication is encrypted, protecting against eavesdropping.
|
||||
- Authentication: Ensures the identity of the communicating parties.
|
||||
- Integrity: Guarantees that the transmitted data hasn't been altered.
|
||||
- Port Forwarding: Allows secure tunneling of other protocols.
|
||||
|
||||
## 3. How SSH Works
|
||||
|
||||
SSH operates on a client-server model. The process typically involves:
|
||||
|
||||
- Key Exchange: The client and server agree on a shared secret key.
|
||||
- Encryption Negotiation: They decide on the encryption algorithm to use.
|
||||
- Authentication: The server authenticates the client.
|
||||
- Session: Encrypted data transfer begins.
|
||||
|
||||
## 4. SSH Authentication Methods
|
||||
|
||||
- Password Authentication: Simple but less secure.
|
||||
- Public Key Authentication: More secure, involves a public-private key pair.
|
||||
- Host-Based Authentication: Based on the host rather than the user.
|
||||
- Keyboard-Interactive: Allows for various prompts (e.g., two-factor authentication).
|
||||
|
||||
## 5. SSH Key Management
|
||||
|
||||
- Generating Keys: Use `ssh-keygen` to create key pairs.
|
||||
- Key Types: RSA, DSA, ECDSA, Ed25519 (Ed25519 is recommended for new deployments).
|
||||
- Key Size: Larger keys are more secure but slower (e.g., 4096-bit RSA).
|
||||
- Passphrase: An extra layer of security for private keys.
|
||||
|
||||
## 6. Common SSH Commands
|
||||
|
||||
- `ssh user@hostname`: Basic connection command.
|
||||
- `scp`: Secure copy files between hosts.
|
||||
- `sftp`: Secure file transfer protocol.
|
||||
- `ssh-keygen`: Generate SSH key pairs.
|
||||
- `ssh-copy-id`: Copy public key to a remote host.
|
||||
|
||||
## 7. SSH Configuration
|
||||
|
||||
- Client Configuration: `~/.ssh/config`
|
||||
- Server Configuration: `/etc/ssh/sshd_config`
|
||||
- Important settings:
|
||||
- Port (default 22)
|
||||
- PermitRootLogin
|
||||
- PasswordAuthentication
|
||||
- PubkeyAuthentication
|
||||
|
||||
## 8. SSH Security Best Practices
|
||||
|
||||
- Use key-based authentication instead of passwords.
|
||||
- Disable root login.
|
||||
- Use non-standard ports.
|
||||
- Implement fail2ban or similar intrusion prevention systems.
|
||||
- Keep software up-to-date.
|
||||
- Use SSH protocol version 2.
|
||||
- Limit user access with AllowUsers or AllowGroups.
|
||||
|
||||
## 9. Advanced SSH Features
|
||||
|
||||
- Port Forwarding: Local, Remote, and Dynamic.
|
||||
- X11 Forwarding: Run graphical applications remotely.
|
||||
- SSH Agent: Manage multiple SSH keys.
|
||||
- ProxyJump: Easily connect through a jump host.
|
||||
|
||||
## 10. Troubleshooting SSH
|
||||
|
||||
- Connection Issues: Check network, firewall, and SSH service status.
|
||||
- Authentication Problems: Verify credentials, key permissions, and server configuration.
|
||||
- Performance Issues: Consider compression or alternative ciphers.
|
||||
|
||||
## 11. SSH Alternatives and Related Protocols
|
||||
|
||||
- Telnet: Older, unencrypted protocol (not recommended).
|
||||
- RDP: Remote Desktop Protocol (mainly for Windows).
|
||||
- VNC: Virtual Network Computing (graphical desktop sharing).
|
||||
|
||||
## 12. SSH in Enterprise Environments
|
||||
|
||||
- Centralized key management solutions.
|
||||
- Integration with LDAP or Active Directory.
|
||||
- Auditing and logging considerations.
|
||||
- Bastion hosts for added security.
|
||||
|
||||
162
04 - Networking in Linux/VPN and Proxy Configuration.md
Normal file
162
04 - Networking in Linux/VPN and Proxy Configuration.md
Normal file
@ -0,0 +1,162 @@
|
||||
i# VPN and proxy configuration in Linux
|
||||
|
||||
## 1. VPN Configuration
|
||||
|
||||
VPNs (Virtual Private Networks) provide secure, encrypted connections over public networks. There are several VPN protocols and clients available for Linux.
|
||||
|
||||
### OpenVPN:
|
||||
OpenVPN is one of the most popular and secure VPN protocols. To set it up:
|
||||
|
||||
- 1. Install OpenVPN:
|
||||
```
|
||||
sudo apt install openvpn
|
||||
```
|
||||
|
||||
- 2. Obtain configuration files from your VPN provider.
|
||||
|
||||
- 3. Connect to the VPN:
|
||||
```
|
||||
sudo openvpn --config /path/to/your/config.ovpn
|
||||
```
|
||||
|
||||
- 4. For automatic connection, create a systemd service:
|
||||
```
|
||||
sudo nano /etc/systemd/system/openvpn.service
|
||||
```
|
||||
Add the following content:
|
||||
```
|
||||
[Unit]
|
||||
Description=OpenVPN connection to YOUR_VPN
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/sbin/openvpn --config /path/to/your/config.ovpn
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
Enable and start the service:
|
||||
```
|
||||
sudo systemctl enable openvpn.service
|
||||
sudo systemctl start openvpn.service
|
||||
```
|
||||
|
||||
### WireGuard:
|
||||
WireGuard is a newer, faster VPN protocol. To set it up:
|
||||
|
||||
- a. Install WireGuard:
|
||||
```
|
||||
sudo apt install wireguard
|
||||
```
|
||||
|
||||
- b. Create a configuration file:
|
||||
```
|
||||
sudo nano /etc/wireguard/wg0.conf
|
||||
```
|
||||
Add your WireGuard configuration details.
|
||||
|
||||
- c. Start the WireGuard connection:
|
||||
```
|
||||
sudo wg-quick up wg0
|
||||
```
|
||||
|
||||
- d. To enable automatic connection on boot:
|
||||
```
|
||||
sudo systemctl enable wg-quick@wg0
|
||||
```
|
||||
|
||||
### Built-in VPN clients:
|
||||
Many Linux distributions include built-in VPN clients in their network managers, supporting protocols like OpenVPN, L2TP/IPsec, and PPTP.
|
||||
|
||||
## 2. Proxy Configuration
|
||||
|
||||
Proxies route your traffic through an intermediary server. There are several ways to configure proxies in Linux:
|
||||
|
||||
### Environment variables:
|
||||
Set these variables in your shell configuration file (e.g., ~/.bashrc):
|
||||
```
|
||||
export http_proxy="http://proxy_server:port"
|
||||
export https_proxy="http://proxy_server:port"
|
||||
export ftp_proxy="http://proxy_server:port"
|
||||
export no_proxy="localhost,127.0.0.1,::1"
|
||||
```
|
||||
|
||||
### System-wide proxy settings:
|
||||
For GNOME-based systems:
|
||||
- a. Open Settings > Network > Network Proxy
|
||||
- b. Choose "Manual" and enter your proxy details
|
||||
|
||||
### For KDE-based systems:
|
||||
- a. Open System Settings > Network Settings > Proxy
|
||||
- b. Choose "Manual" and enter your proxy details
|
||||
|
||||
### Application-specific proxy settings:
|
||||
Many applications have their own proxy settings. For example:
|
||||
|
||||
- Firefox: Preferences > Network Settings > Configure Proxy Access to the Internet
|
||||
- Chrome: Settings > Advanced > System > Open your computer's proxy settings
|
||||
|
||||
### Command-line tools:
|
||||
Use proxychains to route terminal commands through a proxy:
|
||||
|
||||
#### 1. Install proxychains:
|
||||
```
|
||||
sudo apt install proxychains
|
||||
```
|
||||
|
||||
#### 2. Configure proxychains:
|
||||
```
|
||||
sudo nano /etc/proxychains.conf
|
||||
```
|
||||
Add your proxy server details.
|
||||
|
||||
#### 3. Use proxychains:
|
||||
```
|
||||
proxychains command_to_run
|
||||
```
|
||||
|
||||
### SOCKS proxy with SSH:
|
||||
Create a SOCKS proxy using SSH:
|
||||
```
|
||||
ssh -D 1080 -f -C -q -N username@remote_host
|
||||
```
|
||||
Then configure applications to use SOCKS5 proxy at 127.0.0.1:1080.
|
||||
|
||||
## 3. Testing and Verification
|
||||
|
||||
To verify your VPN or proxy configuration:
|
||||
|
||||
- Check your IP address:
|
||||
```
|
||||
curl ifconfig.me
|
||||
```
|
||||
|
||||
- DNS leak test:
|
||||
```
|
||||
dig +short myip.opendns.com @resolver1.opendns.com
|
||||
```
|
||||
|
||||
- WebRTC leak test (in browsers)
|
||||
|
||||
- Use tools like ipleak.net or dnsleak.com
|
||||
|
||||
## 4. Security Considerations
|
||||
|
||||
- Keep your VPN client and system updated
|
||||
- Use strong authentication methods (e.g., certificates for OpenVPN)
|
||||
- Be cautious with free VPN or proxy services
|
||||
- Consider using a kill switch to prevent traffic leaks if the VPN disconnects
|
||||
|
||||
## 5. Troubleshooting
|
||||
|
||||
- Check logs: `journalctl -u openvpn` or `journalctl -u wg-quick@wg0`
|
||||
- Verify DNS settings
|
||||
- Ensure correct permissions on configuration files
|
||||
- Check for conflicting network settings
|
||||
|
||||
- [(1) Setting Up a VPN on Linux Mint: A Step-by-Step Guide - FOSS Linux.](https://www.fosslinux.com/102356/how-to-set-up-a-vpn-on-linux-mint.htm.)
|
||||
- [(2) How to Configure OpenVPN in Linux Mint? – IPVanish.](https://support.ipvanish.com/hc/en-us/articles/360001738513-How-to-Configure-OpenVPN-in-Linux-Mint.)
|
||||
- [(3) How to configure OpenVPN on Linux Mint - FastVPN - Namecheap.](https://www.namecheap.com/support/knowledgebase/article.aspx/10416/2271/how-to-configure-openvpn-on-linux-mint/.)
|
||||
- [(4) How to Set up an OpenVPN Connection in Linux Mint - Comparitech.](https://www.comparitech.com/blog/vpn-privacy/openvpn-connection-linux-mint/.)
|
||||
110
05 - Linux Permissions and Ownership/The sudo Command.md
Normal file
110
05 - Linux Permissions and Ownership/The sudo Command.md
Normal file
@ -0,0 +1,110 @@
|
||||
# The sudo Command: Elevating Privileges in Linux
|
||||
|
||||
## Introduction
|
||||
|
||||
The sudo command, short for "superuser do," is a fundamental tool in Unix-like operating systems, including Linux. It allows users to execute commands with elevated privileges, typically as the superuser (root). This tutorial will cover the basics of sudo, its configuration, usage examples, and best practices.
|
||||
|
||||
### Basic Concept
|
||||
|
||||
Sudo operates on the principle of least privilege, allowing users to run specific commands with root privileges without logging in as the root user. This enhances security by limiting exposure to potential mistakes or malicious actions while still providing the necessary access for system administration tasks.
|
||||
|
||||
### Syntax
|
||||
|
||||
The basic syntax for sudo is:
|
||||
|
||||
```
|
||||
sudo [options] command
|
||||
```
|
||||
|
||||
### Common Options
|
||||
|
||||
- `-u` username: Run the command as a user other than root
|
||||
- `-i:` Simulate initial login (shell)
|
||||
- `-s:` Run the specified shell
|
||||
- `-l:` List the allowed commands for the current user
|
||||
- `-v:` Validate and update the user's timestamp without running a command
|
||||
|
||||
## Configuration
|
||||
|
||||
Sudo's behavior is controlled by the /etc/sudoers file. This file defines who can use sudo and what commands they can run. It's crucial to edit this file using the visudo command, which provides syntax checking to prevent configuration errors.
|
||||
|
||||
>**To edit the sudoers file:**
|
||||
|
||||
```
|
||||
sudo visudo
|
||||
```
|
||||
|
||||
## Basic sudoers File Structure
|
||||
|
||||
```
|
||||
# User privilege specification
|
||||
root ALL=(ALL:ALL) ALL
|
||||
|
||||
# Allow members of group sudo to execute any command
|
||||
%sudo ALL=(ALL:ALL) ALL
|
||||
|
||||
# Allow specific user to run specific commands without a password
|
||||
username ALL=(ALL) NOPASSWD: /path/to/command1, /path/to/command2
|
||||
```
|
||||
|
||||
### Usage Examples
|
||||
|
||||
- Run a command as root:
|
||||
```
|
||||
sudo apt update
|
||||
```
|
||||
|
||||
- Edit a system file:
|
||||
```
|
||||
sudo nano /etc/hosts
|
||||
```
|
||||
|
||||
- Switch to root user:
|
||||
```
|
||||
sudo -i
|
||||
```
|
||||
|
||||
- Run a command as another user:
|
||||
```
|
||||
sudo -u username command
|
||||
```
|
||||
|
||||
- List allowed commands:
|
||||
```
|
||||
sudo -l
|
||||
```
|
||||
|
||||
### Sudo vs. Su
|
||||
|
||||
While both sudo and su can be used to gain root privileges, sudo is generally preferred because:
|
||||
- It provides more granular control over permissions
|
||||
- It logs commands for accountability
|
||||
- It doesn't require sharing the root password
|
||||
|
||||
## Security Best Practices
|
||||
|
||||
- Limit sudo access to only necessary users
|
||||
- Use specific command permissions instead of blanket access
|
||||
- Regularly audit sudo logs `(/var/log/auth.log or /var/log/secure)`
|
||||
- Use `NOPASSWD` sparingly
|
||||
- Set a short timeout for sudo sessions (defaults to 15 minutes)
|
||||
|
||||
## Advanced Features
|
||||
|
||||
- Aliases: Group users, hosts, or commands for easier management
|
||||
- Lecture option: Display a warning message before allowing sudo usage
|
||||
- Environment variable passing: Control which environment variables are preserved when using sudo
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
#### Common issues include:
|
||||
|
||||
- `"user is not in the sudoers file":` Add the user to the sudo group or sudoers file
|
||||
|
||||
- Forgotten sudo password: Boot into recovery mode to reset the password
|
||||
|
||||
- Syntax errors in sudoers: Use visudo to edit and check for errors
|
||||
|
||||
# Conclusion
|
||||
|
||||
The sudo command is a powerful tool for managing privileges in Linux systems. By understanding its configuration and usage, system administrators can maintain a secure environment while still allowing users to perform necessary tasks with elevated permissions.
|
||||
@ -0,0 +1,151 @@
|
||||
# File Permissions in Linux: A Comprehensive Guide
|
||||
|
||||
## 1. Introduction to File Permissions
|
||||
|
||||
In Linux, file permissions are a crucial aspect of system security and user access control. They determine who can read, write, or execute files and directories. Understanding file permissions is essential for system administrators and users alike.
|
||||
|
||||
## 2. Basic Concepts
|
||||
|
||||
### Users and Groups
|
||||
Every file and directory in Linux is owned by a user and associated with a group.
|
||||
There are three types of users:
|
||||
- Owner: The user who created or owns the file
|
||||
- Group: Users belonging to the file's group
|
||||
- Others: All other users on the system
|
||||
|
||||
### Permission Types
|
||||
- There are three basic permission types:
|
||||
a) Read (r): Allows viewing the contents of a file or listing the contents of a directory
|
||||
b) Write (w): Allows modifying a file or creating/deleting files within a directory
|
||||
c) Execute (x): Allows running a file as a program or accessing a directory
|
||||
|
||||
## 3. Viewing File Permissions
|
||||
|
||||
To view file permissions, use the `ls -l` command. The output will look like this:
|
||||
|
||||
```
|
||||
-rwxrw-r-- 1 user group 4096 Jul 22 10:00 example.txt
|
||||
```
|
||||
|
||||
Let's break down this information:
|
||||
- First character: File type (- for regular file, d for directory)
|
||||
- Next 9 characters: Permissions for owner, group, and others
|
||||
- User and group names
|
||||
- File size
|
||||
- Last modification date and time
|
||||
- File name
|
||||
|
||||
## 4. Understanding Permission Notation
|
||||
|
||||
### Symbolic Notation
|
||||
Permissions are represented by 9 characters, grouped into three sets of three:
|
||||
- First set: Owner permissions (rwx)
|
||||
- Second set: Group permissions (rwx)
|
||||
- Third set: Others permissions (rwx)
|
||||
|
||||
Each set uses 'r' for read, 'w' for write, and 'x' for execute. A hyphen (-) indicates the absence of that permission.
|
||||
|
||||
### Numeric Notation
|
||||
Permissions can also be represented numerically:
|
||||
- Read (r) = 4
|
||||
- Write (w) = 2
|
||||
- Execute (x) = 1
|
||||
|
||||
The sum of these values for each user category represents the permissions:
|
||||
- 7 (4+2+1) = rwx (Read, Write, Execute)
|
||||
- 6 (4+2) = rw- (Read, Write)
|
||||
- 5 (4+1) = r-x (Read, Execute)
|
||||
- 4 = r-- (Read only)
|
||||
- 3 (2+1) = -wx (Write, Execute)
|
||||
- 2 = -w- (Write only)
|
||||
- 1 = --x (Execute only)
|
||||
- 0 = --- (No permissions)
|
||||
|
||||
##5. Changing File Permissions
|
||||
|
||||
### Using chmod with Symbolic Notation
|
||||
The `chmod` command is used to change file permissions. The basic syntax is:
|
||||
|
||||
```
|
||||
chmod [who][operation][permissions] filename
|
||||
```
|
||||
|
||||
- Who: u (user/owner), g (group), o (others), a (all)
|
||||
- Operation: + (add), - (remove), = (set exactly)
|
||||
- Permissions: r, w, x
|
||||
|
||||
Examples:
|
||||
- `chmod u+x file.txt`: Add execute permission for the owner
|
||||
- `chmod go-rw file.txt`: Remove read and write permissions for group and others
|
||||
- `chmod a=rx file.txt`: Set read and execute permissions for all users
|
||||
|
||||
### Using chmod with Numeric Notation
|
||||
You can also use numeric notation with chmod:
|
||||
|
||||
```
|
||||
chmod [numeric_permissions] filename
|
||||
```
|
||||
|
||||
Example:
|
||||
- `chmod 755 file.txt`: Set rwx for owner, rx for group and others
|
||||
|
||||
## 6. Changing File Ownership
|
||||
|
||||
### chown command
|
||||
Use `chown` to change the owner of a file:
|
||||
|
||||
```
|
||||
chown new_owner filename
|
||||
```
|
||||
|
||||
### chgrp command
|
||||
Use `chgrp` to change the group of a file:
|
||||
|
||||
```
|
||||
chgrp new_group filename
|
||||
```
|
||||
|
||||
## 7. Special Permissions
|
||||
|
||||
### SetUID (Set User ID)
|
||||
- Represented by 's' in the owner's execute position
|
||||
- Allows a file to be executed with the permissions of the file owner
|
||||
- Numeric value: 4000
|
||||
|
||||
### SetGID (Set Group ID)
|
||||
- Represented by 's' in the group's execute position
|
||||
- For files: Executes with the permissions of the file group
|
||||
- For directories: New files inherit the directory's group
|
||||
- Numeric value: 2000
|
||||
|
||||
### Sticky Bit
|
||||
- Represented by 't' in the others' execute position
|
||||
- Used on directories to prevent users from deleting files they don't own
|
||||
- Numeric value: 1000
|
||||
|
||||
Example:
|
||||
`chmod 4755 file`: Sets SetUID and rwxr-xr-x permissions
|
||||
|
||||
## 8. Default Permissions
|
||||
|
||||
The `umask` command sets the default permissions for newly created files and directories. It specifies which permissions should be removed from the default (666 for files, 777 for directories).
|
||||
|
||||
Example:
|
||||
- `umask 022`: New files will have 644 permissions, new directories 755
|
||||
|
||||
## 9. Access Control Lists (ACLs)
|
||||
|
||||
For more fine-grained control, Linux supports ACLs. Use `setfacl` to set and `getfacl` to view ACLs.
|
||||
|
||||
Example:
|
||||
`setfacl -m u:username:rx file.txt`: Grant read and execute permissions to a specific user
|
||||
|
||||
## 10. Practical Tips
|
||||
- Always use the principle of least privilege
|
||||
- Regularly audit file permissions
|
||||
- Be cautious when using recursive permission changes
|
||||
- Understand the implications of SetUID and SetGID bits
|
||||
|
||||
## 11. Conclusion
|
||||
|
||||
Understanding Linux file permissions is crucial for maintaining system security and proper access control. By mastering these concepts and commands, you can effectively manage file access and protect sensitive data on your Linux systems.
|
||||
@ -0,0 +1,57 @@
|
||||
# Understanding UserID (UID) and GroupID (GID)
|
||||
|
||||
## 1. Introduction to UIDs and GIDs:
|
||||
In Linux, every user and group is assigned a unique numerical identifier. For users, this is called the User ID (UID), and for groups, it's the Group ID (GID). These IDs are fundamental to the Linux security model and permission system.
|
||||
|
||||
## 2. User IDs (UIDs):
|
||||
- A UID is a positive integer assigned to each user on a Linux system.
|
||||
- UIDs are used internally by the system to identify users and determine their access rights.
|
||||
- The root user always has a UID of 0.
|
||||
- Traditional Linux systems reserved UIDs 1-99 for system accounts, 100-999 for system applications, and 1000+ for regular users.
|
||||
- Modern systems often start regular user UIDs at 1000 or higher.
|
||||
|
||||
## 3. Group IDs (GIDs):
|
||||
- Similar to UIDs, GIDs are positive integers assigned to each group on the system.
|
||||
- Groups are used to organize users and manage permissions collectively.
|
||||
- The root group typically has a GID of 0.
|
||||
- Like UIDs, GIDs below 1000 are often reserved for system groups, while 1000+ are for user-created groups.
|
||||
- Each user has a primary group (primary GID) and can be a member of multiple secondary groups.
|
||||
|
||||
## 4. How UIDs and GIDs are stored:
|
||||
- User information, including UIDs, is stored in the /etc/passwd file.
|
||||
- Group information, including GIDs, is stored in the /etc/group file.
|
||||
- Encrypted passwords are typically stored in /etc/shadow (for users) and /etc/gshadow (for groups).
|
||||
|
||||
## 5. Special UIDs and GIDs:
|
||||
- UID 0 (root): Has full system access and privileges.
|
||||
- UID 65534 (nobody): Often used for unprivileged processes or NFS access.
|
||||
- GID 0 (root): The primary group for the root user.
|
||||
- GID 65534 (nogroup): Often used for unprivileged processes.
|
||||
|
||||
## 6. Viewing and modifying UIDs and GIDs:
|
||||
- View current user and group: id command
|
||||
- View all users: cat /etc/passwd
|
||||
- View all groups: cat /etc/group
|
||||
- Change a user's UID: usermod -u NEW_UID USERNAME
|
||||
- Change a group's GID: groupmod -g NEW_GID GROUPNAME
|
||||
- Add a user to a group: usermod -aG GROUPNAME USERNAME
|
||||
|
||||
## 7. UIDs, GIDs, and file permissions:
|
||||
- Each file and directory in Linux has an owner (UID) and a group (GID).
|
||||
- File permissions are based on these ownership attributes.
|
||||
- The `ls -l` command shows file ownership and permissions.
|
||||
- Changing file ownership: chown USER:GROUP FILENAME
|
||||
|
||||
## 8. Security implications:
|
||||
- UIDs and GIDs are crucial for access control and privilege separation.
|
||||
- Duplicate UIDs or GIDs can lead to security vulnerabilities.
|
||||
- UID 0 (root) has unrestricted access, so it should be protected and used sparingly.
|
||||
- SUID and SGID bits on executables can elevate privileges, potentially causing security risks if misused.
|
||||
|
||||
## 9. Best practices:
|
||||
- Regularly audit user and group assignments.
|
||||
- Use unique UIDs and GIDs for each user and group.
|
||||
- Implement the principle of least privilege: give users only the access they need.
|
||||
- Be cautious when changing UIDs or GIDs of existing users, as it may affect file ownership.
|
||||
- Use groups effectively to manage permissions for multiple users.
|
||||
- Regularly review and update access rights, especially for sensitive system areas.
|
||||
@ -0,0 +1,111 @@
|
||||
# Compression In Linux (tar and gzip)
|
||||
|
||||
1. Introduction to tar and gzip
|
||||
2. Using tar
|
||||
3. Using gzip
|
||||
4. Combining tar and gzip
|
||||
5. Advanced usage and options
|
||||
6. Best practices and tips
|
||||
|
||||
## 1. Introduction to tar and gzip:
|
||||
|
||||
tar (Tape Archive) and gzip (GNU Zip) are two essential utilities in Linux for archiving and compressing files.
|
||||
|
||||
- tar: Creates archives by combining multiple files and directories into a single file.
|
||||
- gzip: Compresses single files to reduce their size.
|
||||
|
||||
These tools are often used together to create compressed archives.
|
||||
|
||||
## 2. Using tar:
|
||||
|
||||
Basic syntax: tar [options] [archive_name] [files_to_archive]
|
||||
|
||||
Common options:
|
||||
- c: Create a new archive
|
||||
- x: Extract files from an archive
|
||||
- v: Verbose mode (list files processed)
|
||||
- f: Specify the archive file name
|
||||
|
||||
Examples:
|
||||
- Create an archive:
|
||||
```
|
||||
tar -cvf archive.tar file1 file2 directory1
|
||||
```
|
||||
- Extract an archive:
|
||||
```
|
||||
tar -xvf archive.tar
|
||||
```
|
||||
- List contents of an archive:
|
||||
```
|
||||
tar -tvf archive.tar
|
||||
```
|
||||
|
||||
## 3. Using gzip:
|
||||
|
||||
Basic syntax: gzip [options] [file_name]
|
||||
|
||||
Common options:
|
||||
- d: Decompress
|
||||
- r: Recursive (compress files in directories)
|
||||
- v: Verbose mode
|
||||
- [number]: Compression level (1-9, 9 being highest)
|
||||
|
||||
Examples:
|
||||
- Compress a file:
|
||||
```
|
||||
gzip file.txt
|
||||
```
|
||||
- Decompress a file:
|
||||
```
|
||||
gzip -d file.txt.gz
|
||||
```
|
||||
- Compress with highest level:
|
||||
```
|
||||
gzip -9 file.txt
|
||||
```
|
||||
|
||||
## 4. Combining tar and gzip:
|
||||
|
||||
tar can use gzip compression directly with the 'z' option.
|
||||
|
||||
- Create a compressed archive:
|
||||
```
|
||||
tar -czvf archive.tar.gz directory1
|
||||
```
|
||||
- Extract a compressed archive:
|
||||
```
|
||||
tar -xzvf archive.tar.gz
|
||||
```
|
||||
|
||||
## 5. Advanced usage and options:
|
||||
|
||||
- Exclude files or directories:
|
||||
```
|
||||
tar -czvf archive.tar.gz directory1 --exclude=*.log
|
||||
```
|
||||
- Update an existing archive:
|
||||
```
|
||||
tar -uvf archive.tar newfile
|
||||
```
|
||||
- Use bzip2 compression (often better for text):
|
||||
```
|
||||
tar -cjvf archive.tar.bz2 directory1
|
||||
```
|
||||
- Preserve file permissions:
|
||||
```
|
||||
tar -cpvf archive.tar directory1
|
||||
```
|
||||
- Split large archives:
|
||||
```
|
||||
tar -cvf - directory1 | split -b 1G - archive.tar.part
|
||||
```
|
||||
|
||||
## 6. Best practices and tips:
|
||||
|
||||
- Use .tar.gz or .tgz extension for gzip-compressed tar archives
|
||||
- Test archives after creation by listing or extracting
|
||||
- Use compression levels wisely (higher levels are slower)
|
||||
- Consider using xz for better compression (use -J option with tar)
|
||||
- For large backups, consider using incremental backups with tar's --listed-incremental option
|
||||
|
||||
This guide covers the basics and some advanced usage of tar and gzip in Linux.
|
||||
29
06 - Linux File Operations/Compression and Archiving.md
Normal file
29
06 - Linux File Operations/Compression and Archiving.md
Normal file
@ -0,0 +1,29 @@
|
||||
## Certainly! Let's delve into compression and archiving using **gzip** and **tar** in **Linux Mint**:
|
||||
|
||||
1. **Tar (Tape Archive)**:
|
||||
- **Tar** combines multiple files or directories into a single archive file.
|
||||
- Basic usage:
|
||||
- To create a tar archive: `tar -cvf archive.tar files_or_directories`
|
||||
- To extract from a tar archive: `tar -xvf archive.tar`
|
||||
- Combine with compression tools for smaller archives.
|
||||
|
||||
2. **Gzip**:
|
||||
- **Gzip** compresses files individually.
|
||||
- Basic usage:
|
||||
- To compress a file: `gzip filename` (creates `filename.gz`)
|
||||
- To decompress: `gzip -d filename.gz`
|
||||
|
||||
3. **Combining Tar and Gzip**:
|
||||
- Create a compressed tar archive (`.tar.gz` or `.tgz`):
|
||||
```
|
||||
tar -czvf archive.tar.gz files_or_directories
|
||||
```
|
||||
|
||||
Remember, these commands help manage files efficiently! Feel free to explore further or ask more questions. 😊🚀
|
||||
|
||||
Source: Conversation with Copilot, 7/12/2024
|
||||
- [(1) How to obtain maximum compression with .tar.gz? - Super User.](https://superuser.com/questions/514260/how-to-obtain-maximum-compression-with-tar-gz.)
|
||||
- [(2) How to Compress and Extract Files Using the tar Command on Linux.](https://www.howtogeek.com/248780/how-to-compress-and-extract-files-using-the-tar-command-on-linux/.)
|
||||
- [(3) File Compression and Archiving – Using tar, gzip, zip, etc..](https://cfcs2r.com/index.php/courses/linux-file-system-basics/lessons/file-compression-and-archiving-using-tar-gzip-zip-etc/.)
|
||||
- [(4) Tar command Compress and Extract Archives - ComputerNetworkingNotes.](https://www.computernetworkingnotes.com/linux-tutorials/tar-command-compress-and-extract-archives.html.)
|
||||
- [(5) How to archive a file with tar gz. and gzip command..](https://nexonhost.com/how-to-archive-a-file-with-tar-gz-and-gzip-command/.)
|
||||
28
06 - Linux File Operations/Directories and Links.md
Normal file
28
06 - Linux File Operations/Directories and Links.md
Normal file
@ -0,0 +1,28 @@
|
||||
## Certainly! Let's explore directories and symbolic links in **Linux Mint**:
|
||||
|
||||
1. **Directories (Folders)**:
|
||||
- Directories are like containers that organize files. They hold files and other directories.
|
||||
- When you navigate through your file system, you're moving between directories.
|
||||
- Common terminal commands related to directories:
|
||||
- `ls`: Lists files and directories in the current working directory³.
|
||||
- `cd`: Changes the current directory (e.g., `cd Documents`).
|
||||
|
||||
2. **Symbolic Links (Symlinks)**:
|
||||
- Symlinks are advanced shortcuts.
|
||||
- A symlink points to another file or directory, even though it appears as if it's the actual file.
|
||||
- To create a symlink using the `ln` command:
|
||||
```
|
||||
ln -s /path/to/original /path/to/link
|
||||
```
|
||||
- For example, creating a symlink from your Downloads folder to your Desktop:
|
||||
```
|
||||
ln -s /home/username/Downloads /home/username/Desktop
|
||||
```
|
||||
|
||||
Remember, directories organize files, and symlinks provide flexible references to other locations! Feel free to explore further or ask more questions. 😊🚀
|
||||
|
||||
Source: Conversation with Copilot, 7/12/2024
|
||||
- [(1) The beginner’s guide to using terminal on Linux Mint - FOSS Linux.](https://www.fosslinux.com/103546/the-beginners-guide-to-using-terminal-on-linux-mint.htm.)
|
||||
- [(2) How to Create and Use Symbolic Links (aka Symlinks) on Linux.](https://www.howtogeek.com/287014/how-to-create-and-use-symbolic-links-aka-symlinks-on-linux/.)
|
||||
- [(3) Open a terminal window and change to the directory where you.](https://forums.linuxmint.com/viewtopic.php?t=97386.)
|
||||
- [(4) How to Find Files and Directories in Linux Mint 20 – LinuxWays.](https://linuxways.net/mint/how-to-find-files-and-directories-in-linux-mint-20/.)
|
||||
@ -0,0 +1,75 @@
|
||||
# Directories and Symlinks
|
||||
|
||||
## Directories:
|
||||
|
||||
### 1. Definition:
|
||||
A directory (also called a folder) is a container in a file system that can hold files and other directories. It organizes files and provides a hierarchical structure.
|
||||
|
||||
### 2. Types of directories:
|
||||
- Root directory: The top-level directory in the file system hierarchy, typically represented by "/" on Unix-like systems.
|
||||
- Home directory: The default directory for a user, usually containing personal files and configurations.
|
||||
- Parent directory: The directory one level above the current directory, represented by "..".
|
||||
- Current directory: The directory you're currently in, represented by ".".
|
||||
- Subdirectory: Any directory contained within another directory.
|
||||
|
||||
### 3. Directory operations:
|
||||
- Create: mkdir (make directory)
|
||||
- Delete: rmdir (remove directory) or rm -r (remove recursively)
|
||||
- Change: cd (change directory)
|
||||
- List contents: ls (list) or dir (on Windows)
|
||||
- View path: pwd (print working directory)
|
||||
|
||||
### 4. Directory permissions:
|
||||
On Unix-like systems, directories have read (r), write (w), and execute (x) permissions. The execute permission allows users to enter the directory.
|
||||
|
||||
### 5. Hidden directories:
|
||||
In Unix-like systems, directories starting with a dot (.) are hidden by default.
|
||||
|
||||
## Symlinks (Symbolic Links):
|
||||
|
||||
### 1. Definition:
|
||||
A symlink is a special type of file that points to another file or directory. It's similar to a shortcut in Windows or an alias in macOS.
|
||||
|
||||
### 2. Types of symlinks:
|
||||
- Soft links (symbolic links): Point to a file or directory by name. They can span file systems and can link to non-existent targets.
|
||||
- Hard links: Point directly to the inode of a file. They can't span file systems or link to directories.
|
||||
|
||||
### 3. Creating symlinks:
|
||||
Use the ln command with the -s option:
|
||||
```
|
||||
ln -s target_path link_path
|
||||
```
|
||||
|
||||
### 4. Advantages of symlinks:
|
||||
- Save space by avoiding duplicate files
|
||||
- Create shortcuts to frequently accessed files or directories
|
||||
- Maintain multiple versions of files or configurations
|
||||
- Facilitate easier software updates and management
|
||||
|
||||
### 5. Symlink behavior:
|
||||
- When you access a symlink, the system automatically redirects to the target.
|
||||
- Deleting a symlink doesn't affect the target file or directory.
|
||||
- If the target is deleted, the symlink becomes a "dangling" or "broken" link.
|
||||
|
||||
### 6. Identifying symlinks:
|
||||
- Use ls -l to see detailed file information. Symlinks are indicated by an "l" at the start of the permissions string.
|
||||
- The file command can also identify symlinks.
|
||||
|
||||
### 7. Following symlinks:
|
||||
- Some commands (like cp) don't follow symlinks by default. Use the -L or --follow options to change this behavior.
|
||||
|
||||
### 8. Symlinks in different operating systems:
|
||||
- Unix-like systems (Linux, macOS): Native support for symlinks.
|
||||
- Windows: Limited support in older versions, full support since Windows Vista.
|
||||
|
||||
### 9. Security considerations:
|
||||
- Symlinks can potentially be used in symlink attacks, where an attacker creates a link to a sensitive file.
|
||||
- Many systems implement symlink protections to mitigate these risks.
|
||||
|
||||
### 10. Use cases:
|
||||
- Maintaining multiple versions of configuration files
|
||||
- Creating shortcuts in the file system
|
||||
- Managing shared libraries
|
||||
- Facilitating easier software updates
|
||||
|
||||
Understanding directories and symlinks is crucial for effective file system management, particularly in Unix-like environments. They provide powerful tools for organizing and accessing files efficiently.
|
||||
@ -0,0 +1,106 @@
|
||||
# File Creation, Deleting, and Renaming
|
||||
|
||||
## 1. Creating Files
|
||||
|
||||
There are several ways to create files in Linux:
|
||||
|
||||
### - a. Using touch:
|
||||
The `touch` command is the simplest way to create an empty file.
|
||||
|
||||
```bash
|
||||
touch filename.txt
|
||||
```
|
||||
|
||||
This creates an empty file named "filename.txt" in the current directory.
|
||||
|
||||
### - b. Using redirection:
|
||||
You can use output redirection to create a file with content.
|
||||
|
||||
```bash
|
||||
echo "Hello, World!" > newfile.txt
|
||||
```
|
||||
|
||||
This creates a file named "newfile.txt" containing the text "Hello, World!".
|
||||
|
||||
### - c. Using text editors:
|
||||
You can create and edit files using text editors like nano, vim, or gedit.
|
||||
|
||||
```bash
|
||||
nano newfile.txt
|
||||
vim newfile.txt
|
||||
gedit newfile.txt
|
||||
```
|
||||
|
||||
These commands open the respective text editor with a new file named "newfile.txt".
|
||||
|
||||
## 2. Deleting Files
|
||||
|
||||
To delete files in Linux, you can use the `rm` (remove) command:
|
||||
|
||||
- a. Deleting a single file:
|
||||
```bash
|
||||
rm filename.txt
|
||||
```
|
||||
|
||||
- b. Deleting multiple files:
|
||||
```bash
|
||||
rm file1.txt file2.txt file3.txt
|
||||
```
|
||||
|
||||
- c. Deleting files with a specific pattern:
|
||||
```bash
|
||||
rm *.txt
|
||||
```
|
||||
This removes all files with the .txt extension in the current directory.
|
||||
|
||||
- d. Deleting files interactively (prompts for confirmation):
|
||||
```bash
|
||||
rm -i filename.txt
|
||||
```
|
||||
|
||||
- e. Deleting files forcefully (use with caution):
|
||||
```bash
|
||||
rm -f filename.txt
|
||||
```
|
||||
|
||||
Note: Be extremely careful when using `rm`, especially with wildcards or the `-f` option, as deleted files cannot be easily recovered.
|
||||
|
||||
## 3. Renaming Files
|
||||
|
||||
In Linux, renaming is done using the `mv` (move) command:
|
||||
|
||||
- a. Basic renaming:
|
||||
```bash
|
||||
mv oldname.txt newname.txt
|
||||
```
|
||||
|
||||
- b. Renaming multiple files using a pattern:
|
||||
To rename multiple files, you can use a loop in the shell. For example, to change the extension of all .txt files to .md:
|
||||
|
||||
```bash
|
||||
for file in *.txt; do
|
||||
mv "$file" "${file%.txt}.md"
|
||||
done
|
||||
```
|
||||
|
||||
- c. Renaming with a backup:
|
||||
```bash
|
||||
mv -b oldname.txt newname.txt
|
||||
```
|
||||
This creates a backup of the destination file if it already exists.
|
||||
|
||||
- d. Interactive renaming (prompts before overwriting):
|
||||
```bash
|
||||
mv -i oldname.txt newname.txt
|
||||
```
|
||||
|
||||
## Additional Tips:
|
||||
|
||||
- 1. Use tab completion to avoid typos in filenames.
|
||||
- 2. Use the `ls` command to list files and verify your actions.
|
||||
- 3. Be cautious when using wildcards (*) with `rm` or `mv`.
|
||||
- 4. For complex renaming tasks, consider using specialized tools like `rename` or `mmv`.
|
||||
- 5. Always double-check your commands, especially when deleting or renaming multiple files.
|
||||
- 6. Consider using version control systems like Git for important files and projects.
|
||||
|
||||
## Remember that in Linux, file operations are case-sensitive. "File.txt" and "file.txt" are treated as different files.
|
||||
@ -0,0 +1,32 @@
|
||||
## Certainly! Let's explore file management tasks in **Linux Mint**. Here are some essential commands:
|
||||
|
||||
1. **Creating a File**:
|
||||
- To create a new file, use the `touch` command followed by the desired filename:
|
||||
```
|
||||
touch sample.txt
|
||||
```
|
||||
|
||||
2. **Copying Files**:
|
||||
- The `cp` command copies a file. For example:
|
||||
```
|
||||
cp file.txt new-file.txt
|
||||
```
|
||||
|
||||
3. **Moving or Renaming Files**:
|
||||
- The `mv` command moves files from one location to another. It's also used for renaming files:
|
||||
```
|
||||
mv old-file.txt new-file.txt
|
||||
```
|
||||
|
||||
4. **Removing Files**:
|
||||
- To delete a file, use the `rm` command:
|
||||
```
|
||||
rm unwanted-file.txt
|
||||
```
|
||||
|
||||
Remember, these commands empower you to manage files efficiently! Feel free to ask if you need further assistance. 😊🚀
|
||||
|
||||
Source: Conversation with Copilot, 7/12/2024
|
||||
- [(1) How to create, copy, move, and remove files and directories in Linux.](https://www.thegeeksearch.com/how-to-create-copy-move-and-remove-files-and-directories-in-linux/.)
|
||||
- [(2) How to Create, Delete, & Rename a File in Linux - Hivelocity.](https://www.hivelocity.net/kb/how-to-create-delete-rename-a-file-in-linux/.)
|
||||
- [(3) Linux Mint - Community.](https://community.linuxmint.com/tutorial/view/1162.)
|
||||
138
06 - Linux File Operations/File Searching (find).md
Normal file
138
06 - Linux File Operations/File Searching (find).md
Normal file
@ -0,0 +1,138 @@
|
||||
# File Searching using find
|
||||
|
||||
##1. Basic Syntax:
|
||||
The basic syntax of the find command is:
|
||||
```
|
||||
find [path] [expression]
|
||||
```
|
||||
Where [path] is the directory you want to search in, and [expression] defines the search criteria.
|
||||
|
||||
## 2. Searching by Name:
|
||||
- To find files by name:
|
||||
```
|
||||
find /path/to/search -name "filename"
|
||||
```
|
||||
- Use wildcards for pattern matching:
|
||||
```
|
||||
find /path/to/search -name "*.txt"
|
||||
```
|
||||
- For case-insensitive search:
|
||||
```
|
||||
find /path/to/search -iname "filename"
|
||||
```
|
||||
|
||||
## 3. Searching by Type:
|
||||
- Find only directories:
|
||||
```
|
||||
find /path/to/search -type d
|
||||
```
|
||||
- Find only regular files:
|
||||
```
|
||||
find /path/to/search -type f
|
||||
```
|
||||
- Find symbolic links:
|
||||
```
|
||||
find /path/to/search -type l
|
||||
```
|
||||
|
||||
## 4. Searching by Size:
|
||||
- Find files larger than 100MB:
|
||||
```
|
||||
find /path/to/search -size +100M
|
||||
```
|
||||
- Find files smaller than 1KB:
|
||||
```
|
||||
find /path/to/search -size -1k
|
||||
```
|
||||
- Find files exactly 50 bytes:
|
||||
```
|
||||
find /path/to/search -size 50c
|
||||
```
|
||||
|
||||
## 5. Searching by Time:
|
||||
- Find files modified in the last 7 days:
|
||||
```
|
||||
find /path/to/search -mtime -7
|
||||
```
|
||||
- Find files accessed more than 30 days ago:
|
||||
```
|
||||
find /path/to/search -atime +30
|
||||
```
|
||||
- Find files whose status was changed within the last hour:
|
||||
```
|
||||
find /path/to/search -cmin -60
|
||||
```
|
||||
|
||||
## 6. Searching by Permissions:
|
||||
- Find files with exact permissions:
|
||||
```
|
||||
find /path/to/search -perm 644
|
||||
```
|
||||
- Find files with at least these permissions:
|
||||
```
|
||||
find /path/to/search -perm -644
|
||||
```
|
||||
|
||||
## 7. Logical Operators:
|
||||
- AND operation (implicit):
|
||||
```
|
||||
find /path/to/search -name "*.txt" -size +1M
|
||||
```
|
||||
- OR operation:
|
||||
```
|
||||
find /path/to/search \( -name "*.txt" -o -name "*.pdf" \)
|
||||
```
|
||||
- NOT operation:
|
||||
```
|
||||
find /path/to/search ! -name "*.txt"
|
||||
```
|
||||
|
||||
## 8. Actions:
|
||||
- Print results (default action):
|
||||
```
|
||||
find /path/to/search -name "*.txt" -print
|
||||
```
|
||||
- Execute a command on found files:
|
||||
```
|
||||
find /path/to/search -name "*.txt" -exec cat {} \;
|
||||
```
|
||||
- Delete found files (use with caution):
|
||||
```
|
||||
find /path/to/search -name "*.tmp" -delete
|
||||
```
|
||||
|
||||
## 9. Limiting Depth:
|
||||
- Search only in the current directory:
|
||||
```
|
||||
find /path/to/search -maxdepth 1 -name "*.txt"
|
||||
```
|
||||
- Limit search to 3 levels deep:
|
||||
```
|
||||
find /path/to/search -maxdepth 3 -name "*.txt"
|
||||
```
|
||||
|
||||
## 10. Performance Optimization:
|
||||
- Use '-xdev' to stay on one filesystem:
|
||||
```
|
||||
find /path/to/search -xdev -name "*.txt"
|
||||
```
|
||||
- Optimize for large directories:
|
||||
```
|
||||
find /path/to/search -name "*.txt" -fprintf /dev/stdout '%p\0' | xargs -0 process
|
||||
```
|
||||
|
||||
## 11. Advanced Examples:
|
||||
- Find all empty directories:
|
||||
```
|
||||
find /path/to/search -type d -empty
|
||||
```
|
||||
- Find all files owned by a specific user:
|
||||
```
|
||||
find /path/to/search -user username
|
||||
```
|
||||
- Find files and compress them:
|
||||
```
|
||||
find /path/to/search -name "*.log" -exec gzip {} +
|
||||
```
|
||||
|
||||
This guide covers most common use cases of the 'find' command. Remember that 'find' is very powerful and flexible, allowing you to combine these options in various ways to create complex search criteria.
|
||||
31
06 - Linux File Operations/File Searching.md
Normal file
31
06 - Linux File Operations/File Searching.md
Normal file
@ -0,0 +1,31 @@
|
||||
## Certainly! In **Linux Mint**, you can search for files and directories using various methods in the terminal. Let's explore a few options:
|
||||
|
||||
1. **Using `locate`**:
|
||||
- The `locate` command quickly searches for files and directories by their names. Here's the basic syntax:
|
||||
```
|
||||
locate {filename}
|
||||
```
|
||||
- For example, to locate a file named `resolv.conf`, you can run:
|
||||
```
|
||||
locate resolv.conf
|
||||
```
|
||||
|
||||
2. **Using `find`**:
|
||||
- The `find` command is more versatile and allows you to search based on various criteria.
|
||||
- Basic syntax for finding files:
|
||||
```
|
||||
find /path/to/search -type f -name file-to-search
|
||||
```
|
||||
- Replace `/path/to/search` with the directory where you want to search and `file-to-search` with the desired filename.
|
||||
|
||||
3. **Third-Party Tools**:
|
||||
- If you prefer graphical tools, consider using applications like **Nemo** (the default file manager in Cinnamon) or **Catfish** for file searches.
|
||||
|
||||
Feel free to choose the method that suits your workflow! 😊🚀
|
||||
|
||||
Source: Conversation with Copilot, 7/12/2024
|
||||
- [(1) How do I search files and folders on Linux Mint 18.1 Cinnamon?.](https://unix.stackexchange.com/questions/343172/how-do-i-search-files-and-folders-on-linux-mint-18-1-cinnamon.)
|
||||
- [(2) How to Search File Content in Linux Mint - Softhints.](https://softhints.com/how-to-search-file-content-in-linux-mint/.)
|
||||
- [(3) How to Find Files and Directories in Linux Mint 20 – LinuxWays.](https://linuxways.net/mint/how-to-find-files-and-directories-in-linux-mint-20/.)
|
||||
- [(4) How to Search for Files from the Linux Command Line - freeCodeCamp.org.](https://www.freecodecamp.org/news/how-to-search-for-files-from-the-linux-command-line/.)
|
||||
- [(5) undefined.](https://itsfoss.com/tiny-features-linux-mint-cinnamon/.)
|
||||
38
06 - Linux File Operations/IO Redirection and Piping.md
Normal file
38
06 - Linux File Operations/IO Redirection and Piping.md
Normal file
@ -0,0 +1,38 @@
|
||||
## Certainly! Let's dive into the concepts of **I/O redirection** and **piping** in **Linux Mint**:
|
||||
|
||||
1. **I/O Redirection**:
|
||||
- **Standard Input (stdin)**, **Standard Output (stdout)**, and **Standard Error (stderr)** are essential file descriptors for communication between programs and the outside world.
|
||||
- **stdin**: Default input source (usually keyboard input).
|
||||
- **stdout**: Default output destination (typically the terminal).
|
||||
- **stderr**: Alternative output for errors.
|
||||
- We can redirect these streams to/from files or other commands.
|
||||
|
||||
2. **Redirection Operators**:
|
||||
- `>`: Redirects stdout to a file (overwrites existing content).
|
||||
```
|
||||
ls > files
|
||||
```
|
||||
- `>>`: Appends stdout to a file.
|
||||
```
|
||||
ls -1 *.txt >> files
|
||||
```
|
||||
- `2>`: Redirects stderr to a file.
|
||||
```
|
||||
command_that_might_fail 2> error.log
|
||||
```
|
||||
|
||||
3. **Piping (`|`)**:
|
||||
- Connects the stdout of one command to the stdin of another.
|
||||
- Useful for chaining commands:
|
||||
```
|
||||
ls | grep "pattern"
|
||||
```
|
||||
|
||||
Remember, mastering I/O redirection and piping enhances your command-line skills! Feel free to explore further or ask more questions. 😊🚀¹²⁴
|
||||
|
||||
Source: Conversation with Copilot, 7/12/2024
|
||||
- [(1) Pipes and Redirection in Linux | Baeldung on Linux.](https://www.baeldung.com/linux/pipes-redirection.)
|
||||
- [(2) Basic Guide to Input Output (I/O) Redirection in Linux - OperaVPS.](https://bing.com/search?q=linuxmint+I%2fO+redirection+and+piping.)
|
||||
- [(3) Learn The Basics of How Linux I/O (Input/Output) Redirection ... - Tecmint.](https://www.tecmint.com/linux-io-input-output-redirection-operators/.)
|
||||
- [(4) Basic Guide to Input Output (I/O) Redirection in Linux - OperaVPS.](https://operavps.com/docs/input-output-redirection-in-linux/.)
|
||||
- [(5) 6.2 Using I/O Redirection and Piping.](https://www.oreilly.com/library/view/linux-fundamentals/9780135560396/LFUN_01_06_02.html.)
|
||||
100
06 - Linux File Operations/IO Redirection and PipingV2.md
Normal file
100
06 - Linux File Operations/IO Redirection and PipingV2.md
Normal file
@ -0,0 +1,100 @@
|
||||
# Linux I/O redirection and piping.
|
||||
|
||||
1. Basic Concepts
|
||||
2. Input Redirection
|
||||
3. Output Redirection
|
||||
4. Error Redirection
|
||||
5. Piping
|
||||
6. Advanced Techniques
|
||||
|
||||
## 1. Basic Concepts:
|
||||
|
||||
In Unix/Linux, there are three standard streams:
|
||||
- Standard Input (stdin): 0
|
||||
- Standard Output (stdout): 1
|
||||
- Standard Error (stderr): 2
|
||||
|
||||
By default, stdin is the keyboard, while stdout and stderr are both the terminal.
|
||||
|
||||
## 2. Input Redirection:
|
||||
|
||||
The < symbol is used for input redirection.
|
||||
|
||||
Example:
|
||||
```bash
|
||||
sort < file.txt
|
||||
```
|
||||
This command sorts the contents of file.txt.
|
||||
|
||||
## 3. Output Redirection:
|
||||
|
||||
The > symbol is used for output redirection. It creates a new file or overwrites an existing one.
|
||||
The >> symbol appends to an existing file or creates a new one if it doesn't exist.
|
||||
|
||||
Examples:
|
||||
```bash
|
||||
echo "Hello, World!" > greeting.txt
|
||||
echo "How are you?" >> greeting.txt
|
||||
```
|
||||
|
||||
## 4. Error Redirection:
|
||||
|
||||
You can redirect stderr using 2> or 2>>.
|
||||
|
||||
Example:
|
||||
```bash
|
||||
ls /nonexistent 2> error.log
|
||||
```
|
||||
|
||||
To redirect both stdout and stderr to the same file:
|
||||
```bash
|
||||
command > output.log 2>&1
|
||||
```
|
||||
|
||||
## 5. Piping:
|
||||
|
||||
The | symbol is used for piping. It sends the output of one command as input to another.
|
||||
|
||||
Example:
|
||||
```bash
|
||||
ls -l | grep "\.txt"
|
||||
```
|
||||
This lists all files and then filters for those ending in .txt.
|
||||
|
||||
## 6. Advanced Techniques:
|
||||
|
||||
- a) Here Documents:
|
||||
```bash
|
||||
cat << EOF > file.txt
|
||||
Line 1
|
||||
Line 2
|
||||
EOF
|
||||
```
|
||||
|
||||
- b) Process Substitution:
|
||||
```bash
|
||||
diff <(ls dir1) <(ls dir2)
|
||||
```
|
||||
|
||||
- c) Redirecting stdout and stderr to different files:
|
||||
```bash
|
||||
command 1> output.log 2> error.log
|
||||
```
|
||||
|
||||
- d) Discarding output:
|
||||
```bash
|
||||
command > /dev/null 2>&1
|
||||
```
|
||||
|
||||
- e) tee command (writing to both file and stdout):
|
||||
```bash
|
||||
echo "Hello" | tee file.txt
|
||||
```
|
||||
|
||||
- f) Named Pipes (FIFOs):
|
||||
```bash
|
||||
mkfifo mypipe
|
||||
command1 > mypipe & command2 < mypipe
|
||||
```
|
||||
|
||||
These techniques allow for powerful data manipulation and process control in the Linux environment. They're essential for scripting, data processing, and system administration tasks.
|
||||
@ -0,0 +1,150 @@
|
||||
# string searching using grep in Linux
|
||||
|
||||
## 1. Basic Usage:
|
||||
The fundamental syntax of grep is:
|
||||
```
|
||||
grep [options] pattern [file...]
|
||||
```
|
||||
|
||||
Example:
|
||||
```
|
||||
grep "error" logfile.txt
|
||||
```
|
||||
This searches for the word "error" in logfile.txt.
|
||||
|
||||
## 2. Case Sensitivity:
|
||||
- By default, grep is case-sensitive.
|
||||
- Use -i for case-insensitive search:
|
||||
```
|
||||
grep -i "error" logfile.txt
|
||||
```
|
||||
|
||||
## 3. Regular Expressions:
|
||||
grep supports regular expressions for powerful pattern matching.
|
||||
|
||||
- . (dot): Matches any single character
|
||||
- *: Matches zero or more of the preceding character
|
||||
- ^: Matches the start of a line
|
||||
- $: Matches the end of a line
|
||||
- []: Matches any single character in brackets
|
||||
|
||||
Example:
|
||||
```
|
||||
grep "^Error" logfile.txt # Lines starting with "Error"
|
||||
grep "failed$" logfile.txt # Lines ending with "failed"
|
||||
grep "t[ae]st" logfile.txt # Matches "test" or "tast"
|
||||
```
|
||||
|
||||
## 4. Extended Regular Expressions:
|
||||
Use -E option or egrep command for extended regex:
|
||||
```
|
||||
grep -E "Error|Warning" logfile.txt
|
||||
egrep "Error|Warning" logfile.txt
|
||||
```
|
||||
|
||||
## 5. Inverting the Match:
|
||||
-v option inverts the match, showing lines that don't match:
|
||||
```
|
||||
grep -v "success" logfile.txt
|
||||
```
|
||||
|
||||
## 6. Displaying Line Numbers:
|
||||
-n option shows line numbers:
|
||||
```
|
||||
grep -n "error" logfile.txt
|
||||
```
|
||||
|
||||
## 7. Counting Matches:
|
||||
-c option counts the number of matching lines:
|
||||
```
|
||||
grep -c "error" logfile.txt
|
||||
```
|
||||
|
||||
## 8. Showing Context:
|
||||
- -A n: Shows n lines after the match
|
||||
- -B n: Shows n lines before the match
|
||||
- -C n: Shows n lines before and after the match
|
||||
|
||||
Example:
|
||||
```
|
||||
grep -C 2 "critical error" logfile.txt
|
||||
```
|
||||
|
||||
## 9. Recursive Search:
|
||||
-r option searches recursively through directories:
|
||||
```
|
||||
grep -r "TODO" /path/to/project
|
||||
```
|
||||
|
||||
## 10. Matching Whole Words:
|
||||
-w option matches whole words only:
|
||||
```
|
||||
grep -w "log" logfile.txt
|
||||
```
|
||||
|
||||
## 11. Displaying Filename:
|
||||
- -H: Always print filename
|
||||
- -h: Never print filename
|
||||
```
|
||||
grep -H "error" *.log
|
||||
```
|
||||
|
||||
## 12. Quiet Mode:
|
||||
-q option suppresses output, useful in scripts:
|
||||
```
|
||||
if grep -q "error" logfile.txt; then
|
||||
echo "Errors found"
|
||||
fi
|
||||
```
|
||||
|
||||
## 13. Using grep with Pipes:
|
||||
grep works well with pipes for filtering output:
|
||||
```
|
||||
ps aux | grep "nginx"
|
||||
```
|
||||
|
||||
## 14. Multiple Patterns:
|
||||
Use -e option for multiple patterns:
|
||||
```
|
||||
grep -e "error" -e "warning" -e "critical" logfile.txt
|
||||
```
|
||||
|
||||
## 15. Reading Patterns from a File:
|
||||
-f option reads patterns from a file:
|
||||
```
|
||||
grep -f patterns.txt logfile.txt
|
||||
```
|
||||
|
||||
## 16. Binary Files:
|
||||
- -a: Process binary files as text
|
||||
- --binary-files=without-match: Assume binary files don't match
|
||||
|
||||
```
|
||||
grep -a "string" binary_file
|
||||
```
|
||||
|
||||
## 17. Colorizing Output:
|
||||
--color option highlights matches:
|
||||
```
|
||||
grep --color "error" logfile.txt
|
||||
```
|
||||
|
||||
## 18. Excluding Files:
|
||||
--exclude option excludes files from the search:
|
||||
```
|
||||
grep "TODO" --exclude="*.o" -r .
|
||||
```
|
||||
|
||||
## 19. Including Only Certain Files:
|
||||
--include option includes only specified files:
|
||||
```
|
||||
grep "function" --include="*.c" -r .
|
||||
```
|
||||
|
||||
## 20. Null-Separated Output:
|
||||
-Z option outputs a zero byte after filename:
|
||||
```
|
||||
grep -lZ "error" *.log | xargs -0 rm
|
||||
```
|
||||
|
||||
This guide covers many of grep's powerful features. Remember to consult the man pages (`man grep`) for more detailed information and additional options.
|
||||
183
07 - Shell Scripting Basics/Bash Loops.md
Normal file
183
07 - Shell Scripting Basics/Bash Loops.md
Normal file
@ -0,0 +1,183 @@
|
||||
# Loops in Bash
|
||||
|
||||
Loops are fundamental constructs in programming that allow you to execute a set of commands repeatedly. In Bash scripting, loops are essential for automating repetitive tasks, processing multiple files, and working with data structures. This tutorial will cover the three main types of loops in Bash: for loops, while loops, and until loops.
|
||||
|
||||
## 1. For Loops
|
||||
|
||||
The 'for' loop is used to iterate over a list of items or a range of values.
|
||||
|
||||
Syntax:
|
||||
```bash
|
||||
for variable in list
|
||||
do
|
||||
commands
|
||||
done
|
||||
```
|
||||
|
||||
Examples:
|
||||
|
||||
- Iterating over a list of items:
|
||||
```bash
|
||||
for fruit in apple banana orange
|
||||
do
|
||||
echo "I like $fruit"
|
||||
done
|
||||
```
|
||||
|
||||
- Iterating over a range of numbers:
|
||||
```bash
|
||||
for i in {1..5}
|
||||
do
|
||||
echo "Number: $i"
|
||||
done
|
||||
```
|
||||
|
||||
- C-style for loop:
|
||||
```bash
|
||||
for ((i=0; i<5; i++))
|
||||
do
|
||||
echo "Count: $i"
|
||||
done
|
||||
```
|
||||
|
||||
- Iterating over files in a directory:
|
||||
```bash
|
||||
for file in *.txt
|
||||
do
|
||||
echo "Processing $file"
|
||||
# Add commands to process each file
|
||||
done
|
||||
```
|
||||
|
||||
## 2. While Loops
|
||||
|
||||
The 'while' loop executes a set of commands as long as a given condition is true.
|
||||
|
||||
Syntax:
|
||||
```bash
|
||||
while condition
|
||||
do
|
||||
commands
|
||||
done
|
||||
```
|
||||
|
||||
Examples:
|
||||
|
||||
- Basic while loop:
|
||||
```bash
|
||||
count=1
|
||||
while [ $count -le 5 ]
|
||||
do
|
||||
echo "Count: $count"
|
||||
((count++))
|
||||
done
|
||||
```
|
||||
|
||||
- Reading input until a condition is met:
|
||||
```bash
|
||||
while read -p "Enter a number (0 to exit): " num
|
||||
do
|
||||
if [ "$num" -eq 0 ]; then
|
||||
echo "Exiting..."
|
||||
break
|
||||
fi
|
||||
echo "You entered: $num"
|
||||
done
|
||||
```
|
||||
|
||||
## 3. Until Loops
|
||||
|
||||
The 'until' loop is similar to the while loop, but it executes commands until a condition becomes true.
|
||||
|
||||
Syntax:
|
||||
```bash
|
||||
until condition
|
||||
do
|
||||
commands
|
||||
done
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
count=1
|
||||
until [ $count -gt 5 ]
|
||||
do
|
||||
echo "Count: $count"
|
||||
((count++))
|
||||
done
|
||||
```
|
||||
|
||||
## 4. Loop Control Statements
|
||||
|
||||
Bash provides two main loop control statements:
|
||||
|
||||
- break: Exits the loop immediately
|
||||
- continue: Skips the rest of the current iteration and moves to the next one
|
||||
|
||||
Example using both:
|
||||
```bash
|
||||
for i in {1..10}
|
||||
do
|
||||
if [ $i -eq 5 ]; then
|
||||
continue
|
||||
fi
|
||||
if [ $i -eq 8 ]; then
|
||||
break
|
||||
fi
|
||||
echo "Number: $i"
|
||||
done
|
||||
```
|
||||
|
||||
## 5. Advanced Loop Techniques
|
||||
|
||||
- Nested loops:
|
||||
```bash
|
||||
for i in {1..3}
|
||||
do
|
||||
for j in {1..3}
|
||||
do
|
||||
echo "i=$i, j=$j"
|
||||
done
|
||||
done
|
||||
```
|
||||
|
||||
- Looping through arrays:
|
||||
```bash
|
||||
declare -a fruits=("apple" "banana" "orange" "grape")
|
||||
for fruit in "${fruits[@]}"
|
||||
do
|
||||
echo "I like $fruit"
|
||||
done
|
||||
```
|
||||
|
||||
- Infinite loops (use with caution):
|
||||
```bash
|
||||
while true
|
||||
do
|
||||
echo "This will run forever unless interrupted"
|
||||
sleep 1
|
||||
done
|
||||
```
|
||||
|
||||
- Looping with command substitution:
|
||||
```bash
|
||||
for line in $(cat file.txt)
|
||||
do
|
||||
echo "Line: $line"
|
||||
done
|
||||
```
|
||||
|
||||
- Parallel execution of loops:
|
||||
```bash
|
||||
for job in job1 job2 job3
|
||||
do
|
||||
(
|
||||
echo "Starting $job"
|
||||
sleep 2
|
||||
echo "Finished $job"
|
||||
) &
|
||||
done
|
||||
wait
|
||||
echo "All jobs completed"
|
||||
```
|
||||
128
07 - Shell Scripting Basics/Bash Scripting Basics.md
Normal file
128
07 - Shell Scripting Basics/Bash Scripting Basics.md
Normal file
@ -0,0 +1,128 @@
|
||||
# Introduction to Bash Scripting
|
||||
|
||||
Bash (Bourne Again SHell) is a command-line interface and scripting language used in Unix and Unix-like operating systems, including Linux and macOS. Bash scripts are text files containing a series of commands that can be executed by the Bash shell.
|
||||
|
||||
## 1. Creating a Bash Script
|
||||
|
||||
To create a Bash script:
|
||||
|
||||
- Open a text editor
|
||||
- Start the file with a shebang: #!/bin/bash
|
||||
- Add your commands
|
||||
- Save the file with a .sh extension (e.g., myscript.sh)
|
||||
- Make the script executable: chmod +x myscript.sh
|
||||
|
||||
Here's a simple example:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
echo "Hello, World!"
|
||||
```
|
||||
|
||||
## 2. Variables
|
||||
|
||||
Variables in Bash are created by assigning a value:
|
||||
|
||||
```bash
|
||||
name="John"
|
||||
age=30
|
||||
echo "Name: $name, Age: $age"
|
||||
```
|
||||
|
||||
Use `$` to reference variables. For command substitution, use `$(command)`:
|
||||
|
||||
```bash
|
||||
current_date=$(date +%Y-%m-%d)
|
||||
echo "Today is $current_date"
|
||||
```
|
||||
|
||||
## 3. User Input
|
||||
|
||||
Use `read` to get user input:
|
||||
|
||||
```bash
|
||||
echo "What's your name?"
|
||||
read user_name
|
||||
echo "Hello, $user_name!"
|
||||
```
|
||||
|
||||
## 4. Conditional Statements
|
||||
|
||||
If-else statements:
|
||||
|
||||
```bash
|
||||
if [ "$age" -ge 18 ]; then
|
||||
echo "You are an adult"
|
||||
else
|
||||
echo "You are a minor"
|
||||
fi
|
||||
```
|
||||
|
||||
Note the spaces around the brackets and comparison operator.
|
||||
|
||||
## 5. Loops
|
||||
|
||||
For loop:
|
||||
|
||||
```bash
|
||||
for i in {1..5}
|
||||
do
|
||||
echo "Iteration $i"
|
||||
done
|
||||
```
|
||||
|
||||
While loop:
|
||||
|
||||
```bash
|
||||
counter=1
|
||||
while [ $counter -le 5 ]
|
||||
do
|
||||
echo "Counter: $counter"
|
||||
((counter++))
|
||||
done
|
||||
```
|
||||
|
||||
## 6. Functions
|
||||
|
||||
Define and call functions:
|
||||
|
||||
```bash
|
||||
greet() {
|
||||
echo "Hello, $1!"
|
||||
}
|
||||
|
||||
greet "Alice"
|
||||
greet "Bob"
|
||||
```
|
||||
|
||||
## 7. Command-line Arguments
|
||||
|
||||
Access command-line arguments using `$1`, `$2`, etc.:
|
||||
|
||||
```bash
|
||||
echo "Script name: $0"
|
||||
echo "First argument: $1"
|
||||
echo "Second argument: $2"
|
||||
echo "All arguments: $@"
|
||||
```
|
||||
|
||||
## 8. File Operations
|
||||
|
||||
Check if a file exists:
|
||||
|
||||
```bash
|
||||
if [ -f "myfile.txt" ]; then
|
||||
echo "myfile.txt exists"
|
||||
else
|
||||
echo "myfile.txt does not exist"
|
||||
fi
|
||||
```
|
||||
|
||||
Read from a file:
|
||||
|
||||
```bash
|
||||
while IFS= read -r line
|
||||
do
|
||||
echo "$line"
|
||||
done < "myfile.txt"
|
||||
```
|
||||
235
07 - Shell Scripting Basics/Conditional Statements.md
Normal file
235
07 - Shell Scripting Basics/Conditional Statements.md
Normal file
@ -0,0 +1,235 @@
|
||||
# Conditional Statements in Bash
|
||||
|
||||
Conditional statements in Bash allow you to control the flow of your script based on certain conditions. They enable your script to make decisions and execute different code blocks depending on whether specific conditions are true or false.
|
||||
|
||||
## 1. if statement
|
||||
|
||||
The most basic conditional statement is the 'if' statement. Its syntax is:
|
||||
|
||||
```bash
|
||||
if [ condition ]; then
|
||||
# commands to execute if condition is true
|
||||
fi
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
age=18
|
||||
|
||||
if [ $age -ge 18 ]; then
|
||||
echo "You are an adult."
|
||||
fi
|
||||
```
|
||||
|
||||
## 2. if-else statement
|
||||
|
||||
The if-else statement allows you to specify actions for both when the condition is true and when it's false:
|
||||
|
||||
```bash
|
||||
if [ condition ]; then
|
||||
# commands to execute if condition is true
|
||||
else
|
||||
# commands to execute if condition is false
|
||||
fi
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
age=16
|
||||
|
||||
if [ $age -ge 18 ]; then
|
||||
echo "You are an adult."
|
||||
else
|
||||
echo "You are a minor."
|
||||
fi
|
||||
```
|
||||
|
||||
## 3. if-elif-else statement
|
||||
|
||||
For multiple conditions, use the if-elif-else structure:
|
||||
|
||||
```bash
|
||||
if [ condition1 ]; then
|
||||
# commands for condition1
|
||||
elif [ condition2 ]; then
|
||||
# commands for condition2
|
||||
elif [ condition3 ]; then
|
||||
# commands for condition3
|
||||
else
|
||||
# commands if none of the conditions are true
|
||||
fi
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
grade=75
|
||||
|
||||
if [ $grade -ge 90 ]; then
|
||||
echo "A"
|
||||
elif [ $grade -ge 80 ]; then
|
||||
echo "B"
|
||||
elif [ $grade -ge 70 ]; then
|
||||
echo "C"
|
||||
elif [ $grade -ge 60 ]; then
|
||||
echo "D"
|
||||
else
|
||||
echo "F"
|
||||
fi
|
||||
```
|
||||
|
||||
## 4. Comparison operators
|
||||
|
||||
Bash uses different operators for string and numeric comparisons:
|
||||
|
||||
Numeric comparisons:
|
||||
- -eq: equal to
|
||||
- -ne: not equal to
|
||||
- -lt: less than
|
||||
- -le: less than or equal to
|
||||
- -gt: greater than
|
||||
- -ge: greater than or equal to
|
||||
|
||||
String comparisons:
|
||||
- =: equal to
|
||||
- !=: not equal to
|
||||
- <: less than (in ASCII alphabetical order)
|
||||
- >: greater than (in ASCII alphabetical order)
|
||||
- -z: string is null (zero length)
|
||||
- -n: string is not null
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
num1=10
|
||||
num2=20
|
||||
str1="hello"
|
||||
str2="world"
|
||||
|
||||
if [ $num1 -lt $num2 ]; then
|
||||
echo "$num1 is less than $num2"
|
||||
fi
|
||||
|
||||
if [ $str1 != $str2 ]; then
|
||||
echo "$str1 is not equal to $str2"
|
||||
fi
|
||||
```
|
||||
|
||||
## 5. Logical operators
|
||||
|
||||
Bash supports logical AND and OR operations:
|
||||
|
||||
- &&: AND
|
||||
- ||: OR
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
age=25
|
||||
has_license=true
|
||||
|
||||
if [ $age -ge 18 ] && [ "$has_license" = true ]; then
|
||||
echo "You can drive a car."
|
||||
fi
|
||||
|
||||
if [ $age -lt 18 ] || [ "$has_license" != true ]; then
|
||||
echo "You cannot drive a car."
|
||||
fi
|
||||
```
|
||||
|
||||
## 6. Case statement
|
||||
|
||||
The case statement is useful when you have multiple conditions based on a single variable:
|
||||
|
||||
```bash
|
||||
case $variable in
|
||||
pattern1)
|
||||
# commands for pattern1
|
||||
;;
|
||||
pattern2)
|
||||
# commands for pattern2
|
||||
;;
|
||||
*)
|
||||
# default case
|
||||
;;
|
||||
esac
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
fruit="apple"
|
||||
|
||||
case $fruit in
|
||||
"apple")
|
||||
echo "This is a red fruit."
|
||||
;;
|
||||
"banana")
|
||||
echo "This is a yellow fruit."
|
||||
;;
|
||||
"grape")
|
||||
echo "This is a purple fruit."
|
||||
;;
|
||||
*)
|
||||
echo "Unknown fruit."
|
||||
;;
|
||||
esac
|
||||
```
|
||||
|
||||
## 7. Test command
|
||||
|
||||
The test command is often used in conditional statements. It's equivalent to using square brackets []. You can use it like this:
|
||||
|
||||
```bash
|
||||
if test $a -eq $b; then
|
||||
echo "a is equal to b"
|
||||
fi
|
||||
```
|
||||
|
||||
This is the same as:
|
||||
|
||||
```bash
|
||||
if [ $a -eq $b ]; then
|
||||
echo "a is equal to b"
|
||||
fi
|
||||
```
|
||||
|
||||
## 8. Double square brackets
|
||||
|
||||
Bash also supports double square brackets [[ ]] for conditional tests. These provide more features than single brackets, such as pattern matching:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
string="Hello, World!"
|
||||
|
||||
if [[ $string == Hello* ]]; then
|
||||
echo "String starts with 'Hello'"
|
||||
fi
|
||||
```
|
||||
|
||||
Double brackets also allow you to use && and || inside the condition:
|
||||
|
||||
```bash
|
||||
if [[ $a -eq 5 && $b -gt 10 ]]; then
|
||||
echo "Condition met"
|
||||
fi
|
||||
```
|
||||
|
||||
## Conclusion
|
||||
|
||||
Conditional statements are crucial for creating dynamic and responsive Bash scripts. They allow your scripts to make decisions based on various conditions, making your scripts more versatile and powerful. Practice using these constructs to become proficient in Bash scripting.
|
||||
206
07 - Shell Scripting Basics/Functions in Bash.md
Normal file
206
07 - Shell Scripting Basics/Functions in Bash.md
Normal file
@ -0,0 +1,206 @@
|
||||
# Functions in Bash: A Comprehensive Guide
|
||||
|
||||
## 1. Introduction to Bash Functions
|
||||
|
||||
Bash functions are reusable pieces of code that perform a specific task. They help in organizing code, improving readability, and reducing repetition. Functions in Bash are similar to functions in other programming languages but with some unique characteristics.
|
||||
|
||||
## 2. Basic Syntax
|
||||
|
||||
The basic syntax for defining a function in Bash is:
|
||||
|
||||
```bash
|
||||
function_name() {
|
||||
# Function body
|
||||
# Commands go here
|
||||
}
|
||||
```
|
||||
|
||||
Alternatively, you can use the `function` keyword:
|
||||
|
||||
```bash
|
||||
function function_name {
|
||||
# Function body
|
||||
# Commands go here
|
||||
}
|
||||
```
|
||||
|
||||
## 3. Calling Functions
|
||||
|
||||
To call a function, simply use its name:
|
||||
|
||||
```bash
|
||||
function_name
|
||||
```
|
||||
|
||||
## 4. Function Parameters
|
||||
|
||||
Bash functions can accept parameters, which are accessed using special variables:
|
||||
|
||||
- `$1`, `$2`, `$3`, etc.: Positional parameters
|
||||
- `$@`: All parameters as separate quoted strings
|
||||
- `$*`: All parameters as a single quoted string
|
||||
- `$#`: Number of parameters
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
greet() {
|
||||
echo "Hello, $1! Nice to meet you."
|
||||
}
|
||||
|
||||
greet "Alice" # Output: Hello, Alice! Nice to meet you.
|
||||
```
|
||||
|
||||
## 5. Return Values
|
||||
|
||||
Bash functions don't return values in the traditional sense. Instead, they use exit status:
|
||||
|
||||
```bash
|
||||
is_even() {
|
||||
if (( $1 % 2 == 0 )); then
|
||||
return 0 # Success (true)
|
||||
else
|
||||
return 1 # Failure (false)
|
||||
fi
|
||||
}
|
||||
|
||||
is_even 4
|
||||
echo $? # Output: 0 (success)
|
||||
|
||||
is_even 5
|
||||
echo $? # Output: 1 (failure)
|
||||
```
|
||||
|
||||
## 6. Capturing Function Output
|
||||
|
||||
To capture a function's output, use command substitution:
|
||||
|
||||
```bash
|
||||
get_date() {
|
||||
echo $(date +"%Y-%m-%d")
|
||||
}
|
||||
|
||||
today=$(get_date)
|
||||
echo "Today is $today"
|
||||
```
|
||||
|
||||
## 7. Local Variables
|
||||
|
||||
Use the `local` keyword to declare variables that are only accessible within the function:
|
||||
|
||||
```bash
|
||||
my_function() {
|
||||
local my_var="Hello, local variable!"
|
||||
echo $my_var
|
||||
}
|
||||
|
||||
my_function # Output: Hello, local variable!
|
||||
echo $my_var # Output: (empty, as my_var is not accessible here)
|
||||
```
|
||||
|
||||
## 8. Function Scope
|
||||
|
||||
Functions in Bash have access to global variables, but it's generally better to pass values as parameters:
|
||||
|
||||
```bash
|
||||
global_var="I'm global"
|
||||
|
||||
my_function() {
|
||||
echo "Inside function: $global_var"
|
||||
local local_var="I'm local"
|
||||
echo "Local variable: $local_var"
|
||||
}
|
||||
|
||||
my_function
|
||||
echo "Outside function: $global_var"
|
||||
echo "Trying to access local_var: $local_var" # This will be empty
|
||||
```
|
||||
|
||||
## 9. Function Libraries
|
||||
|
||||
You can create function libraries by putting related functions in a separate file and sourcing it:
|
||||
|
||||
```bash
|
||||
# In file: my_functions.sh
|
||||
greet() {
|
||||
echo "Hello, $1!"
|
||||
}
|
||||
|
||||
farewell() {
|
||||
echo "Goodbye, $1!"
|
||||
}
|
||||
|
||||
# In your main script
|
||||
source my_functions.sh
|
||||
|
||||
greet "Alice"
|
||||
farewell "Bob"
|
||||
```
|
||||
|
||||
## 10. Advanced Techniques
|
||||
|
||||
a. Default Parameters:
|
||||
```bash
|
||||
greet() {
|
||||
local name=${1:-"Guest"}
|
||||
echo "Hello, $name!"
|
||||
}
|
||||
|
||||
greet # Output: Hello, Guest!
|
||||
greet "Alice" # Output: Hello, Alice!
|
||||
```
|
||||
|
||||
b. Variable Number of Arguments:
|
||||
```bash
|
||||
sum() {
|
||||
local result=0
|
||||
for num in "$@"; do
|
||||
((result += num))
|
||||
done
|
||||
echo $result
|
||||
}
|
||||
|
||||
sum 1 2 3 4 5 # Output: 15
|
||||
```
|
||||
|
||||
c. Recursive Functions:
|
||||
```bash
|
||||
factorial() {
|
||||
if (( $1 <= 1 )); then
|
||||
echo 1
|
||||
else
|
||||
local prev=$(factorial $(($1 - 1)))
|
||||
echo $(($1 * prev))
|
||||
fi
|
||||
}
|
||||
|
||||
factorial 5 # Output: 120
|
||||
```
|
||||
|
||||
## 11. Best Practices
|
||||
|
||||
- Use descriptive function names
|
||||
- Comment your functions, especially for complex operations
|
||||
- Keep functions focused on a single task
|
||||
- Use local variables to avoid naming conflicts
|
||||
- Pass data to functions as parameters rather than relying on global variables
|
||||
- Use `set -e` at the beginning of your script to exit on any error, including within functions
|
||||
|
||||
## 12. Debugging Functions
|
||||
|
||||
Use the `set -x` command to enable debugging mode, which prints each command before executing it:
|
||||
|
||||
```bash
|
||||
set -x # Enable debugging
|
||||
my_function() {
|
||||
echo "Doing something"
|
||||
local result=$((2 + 2))
|
||||
echo "Result: $result"
|
||||
}
|
||||
my_function
|
||||
set +x # Disable debugging
|
||||
```
|
||||
|
||||
## Conclusion
|
||||
|
||||
Bash functions are powerful tools for creating modular, reusable code. They can significantly improve the organization and maintainability of your shell scripts. By mastering functions, you'll be able to write more efficient and elegant Bash scripts.
|
||||
162
07 - Shell Scripting Basics/Script Debugging Techniques.md
Normal file
162
07 - Shell Scripting Basics/Script Debugging Techniques.md
Normal file
@ -0,0 +1,162 @@
|
||||
# Script Debugging Techniques
|
||||
|
||||
## 1. Enable debugging mode
|
||||
|
||||
The first step in debugging a bash script is to enable debugging mode. You can do this in two ways:
|
||||
|
||||
- Add the -x option when running the script:
|
||||
|
||||
```bash
|
||||
bash -x your_script.sh
|
||||
```
|
||||
|
||||
- Add the set -x command at the beginning of your script:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
set -x
|
||||
|
||||
# Rest of your script
|
||||
```
|
||||
|
||||
The -x option enables trace debugging, which prints each command and its arguments as they are executed.
|
||||
|
||||
## 2. Use set options for additional debugging
|
||||
|
||||
Bash provides several set options that can help with debugging:
|
||||
|
||||
- set -e: Exit immediately if a command exits with a non-zero status.
|
||||
- set -u: Treat unset variables as an error when substituting.
|
||||
- set -o pipefail: The return value of a pipeline is the status of the last command to exit with a non-zero status.
|
||||
|
||||
You can combine these options:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
set -x
|
||||
|
||||
# Rest of your script
|
||||
```
|
||||
|
||||
## 3. Add echo statements
|
||||
|
||||
Insert echo statements throughout your script to print variable values or to indicate which part of the script is being executed:
|
||||
|
||||
```bash
|
||||
echo "Debug: Variable value is $variable"
|
||||
echo "Debug: Entering function foo"
|
||||
```
|
||||
|
||||
## 4. Use bash's built-in debugging commands
|
||||
|
||||
Bash provides several built-in commands for debugging:
|
||||
|
||||
- set -v: Prints shell input lines as they are read.
|
||||
- trap: Can be used to debug functions or specific parts of your script.
|
||||
|
||||
Example of using trap:
|
||||
|
||||
```bash
|
||||
trap 'echo "Line $LINENO: Command \\"$BASH_COMMAND\\" exited with status $?"' ERR
|
||||
```
|
||||
|
||||
## 5. Use a debugger
|
||||
|
||||
For more complex scripts, you might want to use a debugger. Bashdb is a popular bash script debugger. Here's how to use it:
|
||||
|
||||
a) Install bashdb (on Ubuntu/Debian):
|
||||
|
||||
```
|
||||
sudo apt-get install bashdb
|
||||
```
|
||||
|
||||
b) Run your script with bashdb:
|
||||
|
||||
```
|
||||
bashdb your_script.sh
|
||||
```
|
||||
|
||||
This will start an interactive debugging session where you can set breakpoints, step through the code, and inspect variables.
|
||||
|
||||
## 6. Check for syntax errors
|
||||
|
||||
Before diving into debugging, check for syntax errors:
|
||||
|
||||
```bash
|
||||
bash -n your_script.sh
|
||||
```
|
||||
|
||||
This will check for syntax errors without executing the script.
|
||||
|
||||
## 7. Use shellcheck
|
||||
|
||||
Shellcheck is a static analysis tool for shell scripts. It can catch common errors and suggest improvements:
|
||||
|
||||
a) Install shellcheck (on Ubuntu/Debian):
|
||||
|
||||
```
|
||||
sudo apt-get install shellcheck
|
||||
```
|
||||
|
||||
b) Run shellcheck on your script:
|
||||
|
||||
```
|
||||
shellcheck your_script.sh
|
||||
```
|
||||
|
||||
## 8. Debug specific sections
|
||||
|
||||
If you only want to debug a specific section of your script, you can use set -x and set +x to turn debugging on and off:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
# Normal execution
|
||||
echo "This part is not debugged"
|
||||
|
||||
# Start debugging
|
||||
set -x
|
||||
echo "This part is debugged"
|
||||
# Stop debugging
|
||||
set +x
|
||||
|
||||
echo "Back to normal execution"
|
||||
```
|
||||
|
||||
## 9. Use PS4 for more informative debug output
|
||||
|
||||
You can customize the prefix used for debug output using the PS4 variable:
|
||||
|
||||
```bash
|
||||
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
|
||||
set -x
|
||||
|
||||
# Your script here
|
||||
```
|
||||
|
||||
This will prefix each debug line with the source file, line number, and function name.
|
||||
|
||||
## 10. Check exit status
|
||||
|
||||
After each important command, check its exit status:
|
||||
|
||||
```bash
|
||||
important_command
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: important_command failed"
|
||||
exit 1
|
||||
fi
|
||||
```
|
||||
|
||||
## 11. Use bash's DEBUG trap
|
||||
|
||||
You can use the DEBUG trap to execute a command before each command in your script:
|
||||
|
||||
```bash
|
||||
trap 'echo "About to execute: $BASH_COMMAND"' DEBUG
|
||||
```
|
||||
|
||||
This will print each command before it's executed.
|
||||
|
||||
By combining these techniques, you can effectively debug your bash scripts and identify issues more quickly. Remember to remove or comment out debugging code before using the script in production.
|
||||
205
07 - Shell Scripting Basics/User Iput and Arguments in Bash.md
Normal file
205
07 - Shell Scripting Basics/User Iput and Arguments in Bash.md
Normal file
@ -0,0 +1,205 @@
|
||||
# User Input and Arguments in Bash
|
||||
|
||||
## 1. Command-line Arguments
|
||||
|
||||
Bash scripts can accept arguments when executed from the command line. These arguments are accessible within the script using special variables.
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
echo "The script name is: $0"
|
||||
echo "The first argument is: $1"
|
||||
echo "The second argument is: $2"
|
||||
echo "All arguments: $@"
|
||||
```
|
||||
|
||||
Usage:
|
||||
```
|
||||
./script.sh arg1 arg2 arg3
|
||||
```
|
||||
|
||||
## 2. The `read` Command
|
||||
|
||||
The `read` command allows interactive user input during script execution.
|
||||
|
||||
Basic syntax:
|
||||
```bash
|
||||
read variable_name
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
echo "What's your name?"
|
||||
read name
|
||||
echo "Hello, $name!"
|
||||
|
||||
# Reading multiple variables
|
||||
echo "Enter your first and last name:"
|
||||
read first_name last_name
|
||||
echo "Your full name is $first_name $last_name"
|
||||
|
||||
# Using a prompt
|
||||
read -p "Enter your age: " age
|
||||
echo "You are $age years old"
|
||||
|
||||
# Reading with a timeout
|
||||
read -t 5 -p "Quick! Enter a number: " number
|
||||
echo "You entered: $number"
|
||||
```
|
||||
|
||||
## 3. Special Variables for Arguments
|
||||
|
||||
Bash provides special variables for working with command-line arguments:
|
||||
|
||||
- `$0`: Script name
|
||||
- `$1`, `$2`, `$3`, etc.: Individual arguments
|
||||
- `$#`: Number of arguments
|
||||
- `$@`: All arguments as separate words
|
||||
- `$*`: All arguments as a single word
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
echo "Number of arguments: $#"
|
||||
echo "All arguments: $@"
|
||||
|
||||
# Loop through all arguments
|
||||
for arg in "$@"
|
||||
do
|
||||
echo "Argument: $arg"
|
||||
done
|
||||
```
|
||||
|
||||
## 4. Handling Options and Flags
|
||||
|
||||
You can create scripts that accept options (flags) to modify behavior.
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
verbose=false
|
||||
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
key="$1"
|
||||
case $key in
|
||||
-v|--verbose)
|
||||
verbose=true
|
||||
shift
|
||||
;;
|
||||
-n|--name)
|
||||
name="$2"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$verbose" = true ] ; then
|
||||
echo "Verbose mode on"
|
||||
fi
|
||||
|
||||
if [ ! -z "$name" ] ; then
|
||||
echo "Hello, $name!"
|
||||
fi
|
||||
```
|
||||
|
||||
Usage:
|
||||
```
|
||||
./script.sh -v --name John
|
||||
```
|
||||
|
||||
## 5. Validating Input
|
||||
|
||||
It's important to validate user input to ensure your script behaves correctly.
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
read -p "Enter a number between 1 and 10: " number
|
||||
|
||||
if [[ ! $number =~ ^[0-9]+$ ]] ; then
|
||||
echo "Error: Not a number"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if (( number < 1 || number > 10 )) ; then
|
||||
echo "Error: Number out of range"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "You entered a valid number: $number"
|
||||
```
|
||||
|
||||
## 6. Using `getopts` for Advanced Option Parsing
|
||||
|
||||
For more complex option parsing, Bash provides the `getopts` built-in command.
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 [-h] [-v] [-n name]"
|
||||
echo " -h: Display this help message"
|
||||
echo " -v: Enable verbose mode"
|
||||
echo " -n name: Specify a name"
|
||||
}
|
||||
|
||||
verbose=false
|
||||
name=""
|
||||
|
||||
while getopts ":hvn:" opt; do
|
||||
case ${opt} in
|
||||
h )
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
v )
|
||||
verbose=true
|
||||
;;
|
||||
n )
|
||||
name=$OPTARG
|
||||
;;
|
||||
\? )
|
||||
echo "Invalid option: $OPTARG" 1>&2
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
: )
|
||||
echo "Invalid option: $OPTARG requires an argument" 1>&2
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$verbose" = true ] ; then
|
||||
echo "Verbose mode enabled"
|
||||
fi
|
||||
|
||||
if [ ! -z "$name" ] ; then
|
||||
echo "Hello, $name!"
|
||||
fi
|
||||
```
|
||||
|
||||
Usage:
|
||||
```
|
||||
./script.sh -v -n Alice
|
||||
```
|
||||
@ -0,0 +1,147 @@
|
||||
# Advanced Package Management with apt
|
||||
|
||||
## 1. Understanding apt
|
||||
|
||||
APT (Advanced Package Tool) is a powerful package management system used in Debian, Ubuntu, and other Debian-based Linux distributions. It simplifies the process of installing, upgrading, configuring, and removing software packages.
|
||||
|
||||
## 2. Key components
|
||||
|
||||
- apt: The command-line tool for package management
|
||||
- apt-get: The older command-line tool (still widely used)
|
||||
- apt-cache: Used for querying package information
|
||||
- /etc/apt/sources.list: The main configuration file for package repositories
|
||||
|
||||
## 3. Basic apt commands
|
||||
|
||||
- Update package lists: `sudo apt update`
|
||||
- Upgrade installed packages: `sudo apt upgrade`
|
||||
- Install a package: `sudo apt install package_name`
|
||||
- Remove a package: `sudo apt remove package_name`
|
||||
- Search for a package: `apt search keyword`
|
||||
- Show package information: `apt show package_name`
|
||||
|
||||
## 4. Advanced apt commands
|
||||
|
||||
### a. Install specific version:
|
||||
```
|
||||
sudo apt install package_name=version_number
|
||||
```
|
||||
|
||||
### b. Downgrade a package:
|
||||
```
|
||||
sudo apt install package_name=older_version_number
|
||||
```
|
||||
|
||||
### c. Hold a package at its current version:
|
||||
```
|
||||
sudo apt-mark hold package_name
|
||||
```
|
||||
|
||||
### d. Remove a package and its configuration files:
|
||||
```
|
||||
sudo apt purge package_name
|
||||
```
|
||||
|
||||
### e. Remove unused dependencies:
|
||||
```
|
||||
sudo apt autoremove
|
||||
```
|
||||
|
||||
### f. Clean up the local repository:
|
||||
```
|
||||
sudo apt clean
|
||||
```
|
||||
|
||||
### g. Download a package without installing:
|
||||
```
|
||||
sudo apt download package_name
|
||||
```
|
||||
|
||||
## 5. Working with repositories
|
||||
|
||||
### a. Add a repository:
|
||||
```
|
||||
sudo add-apt-repository ppa:user/ppa-name
|
||||
```
|
||||
|
||||
### b. Remove a repository:
|
||||
```
|
||||
sudo add-apt-repository --remove ppa:user/ppa-name
|
||||
```
|
||||
|
||||
### c. Update package lists after adding/removing repositories:
|
||||
```
|
||||
sudo apt update
|
||||
```
|
||||
|
||||
## 6. Managing package priorities
|
||||
|
||||
APT uses priorities to determine which version of a package to install when multiple versions are available. You can modify priorities using the `/etc/apt/preferences` file.
|
||||
|
||||
Example:
|
||||
```
|
||||
Package: firefox
|
||||
Pin: release o=Ubuntu
|
||||
Pin-Priority: 1001
|
||||
```
|
||||
|
||||
This gives Firefox from the Ubuntu repositories a higher priority than other sources.
|
||||
|
||||
## 7. Apt configuration
|
||||
|
||||
The main configuration file is `/etc/apt/apt.conf`. You can create custom configuration files in `/etc/apt/apt.conf.d/`.
|
||||
|
||||
Example configuration options:
|
||||
```
|
||||
APT::Get::Show-Versions "true";
|
||||
APT::Get::Show-Upgraded "true";
|
||||
```
|
||||
|
||||
## 8. Troubleshooting
|
||||
|
||||
### a. Fix broken dependencies:
|
||||
```
|
||||
sudo apt --fix-broken install
|
||||
```
|
||||
|
||||
### b. Reconfigure a package:
|
||||
```
|
||||
sudo dpkg-reconfigure package_name
|
||||
```
|
||||
|
||||
### c. Verify package integrity:
|
||||
```
|
||||
sudo apt-get check
|
||||
```
|
||||
|
||||
## 9. Advanced features
|
||||
|
||||
### a. Simulate installations:
|
||||
```
|
||||
sudo apt install -s package_name
|
||||
```
|
||||
|
||||
### b. Download source code:
|
||||
```
|
||||
sudo apt source package_name
|
||||
```
|
||||
|
||||
### c. Build a package from source:
|
||||
```
|
||||
sudo apt build-dep package_name
|
||||
sudo apt source --compile package_name
|
||||
```
|
||||
|
||||
### d. Create a package download script:
|
||||
```
|
||||
sudo apt-get --print-uris --yes install package_name > download_script.sh
|
||||
```
|
||||
|
||||
## 10. Best practices
|
||||
|
||||
- Regularly update and upgrade your system
|
||||
- Use `apt` instead of `apt-get` for interactive use
|
||||
- Be cautious when adding third-party repositories
|
||||
- Always verify package names and versions before installation
|
||||
- Use `apt-mark` to manage package states (hold, unhold, etc.)
|
||||
- Regularly clean up unused packages and local repository cache
|
||||
@ -0,0 +1,76 @@
|
||||
# Advanced Package Management (YUM)
|
||||
|
||||
## 1. Understanding YUM:
|
||||
YUM is a package manager used in Red Hat-based Linux distributions like CentOS, Fedora, and RHEL. It simplifies the process of installing, updating, and removing software packages.
|
||||
|
||||
## 2. Basic YUM commands:
|
||||
- Install a package: `yum install package_name`
|
||||
- Remove a package: `yum remove package_name`
|
||||
- Update all packages: `yum update`
|
||||
- Search for a package: `yum search keyword`
|
||||
- Get information about a package: `yum info package_name`
|
||||
|
||||
## 3. Working with repositories:
|
||||
- List configured repositories: `yum repolist`
|
||||
- Add a repository:
|
||||
Create a .repo file in /etc/yum.repos.d/ with the following structure:
|
||||
```
|
||||
[repo-name]
|
||||
name=Repository Name
|
||||
baseurl=http://repo.url
|
||||
enabled=1
|
||||
gpgcheck=1
|
||||
gpgkey=http://repo.url/RPM-GPG-KEY
|
||||
```
|
||||
- Enable/disable a repository: `yum-config-manager --enable/--disable repo-name`
|
||||
|
||||
## 4. Advanced package operations:
|
||||
- Install a specific version: `yum install package_name-version`
|
||||
- Downgrade a package: `yum downgrade package_name`
|
||||
- Reinstall a package: `yum reinstall package_name`
|
||||
- List dependencies: `yum deplist package_name`
|
||||
- Install only dependencies: `yum depinstall package_name`
|
||||
|
||||
## 5. Group operations:
|
||||
- List available groups: `yum grouplist`
|
||||
- Install a group: `yum groupinstall "Group Name"`
|
||||
- Remove a group: `yum groupremove "Group Name"`
|
||||
- Update a group: `yum groupupdate "Group Name"`
|
||||
|
||||
## 6. History and rollback:
|
||||
- View transaction history: `yum history`
|
||||
- Undo a transaction: `yum history undo transaction_id`
|
||||
- Redo a transaction: `yum history redo transaction_id`
|
||||
|
||||
## 7. Cleanup operations:
|
||||
- Clean all caches: `yum clean all`
|
||||
- Remove orphaned packages: `yum autoremove`
|
||||
|
||||
## 8. Using YUM plugins:
|
||||
- List installed plugins: `yum list installed | grep yum-plugin`
|
||||
- Install a plugin: `yum install yum-plugin-name`
|
||||
- Enable/disable a plugin: Edit /etc/yum/pluginconf.d/plugin-name.conf
|
||||
|
||||
## 9. Creating and using local repositories:
|
||||
- Install createrepo: `yum install createrepo`
|
||||
- Create a repository: `createrepo /path/to/repo`
|
||||
- Add the local repo to YUM: Create a .repo file in /etc/yum.repos.d/
|
||||
|
||||
## 10. YUM variables and configuration:
|
||||
- View YUM variables: `yum variables`
|
||||
- Set variables: Edit /etc/yum/vars/ or use `--setopt` in commands
|
||||
- Configure YUM behavior: Edit /etc/yum.conf
|
||||
|
||||
## 11. Using alternative package managers:
|
||||
- DNF (Dandified YUM): A next-generation replacement for YUM
|
||||
- Use `dnf` instead of `yum` in commands for newer distributions
|
||||
|
||||
## 12. Security considerations:
|
||||
- Always use gpgcheck=1 in repository configurations
|
||||
- Regularly update the system with `yum update`
|
||||
- Use `yum update --security` for security updates only
|
||||
|
||||
## 13. Troubleshooting:
|
||||
- Check YUM logs: /var/log/yum.log
|
||||
- Debug YUM operations: Add `-v` or `--verbose` to commands
|
||||
- Resolve dependency issues: Use `yum depsolve` or `yum check`
|
||||
@ -0,0 +1,27 @@
|
||||
## In **Linux Mint**, package management is essential for installing, updating, and managing software. Let's explore some key tools and concepts:
|
||||
|
||||
1. **APT (Advanced Packaging Tool)**:
|
||||
- APT is the primary package manager for Debian-based systems, including Linux Mint.
|
||||
- It handles software installation, removal, querying, and upgrades.
|
||||
- Common APT commands:
|
||||
- `sudo apt update`: Refreshes package lists from repositories.
|
||||
- `sudo apt install package-name`: Installs a package.
|
||||
- `sudo apt remove package-name`: Removes a package.
|
||||
- `sudo apt upgrade`: Upgrades installed packages.
|
||||
- `sudo apt search keyword`: Searches for packages.
|
||||
- APT uses `.deb` packages and works alongside `dpkg`, which installs individual `.deb` files.
|
||||
|
||||
2. **Synaptic Package Manager**:
|
||||
- Synaptic is an advanced graphical package management tool.
|
||||
- To install Synaptic:
|
||||
```
|
||||
sudo apt install synaptic
|
||||
```
|
||||
- Launch it from the Applications menu or by typing `synaptic` in the terminal.
|
||||
|
||||
Remember, APT and Synaptic empower you to manage software efficiently in Linux Mint! 😊🚀 ²³
|
||||
|
||||
Source: Conversation with Copilot, 7/12/2024
|
||||
- [(1) How to Install and Update Apps on Linux Mint - UMA Technology.](https://umatechnology.org/how-to-install-and-update-apps-on-linux-mint/.)
|
||||
- [(2) How to Use APT Command in Linux [15 Useful Examples] - UbuntuMint.](https://www.ubuntumint.com/apt-commands/.)
|
||||
- [(3) Package Management Essentials: apt, yum, dnf, pkg.](https://www.digitalocean.com/community/tutorials/package-management-basics-apt-yum-dnf-pkg.)
|
||||
@ -0,0 +1,136 @@
|
||||
# Cron Jobs and Task Scheduling
|
||||
|
||||
## 1. Introduction to Cron
|
||||
|
||||
Cron is a time-based job scheduler in Unix-like operating systems. It allows users to schedule commands or scripts to run automatically at specified intervals or times. The name "cron" comes from the Greek word for time, "chronos."
|
||||
|
||||
## 2. The Cron Daemon
|
||||
|
||||
The cron daemon is a background process that runs constantly, checking for scheduled tasks and executing them when their time comes. It reads the crontab (cron table) files to determine which tasks to run and when.
|
||||
|
||||
## 3. Crontab Files
|
||||
|
||||
There are two types of crontab files:
|
||||
|
||||
- a. System-wide crontab: Located at /etc/crontab
|
||||
- b. User-specific crontabs: Usually located in /var/spool/cron/crontabs/
|
||||
|
||||
## 4. Crontab Syntax
|
||||
|
||||
A crontab entry typically has six fields:
|
||||
|
||||
```
|
||||
* * * * * command_to_execute
|
||||
│ │ │ │ │
|
||||
│ │ │ │ └─── Day of the week (0 - 7) (Sunday = 0 or 7)
|
||||
│ │ │ └────── Month (1 - 12)
|
||||
│ │ └───────── Day of the month (1 - 31)
|
||||
│ └──────────── Hour (0 - 23)
|
||||
└─────────────── Minute (0 - 59)
|
||||
```
|
||||
|
||||
## 5. Special Characters in Crontab
|
||||
|
||||
- Asterisk (*): Matches any value
|
||||
- Comma (,): Specifies a list of values
|
||||
- Hyphen (-): Defines a range of values
|
||||
- Forward slash (/): Specifies step values
|
||||
|
||||
## 6. Examples of Cron Jobs
|
||||
|
||||
### a. Run a script every day at 3:30 AM:
|
||||
```
|
||||
30 3 * * * /path/to/script.sh
|
||||
```
|
||||
|
||||
### b. Run a command every 15 minutes:
|
||||
```
|
||||
*/15 * * * * /path/to/command
|
||||
```
|
||||
|
||||
### c. Run a script every weekday at 9 AM:
|
||||
```
|
||||
0 9 * * 1-5 /path/to/script.sh
|
||||
```
|
||||
|
||||
## 7. Managing Crontabs
|
||||
|
||||
- Edit current user's crontab: `crontab -e`
|
||||
- List current user's crontab: `crontab -l`
|
||||
- Remove current user's crontab: `crontab -r`
|
||||
|
||||
## 8. Cron Job Output
|
||||
|
||||
By default, cron sends the output of jobs to the user's email. To redirect output:
|
||||
|
||||
```
|
||||
* * * * * /path/to/command > /path/to/output.log 2>&1
|
||||
```
|
||||
|
||||
## 9. Environment Variables
|
||||
|
||||
Cron jobs run with a minimal set of environment variables. To set variables:
|
||||
|
||||
### a. In the crontab file:
|
||||
```
|
||||
SHELL=/bin/bash
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
||||
* * * * * /path/to/command
|
||||
```
|
||||
|
||||
### b. In the script itself:
|
||||
```bash
|
||||
#!/bin/bash
|
||||
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
||||
# Rest of the script
|
||||
```
|
||||
|
||||
## 10. Troubleshooting Cron Jobs
|
||||
|
||||
- Check system logs: `grep CRON /var/log/syslog`
|
||||
- Ensure correct permissions on scripts
|
||||
- Use full paths for commands and files
|
||||
- Test scripts manually before scheduling
|
||||
|
||||
## 11. Alternatives to Cron
|
||||
|
||||
a. Anacron: Runs jobs at intervals on systems not running 24/7
|
||||
b. Systemd Timers: Modern alternative in systems using systemd
|
||||
c. at: For one-time scheduled tasks
|
||||
|
||||
## 12. Best Practices
|
||||
|
||||
- Comment your crontab entries
|
||||
- Use descriptive names for scripts
|
||||
- Avoid running resource-intensive jobs during peak hours
|
||||
- Use error handling in your scripts
|
||||
- Monitor and log job execution
|
||||
|
||||
## 13. Security Considerations
|
||||
|
||||
- Limit access to crontab files
|
||||
- Avoid running jobs as root unless necessary
|
||||
- Be cautious with scripts that modify system files or settings
|
||||
- Regularly audit cron jobs
|
||||
|
||||
## 14. Advanced Cron Features
|
||||
|
||||
- @reboot: Run a job at system startup
|
||||
- @yearly, @monthly, @weekly, @daily, @hourly: Shorthand for common intervals
|
||||
|
||||
Example:
|
||||
```
|
||||
@daily /path/to/daily_backup.sh
|
||||
```
|
||||
|
||||
## 15. Debugging Cron Jobs
|
||||
|
||||
- Use `set -x` in bash scripts for verbose output
|
||||
- Redirect stderr to a log file for error tracking
|
||||
- Use `lockfile` to prevent overlapping job executions
|
||||
|
||||
## 16. External Resources
|
||||
|
||||
- 1.[Crontab Generator](https://crontab-generator.org/)
|
||||
This guide covers the essentials of Cron jobs and task scheduling in Linux. It's a powerful tool for automating repetitive tasks and system maintenance. As you become more familiar with Cron, you'll find numerous ways to improve your system's efficiency and reduce manual interventions.
|
||||
|
||||
@ -0,0 +1,136 @@
|
||||
# Disk Management and Partitions in Linux
|
||||
|
||||
1. Introduction to Disk Management in Linux
|
||||
2. Understanding Partitions
|
||||
3. Partition Table Types
|
||||
4. Linux Filesystem Hierarchy
|
||||
5. Common Disk Management Tools
|
||||
6. Basic Disk Operations
|
||||
7. Advanced Disk Operations
|
||||
8. Best Practices and Considerations
|
||||
|
||||
## 1. Introduction to Disk Management in Linux
|
||||
|
||||
Disk management in Linux involves organizing and maintaining storage devices connected to your system. This includes tasks such as creating, resizing, and deleting partitions, formatting filesystems, and mounting storage devices.
|
||||
|
||||
## 2. Understanding Partitions
|
||||
|
||||
A partition is a logical division of a physical storage device. Partitions allow you to:
|
||||
- Separate the operating system from user data
|
||||
- Install multiple operating systems on a single drive
|
||||
- Organize data more efficiently
|
||||
- Improve system performance and security
|
||||
|
||||
Common partition types in Linux include:
|
||||
- Root (/)
|
||||
- Swap
|
||||
- /home
|
||||
- /boot
|
||||
- /var
|
||||
|
||||
## 3. Partition Table Types
|
||||
|
||||
There are two main types of partition tables:
|
||||
|
||||
### a. MBR (Master Boot Record):
|
||||
- Limited to 4 primary partitions
|
||||
- Maximum partition size of 2TB
|
||||
- Used in legacy BIOS systems
|
||||
|
||||
### b. GPT (GUID Partition Table):
|
||||
- Supports up to 128 partitions
|
||||
- Allows for much larger partition sizes
|
||||
- Used in modern UEFI systems
|
||||
|
||||
## 4. Linux Filesystem Hierarchy
|
||||
|
||||
Linux follows a standardized directory structure:
|
||||
- /: Root directory
|
||||
- /home: User home directories
|
||||
- /etc: System configuration files
|
||||
- /var: Variable data (logs, temporary files)
|
||||
- /boot: Boot loader files
|
||||
- /mnt and /media: Mount points for removable devices
|
||||
|
||||
## 5. Common Disk Management Tools
|
||||
|
||||
Linux provides several tools for disk management:
|
||||
|
||||
### a. Command-line tools:
|
||||
- fdisk: Partition table manipulator
|
||||
- parted: Versatile partition tool
|
||||
- lsblk: List block devices
|
||||
- df: Report file system disk space usage
|
||||
- du: Estimate file space usage
|
||||
|
||||
### b. Graphical tools:
|
||||
- GParted: GNOME Partition Editor
|
||||
- KDE Partition Manager
|
||||
|
||||
## 6. Basic Disk Operations
|
||||
|
||||
### a. Viewing disk information:
|
||||
```
|
||||
lsblk
|
||||
fdisk -l
|
||||
```
|
||||
|
||||
### b. Creating a new partition:
|
||||
```
|
||||
sudo fdisk /dev/sdX
|
||||
```
|
||||
(Replace X with the appropriate letter)
|
||||
|
||||
### c. Formatting a partition:
|
||||
```
|
||||
sudo mkfs.ext4 /dev/sdXY
|
||||
```
|
||||
(Replace X and Y with appropriate letters/numbers)
|
||||
|
||||
### d. Mounting a partition:
|
||||
```
|
||||
sudo mount /dev/sdXY /mnt/mountpoint
|
||||
```
|
||||
|
||||
### e. Unmounting a partition:
|
||||
```
|
||||
sudo umount /mnt/mountpoint
|
||||
```
|
||||
|
||||
## 7. Advanced Disk Operations
|
||||
|
||||
### a. Resizing partitions:
|
||||
Use GParted or command-line tools like resize2fs for ext filesystems.
|
||||
|
||||
### b. LVM (Logical Volume Management):
|
||||
LVM allows for more flexible disk management, including:
|
||||
- Spanning volumes across multiple disks
|
||||
- Easy resizing of logical volumes
|
||||
- Creating snapshots
|
||||
|
||||
### c. RAID (Redundant Array of Independent Disks):
|
||||
Linux supports software RAID for improved performance and data redundancy.
|
||||
|
||||
### d. Encrypting partitions:
|
||||
Use LUKS (Linux Unified Key Setup) for full-disk encryption.
|
||||
|
||||
## 8. Best Practices and Considerations
|
||||
|
||||
a. Regular backups: Always back up important data before making changes to disk partitions.
|
||||
|
||||
b. Plan your partitioning scheme: Consider your needs for separate /home, /var, or /opt partitions.
|
||||
|
||||
c. Use appropriate filesystem types: Choose between ext4, XFS, Btrfs, or others based on your requirements.
|
||||
|
||||
d. Monitor disk health: Use tools like smartctl to check for potential drive failures.
|
||||
|
||||
e. Keep your system updated: Regular updates can improve disk management tools and fix bugs.
|
||||
|
||||
f. Be cautious with root privileges: Disk management often requires root access, so be careful to avoid accidental data loss.
|
||||
|
||||
|
||||
- [(1) How to Install GParted on Linux Mint 21 - Linux Genie.](https://linuxgenie.net/how-to-install-gparted-on-linux-mint-21/.)
|
||||
- [(2) Linux Mint View & Manage System Partitions: A Comprehensive Guide.](https://bytebitebit.com/tips-tricks/linux-mint-view-manage-system-partitions/.)
|
||||
- [(3) Linux Mint View Manage System Partitions: A Comprehensive Guide.](https://www.positioniseverything.net/linux-mint-view-manage-system-partitions/.)
|
||||
- [(4) Mastering Linux Disk Management: LVM and Disk Partitioning.](https://www.linuxjournal.com/content/mastering-linux-disk-management-lvm-and-disk-partitioning.)
|
||||
- [(5) How to Use Fdisk to Manage Partitions on Linux - How-To Geek.](https://www.howtogeek.com/106873/how-to-use-fdisk-to-manage-partitions-on-linux/.)
|
||||
@ -0,0 +1,81 @@
|
||||
# etwork File Systems (NFS)
|
||||
|
||||
## Network File System (NFS) Overview:
|
||||
NFS is a distributed file system protocol that allows a user on a client computer to access files over a network in a manner similar to how local storage is accessed. NFS was originally developed by Sun Microsystems in 1984 and has since become a widely used protocol for file sharing in Unix-like operating systems.
|
||||
|
||||
## Key Features of NFS:
|
||||
- 1. Transparent access to remote files
|
||||
- 2. Support for heterogeneous environments
|
||||
- 3. Stateless protocol (versions 2 and 3)
|
||||
- 4. Caching for improved performance
|
||||
- 5. User authentication and access control
|
||||
|
||||
## NFS Versions:
|
||||
- 1. NFSv2 (1989): The first widely used version
|
||||
- 2. NFSv3 (1995): Improved performance and added features
|
||||
- 3. NFSv4 (2000): Major revision with enhanced security and internet-friendly features
|
||||
- 4. NFSv4.1 (2010): Added parallel NFS (pNFS) for improved scalability
|
||||
- 5. NFSv4.2 (2016): Added server-side copy and space reservation
|
||||
|
||||
## NFS Architecture:
|
||||
NFS follows a client-server model:
|
||||
- 1. NFS Server: Exports file systems to be shared
|
||||
- 2. NFS Client: Mounts the exported file systems
|
||||
- 3. RPC (Remote Procedure Call): Facilitates communication between client and server
|
||||
|
||||
## NFS Components:
|
||||
- 1. MOUNT protocol: Handles the mounting of file systems
|
||||
- 2. NFS protocol: Manages file and directory operations
|
||||
- 3. Portmapper/RPCBIND: Maps RPC program numbers to network port numbers
|
||||
- 4. NFS Daemon (nfsd): Handles client requests on the server
|
||||
- 5. Lock Manager (lockd): Manages file locking
|
||||
- 6. Status Monitor (statd): Provides crash and recovery functions
|
||||
|
||||
## NFS Operation:
|
||||
- 1. Server exports file systems
|
||||
- 2. Client discovers available exports
|
||||
- 3. Client mounts desired file system
|
||||
- 4. Client accesses files using NFS protocol
|
||||
|
||||
## Security Considerations:
|
||||
- 1. Authentication: Kerberos (NFSv4), AUTH_SYS (older versions)
|
||||
- 2. Authorization: Access control lists (ACLs) or traditional Unix permissions
|
||||
- 3. Encryption: RPCSEC_GSS (NFSv4)
|
||||
- 4. Firewall configuration: Proper port management
|
||||
|
||||
## Performance Tuning:
|
||||
- 1. Adjust read and write buffer sizes
|
||||
- 2. Optimize network settings (MTU, TCP window size)
|
||||
- 3. Use appropriate mount options (e.g., rsize, wsize)
|
||||
- 4. Implement caching strategies
|
||||
|
||||
## Common NFS Commands:
|
||||
- 1. exportfs: Maintain table of exported file systems
|
||||
- 2. showmount: Display mount information for an NFS server
|
||||
- 3. mount/umount: Mount and unmount NFS shares
|
||||
- 4. nfsstat: Display NFS statistics
|
||||
|
||||
## Troubleshooting NFS:
|
||||
- 1. Check network connectivity
|
||||
- 2. Verify NFS services are running
|
||||
- 3. Review server logs (/var/log/messages, /var/log/syslog)
|
||||
- 4. Use tcpdump or Wireshark for packet analysis
|
||||
- 5. Test with different NFS versions or mount options
|
||||
|
||||
## NFS Alternatives:
|
||||
- 1. Samba (SMB/CIFS): Better for Windows integration
|
||||
- 2. AFS (Andrew File System): Designed for large-scale distributed computing
|
||||
- 3. GlusterFS: Scalable network filesystem
|
||||
- 4. Ceph: Distributed object store and file system
|
||||
|
||||
## Best Practices:
|
||||
- 1. Use NFSv4 when possible for improved security and performance
|
||||
- 2. Implement proper access controls and user mapping
|
||||
- 3. Regularly update NFS software to address security vulnerabilities
|
||||
- 4. Monitor NFS performance and adjust settings as needed
|
||||
- 5. Implement redundancy and failover mechanisms for critical deployments
|
||||
|
||||
## NFS in Modern Environments:
|
||||
- 1. Container orchestration: NFS can be used as persistent storage for Kubernetes
|
||||
- 2. Cloud computing: Many cloud providers offer NFS-compatible file storage services
|
||||
- 3. Hybrid environments: NFS can bridge on-premises and cloud storage
|
||||
39
08 - Advanced Linux Administration/Networking File System.md
Normal file
39
08 - Advanced Linux Administration/Networking File System.md
Normal file
@ -0,0 +1,39 @@
|
||||
## Let's discuss **NTFS (New Technology File System)** and how to work with it in **Linux Mint**.
|
||||
|
||||
1. **Mounting NTFS Partitions**:
|
||||
- NTFS is the default file system for Windows systems, but we can also mount NTFS partitions in Linux to read and write data.
|
||||
- To mount an NTFS partition, follow these steps:
|
||||
- First, create a mount point using the `mkdir` command:
|
||||
```
|
||||
sudo mkdir /mnt/ntfs
|
||||
```
|
||||
- Next, use the `mount` command to mount the partition you want (e.g., `/dev/sdb2`):
|
||||
```
|
||||
sudo mount -t ntfs-3g /dev/sdb2 /mnt/ntfs
|
||||
```
|
||||
- To check if the partition is mounted, run:
|
||||
```
|
||||
df -hT
|
||||
```
|
||||
- Now you have read/write permissions for the NTFS partition you mounted¹².
|
||||
|
||||
2. **Changing File Permissions on NTFS Partitions**:
|
||||
- To apply Linux-compatible file permissions to an NTFS drive, modify the `/etc/fstab` file.
|
||||
- Add the following line to `/etc/fstab`:
|
||||
```
|
||||
/dev/sdb /mnt/ntfs ntfs uid=1000,gid=1000,dmask=022,fmask=133 0 0
|
||||
```
|
||||
This line specifies that the `/dev/sdb` partition should be mounted as NTFS in the `/mnt/ntfs` directory.
|
||||
- Remount the partition or reboot for the changes to take effect².
|
||||
|
||||
Feel free to explore further or ask if you need additional assistance! 😊🚀
|
||||
|
||||
Source: Conversation with Copilot, 7/12/2024
|
||||
- [(1) How to Mount NTFS Partition in Linux - phoenixNAP.](https://phoenixnap.com/kb/mount-ntfs-linux.)
|
||||
- [(2) Changing File Permissions on NTFS Partitions in Linux.](https://linuxconfig.org/changing-file-permissions-on-ntfs-partitions-in-linux.)
|
||||
- [(3) How to Mount and Access Windows NTFS Drives in Linux - MUO.](https://www.makeuseof.com/mount-ntfs-windows-drives-in-linux/.)
|
||||
- [(4) How to Mount an NTFS Partition - Linux Nightly.](https://linuxnightly.com/mount-ntfs-partition/.)
|
||||
- [(5) Linux mount ntfs or Access NTFS partition from Linux - nixCraft.](https://www.cyberciti.biz/faq/linux-mount-ntfs-or-access-ntfs-partition-from-linux/.)
|
||||
- [(6) How to mount NTFS partitions using Linux commands.](https://www.computerworld.com/article/1637061/how-to-mount-ntfs-partitions-using-linux-commands.html.)
|
||||
- [(7) NTFS Disk mounting in mint - Unix & Linux Stack Exchange.](https://unix.stackexchange.com/questions/358229/ntfs-disk-mounting-in-mint.)
|
||||
- [(8) How to Mount NFS in Linux: A Step-by-Step Guide - Byte Bite Bit.](https://bytebitebit.com/operating-system/linux/how-to-mount-nfs-in-linux/.)
|
||||
@ -0,0 +1,101 @@
|
||||
# Overview of Linux System Log Management
|
||||
|
||||
##1. Introduction to Linux Logging
|
||||
|
||||
Linux systems generate various logs to record system events, application activities, and user actions. Effective log management is crucial for system administration, troubleshooting, security monitoring, and compliance.
|
||||
|
||||
## 2. Types of Linux Logs
|
||||
|
||||
- a) System Logs: Record kernel and system-level events
|
||||
- b) Application Logs: Specific to individual applications
|
||||
- c) Security Logs: Track authentication attempts and security-related events
|
||||
- d) Audit Logs: Detailed records of system calls and file accesses
|
||||
|
||||
## 3. Log Locations
|
||||
|
||||
Common log directories:
|
||||
- /var/log: Main directory for most system and application logs
|
||||
- /var/log/syslog or /var/log/messages: General system messages
|
||||
- /var/log/auth.log or /var/log/secure: Authentication and authorization logs
|
||||
- /var/log/kern.log: Kernel logs
|
||||
- /var/log/dmesg: Boot messages
|
||||
|
||||
## 4. Logging Daemons
|
||||
|
||||
### a) Syslog:
|
||||
- Traditional Unix logging system
|
||||
- Configurable via /etc/syslog.conf
|
||||
|
||||
### b) Rsyslog:
|
||||
- Extended version of syslog
|
||||
- More flexible and feature-rich
|
||||
- Configurable via /etc/rsyslog.conf
|
||||
|
||||
### c) Systemd-journald:
|
||||
- Part of systemd init system
|
||||
- Collects and stores logging data in binary format
|
||||
- Accessed using the 'journalctl' command
|
||||
|
||||
## 5. Log Rotation
|
||||
|
||||
Log rotation is essential to manage log file sizes and prevent disk space issues.
|
||||
|
||||
### a) Logrotate:
|
||||
- Standard tool for log rotation
|
||||
- Configured in /etc/logrotate.conf and /etc/logrotate.d/
|
||||
- Features: compression, archiving, and custom rotation schedules
|
||||
|
||||
## 6. Log Analysis Tools
|
||||
|
||||
- a) grep, awk, sed: Command-line tools for basic log parsing
|
||||
- b) logwatch: Summarizes log files and emails reports
|
||||
- c) Goaccess: Real-time web log analyzer and interactive viewer
|
||||
- d) ELK Stack (Elasticsearch, Logstash, Kibana): Advanced log analysis and visualization platform
|
||||
|
||||
## 7. Security Considerations
|
||||
|
||||
- a) Log file permissions: Ensure proper read/write permissions
|
||||
- b) Remote logging: Set up centralized log servers for better security
|
||||
- c) Log integrity: Use tools like logaudit to detect log tampering
|
||||
- d) Retention policies: Implement appropriate log retention periods
|
||||
|
||||
## 8. Best Practices
|
||||
|
||||
- a) Regular log review: Schedule routine log checks
|
||||
- b) Alerting: Set up notifications for critical events
|
||||
- c) Correlation: Analyze logs from multiple sources together
|
||||
- d) Normalization: Standardize log formats for easier analysis
|
||||
- e) Backup: Regularly backup important log files
|
||||
|
||||
## 9. Advanced Logging Techniques
|
||||
|
||||
- a) Syslog-ng: Advanced logging daemon with filtering and routing capabilities
|
||||
- b) Auditd: Linux Audit daemon for detailed system call logging
|
||||
- c) Fail2ban: Log parsing tool to detect and prevent brute-force attacks
|
||||
|
||||
## 10. Compliance and Regulations
|
||||
|
||||
Ensure logging practices comply with relevant standards:
|
||||
- PCI DSS for payment card industry
|
||||
- HIPAA for healthcare
|
||||
- SOX for financial reporting
|
||||
|
||||
## 11. Troubleshooting Common Issues
|
||||
|
||||
- a) Log file corruption
|
||||
- b) Insufficient disk space
|
||||
- c) Incorrect log rotation
|
||||
- d) Time synchronization problems
|
||||
|
||||
## 12. Performance Considerations
|
||||
|
||||
- a) Log levels: Adjust verbosity to balance between detail and performance
|
||||
- b) I/O impact: Monitor the impact of logging on system performance
|
||||
- c) Log compression: Use compression to save disk space
|
||||
|
||||
## 13. Automation and Scripting
|
||||
|
||||
Develop scripts for:
|
||||
- Automated log analysis
|
||||
- Custom report generation
|
||||
- Integration with monitoring systems
|
||||
153
08 - Advanced Linux Administration/RAID and LVM.md
Normal file
153
08 - Advanced Linux Administration/RAID and LVM.md
Normal file
@ -0,0 +1,153 @@
|
||||
|
||||
# RAID and LVM
|
||||
|
||||
## 1. RAID (Redundant Array of Independent Disks)
|
||||
|
||||
RAID is a technology that combines multiple disk drive components into a logical unit for data redundancy and performance improvement.
|
||||
|
||||
Types of RAID:
|
||||
|
||||
### a) RAID 0 (Striping):
|
||||
- Data is split across multiple disks
|
||||
- Improves performance but no redundancy
|
||||
- Minimum 2 disks required
|
||||
|
||||
### b) RAID 1 (Mirroring):
|
||||
- Data is duplicated on two or more disks
|
||||
- Provides redundancy but no performance improvement for writes
|
||||
- Minimum 2 disks required
|
||||
|
||||
### c) RAID 5 (Striping with parity):
|
||||
- Data and parity information are striped across all disks
|
||||
- Good balance of performance and redundancy
|
||||
- Can survive one disk failure
|
||||
- Minimum 3 disks required
|
||||
|
||||
### d) RAID 6 (Striping with double parity):
|
||||
- Similar to RAID 5 but with two parity blocks
|
||||
- Can survive two disk failures
|
||||
- Minimum 4 disks required
|
||||
|
||||
### e) RAID 10 (Stripe of mirrors):
|
||||
- Combines RAID 1 and RAID 0
|
||||
- Provides both redundancy and performance improvement
|
||||
- Minimum 4 disks required
|
||||
|
||||
## Setting up RAID in Linux:
|
||||
|
||||
### 1. Install mdadm:
|
||||
```
|
||||
sudo apt-get install mdadm
|
||||
```
|
||||
|
||||
### 2. Create a RAID array (example for RAID 5):
|
||||
```
|
||||
sudo mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sdb /dev/sdc /dev/sdd
|
||||
```
|
||||
|
||||
### 3. Create a filesystem on the RAID array:
|
||||
```
|
||||
sudo mkfs.ext4 /dev/md0
|
||||
```
|
||||
|
||||
### 4. Mount the RAID array:
|
||||
```
|
||||
sudo mount /dev/md0 /mnt/raid
|
||||
```
|
||||
|
||||
### 5. Save the RAID configuration:
|
||||
```
|
||||
sudo mdadm --detail --scan >> /etc/mdadm/mdadm.conf
|
||||
```
|
||||
|
||||
## 2. LVM (Logical Volume Management)
|
||||
|
||||
LVM is a device mapper framework that provides logical volume management for the Linux kernel. It allows for more flexible disk space management.
|
||||
|
||||
Key concepts:
|
||||
|
||||
- a) Physical Volume (PV): Physical disks or partitions
|
||||
- b) Volume Group (VG): Group of physical volumes
|
||||
- c) Logical Volume (LV): Virtual partitions created from a volume group
|
||||
|
||||
Setting up LVM:
|
||||
|
||||
### 1. Install LVM:
|
||||
```
|
||||
sudo apt-get install lvm2
|
||||
```
|
||||
|
||||
### 2. Create Physical Volumes:
|
||||
```
|
||||
sudo pvcreate /dev/sdb /dev/sdc
|
||||
```
|
||||
|
||||
### 3. Create a Volume Group:
|
||||
```
|
||||
sudo vgcreate myvg /dev/sdb /dev/sdc
|
||||
```
|
||||
|
||||
### 4. Create Logical Volumes:
|
||||
```
|
||||
sudo lvcreate -n mylv1 -L 50G myvg
|
||||
sudo lvcreate -n mylv2 -l 100%FREE myvg
|
||||
```
|
||||
|
||||
### 5. Create filesystems on Logical Volumes:
|
||||
```
|
||||
sudo mkfs.ext4 /dev/myvg/mylv1
|
||||
sudo mkfs.ext4 /dev/myvg/mylv2
|
||||
```
|
||||
|
||||
### 6. Mount Logical Volumes:
|
||||
```
|
||||
sudo mount /dev/myvg/mylv1 /mnt/lv1
|
||||
sudo mount /dev/myvg/mylv2 /mnt/lv2
|
||||
```
|
||||
|
||||
Advantages of LVM:
|
||||
|
||||
- 1. Flexible capacity management
|
||||
- 2. Easy resizing of logical volumes
|
||||
- 3. Snapshots for backup purposes
|
||||
- 4. Striping and mirroring capabilities
|
||||
|
||||
Combining RAID and LVM:
|
||||
|
||||
You can use RAID as the underlying storage for LVM, providing both redundancy and flexibility:
|
||||
|
||||
- 1. Create a RAID array
|
||||
- 2. Use the RAID array as a Physical Volume for LVM
|
||||
- 3. Create Volume Groups and Logical Volumes on top of the RAID array
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
sudo mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sdb /dev/sdc /dev/sdd
|
||||
sudo pvcreate /dev/md0
|
||||
sudo vgcreate myvg /dev/md0
|
||||
sudo lvcreate -n mylv1 -L 100G myvg
|
||||
sudo mkfs.ext4 /dev/myvg/mylv1
|
||||
sudo mount /dev/myvg/mylv1 /mnt/data
|
||||
```
|
||||
|
||||
This setup provides the redundancy of RAID 5 with the flexibility of LVM.
|
||||
|
||||
### Maintenance and Monitoring:
|
||||
|
||||
#### 1. RAID:
|
||||
- Check RAID status: `cat /proc/mdstat`
|
||||
- Detailed RAID info: `sudo mdadm --detail /dev/md0`
|
||||
|
||||
#### 2. LVM:
|
||||
- Display PV info: `sudo pvdisplay`
|
||||
- Display VG info: `sudo vgdisplay`
|
||||
- Display LV info: `sudo lvdisplay`
|
||||
|
||||
Remember, LVM provides flexibility, scalability, and ease of maintenance, while RAID enhances performance and data protection! 😊🚀
|
||||
|
||||
Source: Conversation with Copilot, 7/12/2024
|
||||
- [(1) Complete Beginner's Guide to LVM in Linux [With Hands-on].](https://linuxhandbook.com/lvm-guide/.)
|
||||
- [(2) Linux Storage Management: LVM and RAID.](https://linuxhall.org/linux-storage-management-lvm-and-raid/.)
|
||||
- [(3) raid - RAIDing with LVM vs MDRAID - Unix & Linux Stack Exchange.](https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons.)
|
||||
- [(4) What is better LVM on RAID or RAID on LVM? - Server Fault.](https://serverfault.com/questions/217666/what-is-better-lvm-on-raid-or-raid-on-lvm.)
|
||||
@ -0,0 +1,155 @@
|
||||
# System Log Management *JournalCTL)
|
||||
|
||||
## 1. Introduction to journalctl
|
||||
|
||||
journalctl is a command-line utility for querying and displaying logs from the systemd journal. The systemd journal is a centralized logging system that collects and stores logging data from various sources, including the kernel, system services, and applications.
|
||||
|
||||
## 2. Basic Usage
|
||||
|
||||
### To view all logs:
|
||||
```
|
||||
journalctl
|
||||
```
|
||||
|
||||
### To follow new log entries in real-time:
|
||||
```
|
||||
journalctl -f
|
||||
```
|
||||
|
||||
## 3. Filtering Logs
|
||||
|
||||
### By time:
|
||||
```
|
||||
journalctl --since "2024-01-01 00:00:00"
|
||||
journalctl --until "2024-01-31 23:59:59"
|
||||
journalctl --since "1 hour ago"
|
||||
```
|
||||
|
||||
### By service unit:
|
||||
```
|
||||
journalctl -u nginx.service
|
||||
journalctl -u ssh.service
|
||||
```
|
||||
|
||||
### By priority level:
|
||||
```
|
||||
journalctl -p err
|
||||
```
|
||||
Priority levels: emerg, alert, crit, err, warning, notice, info, debug
|
||||
|
||||
### By kernel messages:
|
||||
```
|
||||
journalctl -k
|
||||
```
|
||||
|
||||
## 4. Output Formatting
|
||||
|
||||
### JSON output:
|
||||
```
|
||||
journalctl -o json
|
||||
```
|
||||
|
||||
### Short output format:
|
||||
```
|
||||
journalctl -o short
|
||||
```
|
||||
|
||||
### Verbose output:
|
||||
```
|
||||
journalctl -o verbose
|
||||
```
|
||||
|
||||
## 5. Boot-specific Logs
|
||||
|
||||
### Current boot:
|
||||
```
|
||||
journalctl -b
|
||||
```
|
||||
|
||||
### Previous boot:
|
||||
```
|
||||
journalctl -b -1
|
||||
```
|
||||
|
||||
## 6. User-specific Logs
|
||||
|
||||
```
|
||||
journalctl _UID=1000
|
||||
```
|
||||
|
||||
## 7. Disk Usage and Log Rotation
|
||||
|
||||
### View disk usage:
|
||||
```
|
||||
journalctl --disk-usage
|
||||
```
|
||||
|
||||
### Rotate logs:
|
||||
```
|
||||
journalctl --rotate
|
||||
```
|
||||
|
||||
### Vacuum old logs:
|
||||
```
|
||||
journalctl --vacuum-time=1week
|
||||
journalctl --vacuum-size=1G
|
||||
```
|
||||
|
||||
## 8. Remote Journal Access
|
||||
|
||||
To access logs on a remote system:
|
||||
```
|
||||
journalctl -D /path/to/journal/directory
|
||||
```
|
||||
|
||||
## 9. Persistent Journal Storage
|
||||
|
||||
### Edit /etc/systemd/journald.conf:
|
||||
```
|
||||
Storage=persistent
|
||||
```
|
||||
|
||||
### Restart journald:
|
||||
```
|
||||
sudo systemctl restart systemd-journald
|
||||
```
|
||||
|
||||
## 10. Forwarding Logs to a Central Server
|
||||
|
||||
### Install rsyslog:
|
||||
```
|
||||
sudo apt install rsyslog
|
||||
```
|
||||
|
||||
### Configure /etc/rsyslog.conf for forwarding:
|
||||
```
|
||||
*.* @@central-log-server:514
|
||||
```
|
||||
|
||||
### Restart rsyslog:
|
||||
```
|
||||
sudo systemctl restart rsyslog
|
||||
```
|
||||
|
||||
## 11. Security Considerations
|
||||
|
||||
- Restrict access to journal files
|
||||
- Use encryption for remote logging
|
||||
- Regularly audit and review logs
|
||||
- Implement log retention policies
|
||||
|
||||
## 12. Performance Tuning
|
||||
|
||||
Adjust RateLimitInterval and RateLimitBurst in /etc/systemd/journald.conf to balance between logging thoroughness and system performance.
|
||||
|
||||
## 13. Integration with Other Tools
|
||||
|
||||
journalctl can be combined with other tools like grep, awk, and sed for advanced log analysis:
|
||||
|
||||
```
|
||||
journalctl | grep "error" | awk '{print $1, $2, $3}'
|
||||
```
|
||||
|
||||
## 14. Scripting and Automation
|
||||
|
||||
You can use journalctl in shell scripts for automated log analysis and reporting.
|
||||
@ -0,0 +1,47 @@
|
||||
## Securing your **Linux Mint** system involves several important steps to protect your data and maintain system integrity. Let's delve into the details:
|
||||
|
||||
1. **Keeping Your System Up to Date**:
|
||||
- Regularly update your system using the built-in update manager or the command line (`sudo apt-get update`).
|
||||
- Apply security patches promptly to address vulnerabilities and protect against potential attacks¹.
|
||||
|
||||
2. **Using Strong Passwords**:
|
||||
- A strong password is crucial for user accounts.
|
||||
- Create passwords that are:
|
||||
- At least eight characters long.
|
||||
- A mix of uppercase and lowercase letters, numbers, and symbols.
|
||||
- Unique for each account.
|
||||
- Consider using a password manager to securely store and manage your passwords¹.
|
||||
|
||||
3. **Enabling the Firewall**:
|
||||
- Activate the firewall (usually **ufw** or **iptables**) to control incoming and outgoing network traffic.
|
||||
- Configure rules to allow necessary services and block unauthorized access¹.
|
||||
|
||||
4. **Installing Antivirus Software**:
|
||||
- Although Linux is less susceptible to viruses, having an antivirus tool can add an extra layer of protection.
|
||||
- Install a lightweight antivirus solution like **ClamAV**¹.
|
||||
|
||||
5. **Disabling Unnecessary Services and Applications**:
|
||||
- Review installed software and disable any unnecessary services or daemons.
|
||||
- Fewer running services reduce the attack surface¹.
|
||||
|
||||
6. **Enabling Automatic Updates**:
|
||||
- Set up automatic updates to ensure your system stays secure without manual intervention.
|
||||
- Regular updates also enhance features and fix bugs¹.
|
||||
|
||||
7. **Using Encryption**:
|
||||
- Encrypt sensitive data, especially if you store it on external drives or cloud services.
|
||||
- Tools like **VeraCrypt** or **LUKS** provide disk encryption options¹.
|
||||
|
||||
8. **Backing Up Your Data**:
|
||||
- Regularly back up important files to an external location.
|
||||
- Use tools like **rsync**, **Deja Dup**, or cloud storage services¹.
|
||||
|
||||
Remember, a combination of these practices helps maintain a secure Linux Mint environment. Feel free to explore further or ask if you need additional guidance! 😊🔒🚀
|
||||
|
||||
Source: Conversation with Copilot, 7/12/2024
|
||||
- [(1) 10 practical tips for securing your Linux Mint system - FOSS Linux.](https://www.fosslinux.com/103872/secure-your-linux-mint-system.htm.)
|
||||
- [(2) How to reset a forgotten password for any user under Linux Mint 21 ....](https://www.thinkpenguin.com/gnu-linux/how-reset-forgotten-password-any-user-under-linux-mint-21.)
|
||||
- [(3) Linux Mint 20 [Essential Security Guide: Tools & Tweaks].](https://www.securitybind.com/secure-linux-mint/.)
|
||||
- [(4) How to Configure Linux Mint Login Window: A Step-by-Step Guide.](https://bytebitebit.com/tips-tricks/how-to-configure-linux-mint-login-window/.)
|
||||
- [(5) Changes to password policies – The Linux Mint Blog.](https://blog.linuxmint.com/?p=3013.)
|
||||
- [(6) en.wikipedia.org.](https://en.wikipedia.org/wiki/Linux_Mint.)
|
||||
157
09 - Linux Security Concepts/Filesystem Security (eCryptFS).md
Normal file
157
09 - Linux Security Concepts/Filesystem Security (eCryptFS).md
Normal file
@ -0,0 +1,157 @@
|
||||
# Filesystem Security (eCryptFS)
|
||||
|
||||
eCryptfs (Enterprise Cryptographic Filesystem) is a POSIX-compliant stacked cryptographic filesystem for Linux. It provides file and directory level encryption, offering an additional layer of security for sensitive data. This guide will cover the key aspects of eCryptfs, its setup, usage, and best practices.
|
||||
|
||||
## 1. Introduction to eCryptfs
|
||||
|
||||
eCryptfs works by encrypting files on a per-file basis, storing the encrypted contents and metadata in the lower filesystem. It operates between the application and the filesystem, encrypting data before it's written to disk and decrypting it when it's read.
|
||||
|
||||
Key features:
|
||||
- File-based encryption
|
||||
- Transparent to applications
|
||||
- Supports extended attributes
|
||||
- Allows for per-file encryption keys
|
||||
- Integrates with Linux kernel keyring
|
||||
|
||||
## 2. Installation
|
||||
|
||||
On most Linux distributions, eCryptfs can be installed using the package manager:
|
||||
|
||||
```bash
|
||||
# For Ubuntu/Debian:
|
||||
sudo apt-get install ecryptfs-utils
|
||||
```
|
||||
```bash
|
||||
# For Fedora:
|
||||
sudo dnf install ecryptfs-utils
|
||||
```
|
||||
```bash
|
||||
# For Arch Linux:
|
||||
sudo pacman -S ecryptfs-utils
|
||||
```
|
||||
|
||||
## 3. Setting up eCryptfs
|
||||
|
||||
### - Creating an encrypted directory:
|
||||
|
||||
```bash
|
||||
mkdir ~/encrypted
|
||||
sudo mount -t ecryptfs ~/encrypted ~/encrypted
|
||||
```
|
||||
|
||||
You'll be prompted to answer several questions:
|
||||
- Choose a passphrase
|
||||
- Select the cipher
|
||||
- Select key bytes
|
||||
- Enable filename encryption (recommended)
|
||||
- Select filename encryption algorithm
|
||||
|
||||
### - Automounting at login:
|
||||
|
||||
To automount the encrypted directory at login, add the following line to your `/etc/fstab` file:
|
||||
|
||||
```
|
||||
/home/user/encrypted /home/user/encrypted ecryptfs defaults 0 0
|
||||
```
|
||||
|
||||
Replace "user" with your username.
|
||||
|
||||
## 4. Usage
|
||||
|
||||
### - Mounting the encrypted directory:
|
||||
|
||||
```bash
|
||||
mount -t ecryptfs ~/encrypted ~/encrypted
|
||||
```
|
||||
|
||||
### - Unmounting:
|
||||
|
||||
```bash
|
||||
umount ~/encrypted
|
||||
```
|
||||
|
||||
### - Checking mount status:
|
||||
|
||||
```bash
|
||||
mount | grep ecryptfs
|
||||
```
|
||||
|
||||
## 5. Key Management
|
||||
|
||||
eCryptfs uses a passphrase to derive the encryption key. This passphrase is stored in the Linux kernel keyring.
|
||||
|
||||
### - Adding a key to the keyring:
|
||||
|
||||
```bash
|
||||
ecryptfs-add-passphrase
|
||||
```
|
||||
|
||||
### - Removing a key from the keyring:
|
||||
|
||||
```bash
|
||||
keyctl purge user ecryptfs
|
||||
```
|
||||
|
||||
## 6. Advanced Features
|
||||
|
||||
### - Non-interactive mounting:
|
||||
|
||||
Create a file containing your mount options:
|
||||
|
||||
```bash
|
||||
echo "passphrase_passwd=your_passphrase" > ~/.ecryptfsrc
|
||||
```
|
||||
|
||||
Then mount using:
|
||||
|
||||
```bash
|
||||
mount -t ecryptfs -o conf=~/.ecryptfsrc ~/encrypted ~/encrypted
|
||||
```
|
||||
|
||||
### - Using different encryption for different directories:
|
||||
|
||||
You can mount multiple eCryptfs directories with different encryption settings by specifying different options during the mount process.
|
||||
|
||||
## 7. Best Practices
|
||||
|
||||
- Use strong passphrases
|
||||
- Enable filename encryption
|
||||
- Regularly backup your data (encrypted)
|
||||
- Keep your system and eCryptfs utilities updated
|
||||
- Consider using a key file instead of a passphrase for automated scripts
|
||||
- Use different encryption settings for highly sensitive data
|
||||
|
||||
## 8. Troubleshooting
|
||||
|
||||
If you can't mount the filesystem, check if the required kernel modules are loaded:
|
||||
|
||||
```bash
|
||||
lsmod | grep ecryptfs
|
||||
```
|
||||
|
||||
If not present, load them:
|
||||
|
||||
```bash
|
||||
sudo modprobe ecryptfs
|
||||
```
|
||||
|
||||
## !!!If you forget your passphrase, there's no way to recover the data. Always keep secure backups!!!
|
||||
|
||||
For performance issues, consider using a faster cipher like AES instead of Blowfish.
|
||||
|
||||
## 9. Limitations
|
||||
|
||||
- Slightly slower than unencrypted filesystems
|
||||
- No built-in key rotation mechanism
|
||||
- Potential for data loss if the encryption metadata is corrupted
|
||||
|
||||
## 10. Alternatives
|
||||
|
||||
While eCryptfs is powerful, consider these alternatives for different use cases:
|
||||
- LUKS: For full disk encryption
|
||||
- VeraCrypt: For cross-platform encrypted containers
|
||||
- Gocryptfs: A more modern alternative to eCryptfs
|
||||
|
||||
## Conclusion:
|
||||
|
||||
eCryptfs provides a flexible and robust solution for filesystem-level encryption in Linux. By following this guide and best practices, you can significantly enhance the security of your sensitive data. Remember that filesystem encryption is just one part of a comprehensive security strategy, and should be combined with other security measures for optimal protection.
|
||||
146
09 - Linux Security Concepts/Network Security (OpenSSH).md
Normal file
146
09 - Linux Security Concepts/Network Security (OpenSSH).md
Normal file
@ -0,0 +1,146 @@
|
||||
# Network Security (OpenSSH)
|
||||
|
||||
## 1. Introduction to OpenSSH
|
||||
OpenSSH (Open Secure Shell) is a suite of secure networking utilities based on the SSH (Secure Shell) protocol. It provides encrypted communication sessions over a computer network, allowing secure remote access, file transfers, and command execution.
|
||||
|
||||
## 2. Key Features of OpenSSH
|
||||
- Encrypted communication
|
||||
- Public key authentication
|
||||
- Port forwarding
|
||||
- X11 forwarding
|
||||
- SFTP (Secure File Transfer Protocol) subsystem
|
||||
|
||||
## 3. Installation
|
||||
Most Unix-like systems come with OpenSSH pre-installed. For other systems:
|
||||
|
||||
- Ubuntu/Debian: `sudo apt-get install openssh-server`
|
||||
- CentOS/RHEL: `sudo yum install openssh-server`
|
||||
- macOS: Comes pre-installed
|
||||
- Windows: Use OpenSSH or third-party implementations like PuTTY
|
||||
|
||||
## 4. Basic Configuration
|
||||
The main configuration file is `/etc/ssh/sshd_config`. Key settings include:
|
||||
|
||||
- Port: Change default port (22) to reduce automated attacks
|
||||
- PermitRootLogin: Disable direct root login
|
||||
- PasswordAuthentication: Disable password authentication
|
||||
- PubkeyAuthentication: Enable public key authentication
|
||||
|
||||
Example:
|
||||
```ini
|
||||
Port 2222
|
||||
PermitRootLogin no
|
||||
PasswordAuthentication no
|
||||
PubkeyAuthentication yes
|
||||
```
|
||||
|
||||
## 5. Public Key Authentication
|
||||
Generate a key pair:
|
||||
```bash
|
||||
ssh-keygen -t rsa -b 4096
|
||||
```
|
||||
|
||||
Transfer the public key to the server:
|
||||
```bash
|
||||
ssh-copy-id user@server
|
||||
```
|
||||
|
||||
## 6. Firewall Configuration
|
||||
Restrict SSH access using a firewall. For example, with UFW:
|
||||
```bash
|
||||
sudo ufw allow 2222/tcp
|
||||
sudo ufw enable
|
||||
```
|
||||
|
||||
## 7. Fail2Ban
|
||||
Install and configure Fail2Ban to protect against brute-force attacks:
|
||||
```bash
|
||||
sudo apt-get install fail2ban
|
||||
```
|
||||
|
||||
Configure in `/etc/fail2ban/jail.local`:
|
||||
```ini
|
||||
[sshd]
|
||||
enabled = true
|
||||
port = 2222
|
||||
filter = sshd
|
||||
logpath = /var/log/auth.log
|
||||
maxretry = 3
|
||||
```
|
||||
|
||||
## 8. Two-Factor Authentication (2FA)
|
||||
Install Google Authenticator:
|
||||
```bash
|
||||
sudo apt-get install libpam-google-authenticator
|
||||
```
|
||||
|
||||
Run the initialization:
|
||||
```bash
|
||||
google-authenticator
|
||||
```
|
||||
|
||||
Modify `/etc/pam.d/sshd`:
|
||||
```ini
|
||||
auth required pam_google_authenticator.so
|
||||
```
|
||||
|
||||
Update `/etc/ssh/sshd_config`:
|
||||
```ini
|
||||
ChallengeResponseAuthentication yes
|
||||
```
|
||||
|
||||
## 9. SSH Keys Management
|
||||
- Use ssh-agent for convenient key management
|
||||
- Implement SSH certificates for larger deployments
|
||||
|
||||
## 10. Port Forwarding
|
||||
Local port forwarding:
|
||||
```bash
|
||||
ssh -L 8080:localhost:80 user@server
|
||||
```
|
||||
|
||||
Remote port forwarding:
|
||||
```bash
|
||||
ssh -R 8080:localhost:80 user@server
|
||||
```
|
||||
|
||||
## 11. SFTP Configuration
|
||||
Configure SFTP-only access for certain users:
|
||||
```ini
|
||||
Match Group sftponly
|
||||
ChrootDirectory /home/%u
|
||||
ForceCommand internal-sftp
|
||||
AllowTcpForwarding no
|
||||
X11Forwarding no
|
||||
```
|
||||
|
||||
## 12. Logging and Monitoring
|
||||
- Enable verbose logging in sshd_config
|
||||
- Use tools like Logwatch or OSSEC for log analysis
|
||||
- Implement centralized logging with solutions like ELK stack
|
||||
|
||||
## 13. Regular Updates
|
||||
Keep your OpenSSH installation and the host system up-to-date:
|
||||
```bash
|
||||
sudo apt-get update && sudo apt-get upgrade
|
||||
```
|
||||
|
||||
## 14. Security Auditing
|
||||
Regularly audit your SSH configuration using tools like:
|
||||
- ssh-audit
|
||||
- Lynis
|
||||
|
||||
## 15. Best Practices
|
||||
- Use strong, unique passwords for each account
|
||||
- Implement the principle of least privilege
|
||||
- Regularly rotate SSH keys
|
||||
- Use SSH protocol version 2 only
|
||||
- Disable unused features and remove unnecessary user accounts
|
||||
|
||||
## 16. Troubleshooting
|
||||
- Check logs in `/var/log/auth.log` or `/var/log/secure`
|
||||
- Use `ssh -v` for verbose output during connection attempts
|
||||
- Verify file permissions (e.g., `~/.ssh` should be 700, `~/.ssh/authorized_keys` should be 600)
|
||||
|
||||
## Conclusion:
|
||||
Implementing these measures will significantly enhance the security of your SSH setup. However, security is an ongoing process. Stay informed about the latest vulnerabilities and best practices, and regularly review and update your configuration.
|
||||
129
09 - Linux Security Concepts/Network Security (OpenSSL).md
Normal file
129
09 - Linux Security Concepts/Network Security (OpenSSL).md
Normal file
@ -0,0 +1,129 @@
|
||||
# Network Security and OpenSSL: A Comprehensive Guide
|
||||
|
||||
## 1. Introduction to OpenSSL
|
||||
|
||||
OpenSSL is a robust, full-featured open-source toolkit that implements the Secure Sockets Layer (SSL) and Transport Layer Security (TLS) protocols, as well as a general-purpose cryptography library. It's widely used to secure network communications and is a critical component in many security systems.
|
||||
|
||||
## 2. Key Features of OpenSSL
|
||||
|
||||
- SSL/TLS protocol implementation
|
||||
- Cryptographic functions (encryption, decryption, hashing)
|
||||
- Certificate creation and management
|
||||
- Key generation and management
|
||||
|
||||
## 3. Installing OpenSSL
|
||||
|
||||
OpenSSL is available for various operating systems. Here are basic installation instructions:
|
||||
|
||||
- Linux: Most distributions come with OpenSSL pre-installed. If not, use package managers:
|
||||
```bash
|
||||
sudo apt-get install openssl libssl-dev # For Debian/Ubuntu
|
||||
```
|
||||
```bash
|
||||
sudo yum install openssl openssl-devel # For CentOS/RHEL
|
||||
```
|
||||
|
||||
- macOS: Use Homebrew:
|
||||
```
|
||||
brew install openssl
|
||||
```
|
||||
|
||||
- Windows: Download the installer from the official OpenSSL website.
|
||||
|
||||
## 4. Basic OpenSSL Commands
|
||||
|
||||
- Generate a private key:
|
||||
```bash
|
||||
openssl genrsa -out private.key 2048
|
||||
```
|
||||
|
||||
- Create a Certificate Signing Request (CSR):
|
||||
```bash
|
||||
openssl req -new -key private.key -out certificate.csr
|
||||
```
|
||||
|
||||
- Generate a self-signed certificate:
|
||||
```bash
|
||||
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365
|
||||
```
|
||||
|
||||
## 5. Implementing SSL/TLS in Network Applications
|
||||
|
||||
To secure network communications, you'll need to integrate OpenSSL into your applications. Here's a basic outline:
|
||||
|
||||
### Server-side implementation:
|
||||
- Initialize OpenSSL library
|
||||
- Create and configure SSL context
|
||||
- Load certificates and private key
|
||||
- Create SSL connection based on TCP socket
|
||||
- Handle SSL handshake
|
||||
|
||||
### Client-side implementation:
|
||||
- Initialize OpenSSL library
|
||||
- Create and configure SSL context
|
||||
- Create SSL connection based on TCP socket
|
||||
- Verify server certificate
|
||||
- Handle SSL handshake
|
||||
|
||||
## 6. Best Practices for OpenSSL Usage
|
||||
|
||||
- Keep OpenSSL updated to the latest version
|
||||
- Use strong encryption algorithms (e.g., AES-256)
|
||||
- Implement proper certificate validation
|
||||
- Use perfect forward secrecy (PFS) cipher suites
|
||||
- Regularly rotate keys and certificates
|
||||
- Implement secure random number generation
|
||||
|
||||
## 7. Common OpenSSL Vulnerabilities and Mitigations
|
||||
|
||||
- Heartbleed: Ensure you're using OpenSSL 1.0.1g or later
|
||||
- POODLE: Disable SSLv3 support
|
||||
- FREAK: Use strong key sizes (2048 bits or more for RSA)
|
||||
- Logjam: Use Diffie-Hellman parameters of 2048 bits or larger
|
||||
|
||||
## 8. OpenSSL for Secure Communication Protocols
|
||||
|
||||
OpenSSL can be used to implement various secure communication protocols:
|
||||
|
||||
- HTTPS: Secure HTTP connections
|
||||
- FTPS: Secure FTP connections
|
||||
- SMTPS: Secure email transmissions
|
||||
- VPNs: Secure virtual private networks
|
||||
|
||||
## 9. Performance Considerations
|
||||
|
||||
While security is paramount, performance shouldn't be neglected:
|
||||
|
||||
- Use hardware acceleration when available
|
||||
- Implement session caching to reduce handshake overhead
|
||||
- Consider using ECDSA certificates for faster operations
|
||||
- Balance security and performance in cipher suite selection
|
||||
|
||||
## 10. OpenSSL and Compliance
|
||||
|
||||
OpenSSL can help meet various compliance requirements:
|
||||
|
||||
- PCI DSS: For securing credit card data transmissions
|
||||
- HIPAA: For protecting healthcare information
|
||||
- GDPR: For safeguarding personal data of EU residents
|
||||
|
||||
## 11. Troubleshooting OpenSSL
|
||||
|
||||
Common issues and their solutions:
|
||||
|
||||
- Certificate errors: Check certificate validity, chain, and revocation status
|
||||
- Handshake failures: Verify supported protocols and cipher suites
|
||||
- Performance issues: Check for proper configuration and consider hardware acceleration
|
||||
|
||||
## 12. Future of OpenSSL
|
||||
|
||||
Stay informed about upcoming features and changes in OpenSSL, such as:
|
||||
|
||||
- TLS 1.3 support
|
||||
- Improved side-channel attack resistance
|
||||
- Enhanced APIs for easier integration
|
||||
|
||||
## Conclusion:
|
||||
|
||||
OpenSSL is a powerful tool for implementing network security. By understanding its features, following best practices, and staying updated on the latest developments, you can effectively use OpenSSL to secure your network communications.
|
||||
|
||||
128
09 - Linux Security Concepts/Security Tools (Fail2Ban, AIDE).md
Normal file
128
09 - Linux Security Concepts/Security Tools (Fail2Ban, AIDE).md
Normal file
@ -0,0 +1,128 @@
|
||||
# Linux Security Tools: Fail2Ban and AIDE
|
||||
|
||||
##1. Fail2Ban
|
||||
|
||||
Fail2Ban is an intrusion prevention software framework that protects Linux systems from brute-force attacks and other malicious activities.
|
||||
|
||||
### How Fail2Ban works:
|
||||
- Monitors log files for suspicious activities
|
||||
- Uses regular expressions to detect patterns indicating potential attacks
|
||||
- Temporarily or permanently bans IP addresses showing malicious behavior
|
||||
- Updates firewall rules to block banned IPs
|
||||
|
||||
### Installation:
|
||||
```bash
|
||||
sudo apt-get update
|
||||
sudo apt-get install fail2ban
|
||||
```
|
||||
|
||||
### Configuration:
|
||||
- Main configuration file: `/etc/fail2ban/jail.conf`
|
||||
- Create a local override file: `/etc/fail2ban/jail.local`
|
||||
|
||||
### Key configuration options:
|
||||
- bantime: Duration of the ban
|
||||
- findtime: Time frame for maxretry
|
||||
- maxretry: Number of failures before a ban is imposed
|
||||
|
||||
### Example configuration for SSH protection:
|
||||
```ini
|
||||
[sshd]
|
||||
enabled = true
|
||||
port = ssh
|
||||
filter = sshd
|
||||
logpath = /var/log/auth.log
|
||||
maxretry = 3
|
||||
bantime = 3600
|
||||
```
|
||||
|
||||
### Managing Fail2Ban:
|
||||
- Start/stop service: `sudo systemctl start/stop fail2ban`
|
||||
- Check status: `sudo fail2ban-client status`
|
||||
- Unban an IP: `sudo fail2ban-client set sshd unbanip <IP_ADDRESS>`
|
||||
|
||||
### Best practices:
|
||||
- Regularly update Fail2Ban
|
||||
- Customize filters for specific applications
|
||||
- Use whitelisting for trusted IP addresses
|
||||
|
||||
## 2. AIDE (Advanced Intrusion Detection Environment)
|
||||
|
||||
AIDE is a file and directory integrity checker that detects unauthorized changes to system files.
|
||||
|
||||
### How AIDE works:
|
||||
- Creates a database of file attributes (size, permissions, checksums)
|
||||
- Periodically checks files against the database
|
||||
- Reports any discrepancies, indicating potential security breaches
|
||||
|
||||
### Installation:
|
||||
```bash
|
||||
sudo apt-get update
|
||||
sudo apt-get install aide
|
||||
```
|
||||
|
||||
### Configuration:
|
||||
- Main configuration file: /etc/aide/aide.conf
|
||||
- Customize rules to monitor specific directories or files
|
||||
|
||||
### Key configuration options:
|
||||
- database_in: Path to the input database
|
||||
- database_out: Path to the output database
|
||||
- report_url: Where to send reports
|
||||
|
||||
### Example configuration:
|
||||
```ini
|
||||
/etc NORMAL
|
||||
/bin NORMAL
|
||||
/sbin NORMAL
|
||||
/var/log LOG
|
||||
```
|
||||
|
||||
### Initializing and using AIDE:
|
||||
- Initialize database: `sudo aideinit`
|
||||
- Update database: `sudo aide --update`
|
||||
- Check for changes: `sudo aide --check`
|
||||
|
||||
### Automating AIDE checks:
|
||||
- Create a cron job to run regular checks
|
||||
- Example crontab entry:
|
||||
```ini
|
||||
0 3 * * * /usr/bin/aide --check | mail -s "AIDE Report" admin@example.com
|
||||
```
|
||||
|
||||
### Best practices:
|
||||
- Store the AIDE database on read-only media
|
||||
- Regularly update the database after authorized changes
|
||||
- Review and act on AIDE reports promptly
|
||||
|
||||
## 3. Integrating Fail2Ban and AIDE
|
||||
|
||||
### Complementary security:
|
||||
- Fail2Ban prevents external attacks
|
||||
- AIDE detects internal changes and potential breaches
|
||||
|
||||
### Combined strategy:
|
||||
- Use Fail2Ban to protect against brute-force attacks
|
||||
- Employ AIDE to monitor critical system files
|
||||
- Set up alerts for both tools to promptly address security issues
|
||||
|
||||
### Monitoring and logging:
|
||||
- Configure centralized logging for both tools
|
||||
- Use log analysis tools to correlate events from Fail2Ban and AIDE
|
||||
|
||||
## 4. Additional considerations
|
||||
|
||||
### Regular updates:
|
||||
- Keep both tools and the underlying system up-to-date
|
||||
|
||||
### Testing:
|
||||
- Regularly test Fail2Ban configurations
|
||||
- Perform periodic AIDE checks and verify reports
|
||||
|
||||
### Documentation:
|
||||
- Maintain detailed documentation of configurations and changes
|
||||
|
||||
### Backup strategy:
|
||||
- Implement a robust backup strategy to recover from potential breaches
|
||||
|
||||
By implementing and properly configuring both Fail2Ban and AIDE, you can significantly enhance the security posture of your Linux systems, protecting against external threats and detecting internal changes that may indicate a compromise.
|
||||
164
09 - Linux Security Concepts/Understanding SELinux.md
Normal file
164
09 - Linux Security Concepts/Understanding SELinux.md
Normal file
@ -0,0 +1,164 @@
|
||||
# Understanding SELinux
|
||||
|
||||
## 1. Introduction to SELinux
|
||||
|
||||
SELinux is a mandatory access control (MAC) security mechanism implemented in the Linux kernel. Developed by the NSA and Red Hat, it provides an additional layer of system security to complement the traditional discretionary access control (DAC) model used in most Linux distributions.
|
||||
|
||||
Key concepts:
|
||||
- Mandatory Access Control (MAC)
|
||||
- Security policies
|
||||
- Security contexts
|
||||
- Access decisions based on security contexts
|
||||
|
||||
## 2. SELinux Modes
|
||||
|
||||
SELinux operates in three modes:
|
||||
- Enforcing: SELinux policy is enforced
|
||||
- Permissive: SELinux prints warnings but does not enforce policy
|
||||
- Disabled: SELinux is turned off
|
||||
|
||||
To check the current mode:
|
||||
```
|
||||
getenforce
|
||||
```
|
||||
|
||||
To change modes temporarily:
|
||||
```bash
|
||||
setenforce 0 # Set to permissive
|
||||
```
|
||||
```bash
|
||||
setenforce 1 # Set to enforcing
|
||||
```
|
||||
|
||||
To change modes permanently, edit /etc/selinux/config and reboot.
|
||||
|
||||
## 3. SELinux Contexts
|
||||
|
||||
SELinux assigns a context to every process, file, and system object. A context consists of four fields:
|
||||
user:role:type:level
|
||||
|
||||
Example:
|
||||
```
|
||||
system_u:object_r:httpd_sys_content_t:s0
|
||||
```
|
||||
|
||||
To view contexts:
|
||||
```
|
||||
ls -Z # For files
|
||||
ps auxZ # For processes
|
||||
```
|
||||
|
||||
## 4. SELinux Policies
|
||||
|
||||
SELinux uses policies to define allowed actions. Two main policy types:
|
||||
- Targeted (default): Focuses on protecting network daemons
|
||||
- MLS (Multi-Level Security): More complex, used in high-security environments
|
||||
|
||||
## 5. Booleans
|
||||
|
||||
Booleans are on/off switches that allow runtime customization of SELinux policies.
|
||||
|
||||
To list all booleans:
|
||||
```
|
||||
getsebool -a
|
||||
```
|
||||
|
||||
To change a boolean:
|
||||
```bash
|
||||
setsebool httpd_can_network_connect on
|
||||
```
|
||||
|
||||
To make the change persistent:
|
||||
```bash
|
||||
setsebool -P httpd_can_network_connect on
|
||||
```
|
||||
|
||||
## 6. Troubleshooting SELinux
|
||||
|
||||
- Check for denials:
|
||||
```
|
||||
ausearch -m AVC,USER_AVC,SELINUX_ERR -ts recent
|
||||
```
|
||||
|
||||
- Use SELinux troubleshooter:
|
||||
```
|
||||
sealert -a /var/log/audit/audit.log
|
||||
```
|
||||
|
||||
- Analyze SELinux logs:
|
||||
```
|
||||
grep "SELinux" /var/log/messages
|
||||
```
|
||||
|
||||
## 7. File and Directory Labeling
|
||||
|
||||
To change the SELinux context of a file or directory:
|
||||
```
|
||||
chcon -t httpd_sys_content_t /path/to/file
|
||||
```
|
||||
|
||||
To restore the default context:
|
||||
```
|
||||
restorecon -v /path/to/file
|
||||
```
|
||||
|
||||
## 8. Managing SELinux Modules
|
||||
|
||||
List available modules:
|
||||
```
|
||||
semodule -l
|
||||
```
|
||||
|
||||
Enable a module:
|
||||
```
|
||||
semodule -e modulename
|
||||
```
|
||||
|
||||
Disable a module:
|
||||
```
|
||||
semodule -d modulename
|
||||
```
|
||||
|
||||
## 9. Creating Custom SELinux Policies
|
||||
|
||||
For complex environments, you may need to create custom policies:
|
||||
|
||||
- Install policy development tools:
|
||||
```
|
||||
yum install selinux-policy-devel
|
||||
```
|
||||
|
||||
- Write a policy module (.te file)
|
||||
- Compile and package the module:
|
||||
```
|
||||
make -f /usr/share/selinux/devel/Makefile
|
||||
```
|
||||
- Install the module:
|
||||
```
|
||||
semodule -i mymodule.pp
|
||||
```
|
||||
|
||||
## 10. SELinux and Containers
|
||||
|
||||
SELinux provides strong isolation for containers:
|
||||
- Each container runs with its own SELinux context
|
||||
- Prevents container processes from accessing host resources
|
||||
|
||||
To run a container with a specific SELinux context:
|
||||
```
|
||||
docker run --security-opt label=type:svirt_lxc_net_t my_image
|
||||
```
|
||||
|
||||
## 11. Best Practices
|
||||
|
||||
- Keep SELinux enabled and in enforcing mode
|
||||
- Use SELinux booleans instead of custom policies when possible
|
||||
- Regularly review and update SELinux policies
|
||||
- Use SELinux MLS for high-security environments
|
||||
- Educate system administrators about SELinux
|
||||
|
||||
## 12. Additional Resources
|
||||
|
||||
- SELinux Project: https://github.com/SELinuxProject
|
||||
- Red Hat SELinux Guide: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/using_selinux/index
|
||||
|
||||
128
09 - Linux Security Concepts/Users and Password Security.md
Normal file
128
09 - Linux Security Concepts/Users and Password Security.md
Normal file
@ -0,0 +1,128 @@
|
||||
# Users and Password Security
|
||||
|
||||
## 1. Password Creation:
|
||||
|
||||
### Length: Use passwords of at least 12 characters. Longer passwords are generally more secure.
|
||||
|
||||
### Complexity: Include a mix of:
|
||||
- Uppercase letters
|
||||
- Lowercase letters
|
||||
- Numbers
|
||||
- Special characters
|
||||
|
||||
### Avoid common patterns:
|
||||
- Don't use keyboard patterns (e.g., qwerty)
|
||||
- Avoid sequential numbers or letters
|
||||
- Don't use personal information (birthdates, names, etc.)
|
||||
|
||||
### Use passphrases: Consider using a string of random words, which can be both long and memorable.
|
||||
|
||||
## 2. Password Management:
|
||||
|
||||
### Use a password manager:
|
||||
- LastPass, 1Password, or Bitwarden are popular options
|
||||
- Allows for unique, complex passwords for each account
|
||||
- Only requires remembering one master password
|
||||
|
||||
### Enable two-factor authentication (2FA):
|
||||
- Adds an extra layer of security beyond passwords
|
||||
- Can use authenticator apps, SMS, or physical security keys
|
||||
|
||||
### Regular password changes:
|
||||
- Change passwords periodically, especially for critical accounts
|
||||
- Immediately change passwords if a breach is suspected
|
||||
|
||||
## 3. Account Security:
|
||||
|
||||
### Use unique passwords for each account:
|
||||
- Prevents compromising multiple accounts if one is breached
|
||||
|
||||
### Monitor account activity:
|
||||
- Regularly check for suspicious logins or activities
|
||||
- Enable login notifications where available
|
||||
|
||||
### Be cautious of phishing attempts:
|
||||
- Verify email senders and website URLs
|
||||
- Don't click on suspicious links or download unknown attachments
|
||||
|
||||
## 4. Device Security:
|
||||
|
||||
### Keep software updated:
|
||||
- Regularly update operating systems and applications
|
||||
- Install security patches promptly
|
||||
|
||||
### Use antivirus and anti-malware software:
|
||||
- Keep definitions up-to-date
|
||||
- Run regular scans
|
||||
|
||||
### Enable device encryption:
|
||||
- Protects data if device is lost or stolen
|
||||
|
||||
## 5. Network Security:
|
||||
|
||||
### Use secure connections:
|
||||
- Prefer HTTPS websites
|
||||
- Be cautious on public Wi-Fi networks
|
||||
- Consider using a VPN for added security
|
||||
|
||||
### Secure your home network:
|
||||
- Use strong Wi-Fi passwords
|
||||
- Enable WPA3 encryption if available
|
||||
- Change default router passwords
|
||||
|
||||
## 6. Recovery and Backup:
|
||||
|
||||
### Set up account recovery options:
|
||||
- Add backup email addresses and phone numbers
|
||||
- Be cautious about security questions; use unique, non-guessable answers
|
||||
|
||||
### Backup important data:
|
||||
- Regularly backup to external drives or secure cloud storage
|
||||
- Test recovery processes periodically
|
||||
|
||||
## 7. Security Awareness:
|
||||
|
||||
### Stay informed about security best practices:
|
||||
- Follow reputable security blogs and news sources
|
||||
- Be aware of current threats and scams
|
||||
|
||||
### Educate others:
|
||||
- Share security knowledge with family and colleagues
|
||||
- Promote a culture of security awareness
|
||||
|
||||
## 8. Special Considerations:
|
||||
|
||||
### For businesses:
|
||||
- Implement strong access controls
|
||||
- Use role-based access to limit data exposure
|
||||
- Conduct regular security audits and penetration testing
|
||||
|
||||
### For developers:
|
||||
- Implement secure coding practices
|
||||
- Use salted hashing for storing passwords
|
||||
- Regularly update and patch dependencies
|
||||
|
||||
### For high-risk individuals:
|
||||
- Consider using hardware security keys
|
||||
- Compartmentalize digital identities
|
||||
- Be extra cautious about information sharing
|
||||
|
||||
## 9. Legal and Ethical Considerations:
|
||||
|
||||
- Comply with data protection regulations (e.g., GDPR, CCPA)
|
||||
- Respect user privacy and obtain consent for data collection
|
||||
- Have a clear policy for handling and disclosing security breaches
|
||||
|
||||
## 10. Emerging Technologies:
|
||||
|
||||
### Biometric authentication:
|
||||
- Understand the pros and cons of fingerprint, facial recognition, etc.
|
||||
- Use as part of multi-factor authentication rather than sole method
|
||||
|
||||
### Passwordless authentication:
|
||||
- Stay informed about developments in this area
|
||||
- Consider implementing when mature and appropriate
|
||||
|
||||
------
|
||||
# Remember, security is an ongoing process. Regularly review and update your security practices to stay protected against evolving threats.
|
||||
|
||||
@ -0,0 +1,165 @@
|
||||
# Container Orchestration, focusing on Kubernetes and Docker Swarm
|
||||
|
||||
## 1. Introduction to Container Orchestration
|
||||
|
||||
Container orchestration is the automated management, deployment, scaling, and networking of containerized applications. It's crucial for managing complex, distributed systems efficiently. The two most popular container orchestration platforms are Kubernetes and Docker Swarm.
|
||||
|
||||
## 2. Kubernetes
|
||||
|
||||
Kubernetes (K8s) is an open-source container orchestration platform originally developed by Google.
|
||||
|
||||
Key Concepts:
|
||||
- Pods: The smallest deployable units in Kubernetes, containing one or more containers.
|
||||
- Nodes: Physical or virtual machines running Kubernetes.
|
||||
- Cluster: A set of nodes running containerized applications managed by Kubernetes.
|
||||
- Control Plane: The set of components that manage the cluster.
|
||||
|
||||
Core Components:
|
||||
- API Server: The front-end for the Kubernetes control plane.
|
||||
- etcd: A distributed key-value store for cluster data.
|
||||
- Scheduler: Assigns pods to nodes.
|
||||
- Controller Manager: Runs controller processes.
|
||||
- Kubelet: Ensures containers are running in a pod.
|
||||
- Kube-proxy: Maintains network rules on nodes.
|
||||
|
||||
Key Features:
|
||||
- Auto-scaling
|
||||
- Self-healing
|
||||
- Service discovery and load balancing
|
||||
- Rolling updates and rollbacks
|
||||
- Secret and configuration management
|
||||
- Storage orchestration
|
||||
|
||||
### Kubernetes Architecture:
|
||||
1. Master Node (Control Plane):
|
||||
- API Server
|
||||
- Scheduler
|
||||
- Controller Manager
|
||||
- etcd
|
||||
2. Worker Nodes:
|
||||
- Kubelet
|
||||
- Kube-proxy
|
||||
- Container Runtime (e.g., Docker)
|
||||
|
||||
Kubernetes Objects:
|
||||
- Deployments
|
||||
- Services
|
||||
- ConfigMaps
|
||||
- Secrets
|
||||
- Persistent Volumes
|
||||
- Namespaces
|
||||
|
||||
## 3. Docker Swarm
|
||||
|
||||
Docker Swarm is Docker's native clustering and orchestration solution.
|
||||
|
||||
Key Concepts:
|
||||
- Swarm: A cluster of Docker nodes.
|
||||
- Node: A machine participating in the swarm (manager or worker).
|
||||
- Service: The definition of tasks to execute on nodes.
|
||||
- Task: A Docker container and the commands to run inside it.
|
||||
|
||||
Core Components:
|
||||
- Swarm Manager: Manages cluster state and dispatches units of work (tasks).
|
||||
- Worker Nodes: Execute tasks assigned by the manager.
|
||||
|
||||
Key Features:
|
||||
- Native Docker integration
|
||||
- Decentralized design
|
||||
- Declarative service model
|
||||
- Scaling
|
||||
- Desired state reconciliation
|
||||
- Multi-host networking
|
||||
- Service discovery
|
||||
- Load balancing
|
||||
- Secure by default
|
||||
- Rolling updates
|
||||
|
||||
### Docker Swarm Architecture:
|
||||
1. Manager Nodes:
|
||||
- Cluster management
|
||||
- Orchestration decisions
|
||||
- API endpoints
|
||||
2. Worker Nodes:
|
||||
- Execute containers
|
||||
|
||||
## 4. Comparison: Kubernetes vs Docker Swarm
|
||||
|
||||
### Kubernetes:
|
||||
Pros:
|
||||
- More powerful and flexible
|
||||
- Larger ecosystem and community
|
||||
- Better for complex, large-scale deployments
|
||||
- More fine-grained control
|
||||
|
||||
Cons:
|
||||
- Steeper learning curve
|
||||
- More complex setup and maintenance
|
||||
|
||||
### Docker Swarm:
|
||||
Pros:
|
||||
- Easier to set up and use
|
||||
- Tightly integrated with Docker
|
||||
- Lighter weight
|
||||
- Faster deployment for simple use cases
|
||||
|
||||
Cons:
|
||||
- Less powerful for complex scenarios
|
||||
- Smaller ecosystem and community
|
||||
|
||||
## 5. Setting Up and Using Kubernetes
|
||||
|
||||
Basic steps:
|
||||
1. Install kubectl (Kubernetes command-line tool)
|
||||
2. Set up a Kubernetes cluster (e.g., using Minikube for local development)
|
||||
3. Deploy an application:
|
||||
```
|
||||
kubectl create deployment my-app --image=my-app-image
|
||||
```
|
||||
4. Expose the deployment:
|
||||
```
|
||||
kubectl expose deployment my-app --type=LoadBalancer --port=8080
|
||||
```
|
||||
5. Scale the deployment:
|
||||
```
|
||||
kubectl scale deployment my-app --replicas=3
|
||||
```
|
||||
|
||||
## 6. Setting Up and Using Docker Swarm
|
||||
|
||||
Basic steps:
|
||||
1. Initialize a swarm:
|
||||
```
|
||||
docker swarm init
|
||||
```
|
||||
2. Join worker nodes to the swarm
|
||||
3. Deploy a service:
|
||||
```
|
||||
docker service create --name my-service my-image
|
||||
```
|
||||
4. Scale the service:
|
||||
```
|
||||
docker service scale my-service=3
|
||||
```
|
||||
|
||||
## 7. Best Practices for Container Orchestration
|
||||
|
||||
- Use declarative configuration
|
||||
- Implement proper resource management
|
||||
- Utilize health checks and self-healing capabilities
|
||||
- Implement proper logging and monitoring
|
||||
- Use secrets management for sensitive data
|
||||
- Implement proper network segmentation
|
||||
- Regularly update and patch your orchestration platform
|
||||
- Use namespaces or projects for multi-tenancy
|
||||
- Implement proper access controls and RBAC
|
||||
|
||||
## 8. Future Trends in Container Orchestration
|
||||
|
||||
- Serverless container platforms (e.g., AWS Fargate, Azure Container Instances)
|
||||
- Integration with service meshes (e.g., Istio, Linkerd)
|
||||
- Increased focus on security and compliance
|
||||
- Edge computing and IoT integration
|
||||
- AI-driven orchestration and optimization
|
||||
|
||||
This guide provides an overview of container orchestration, focusing on Kubernetes and Docker Swarm. Each platform has its strengths and is suited for different use cases. The choice between them depends on your specific requirements, scale, and complexity of your applications.
|
||||
98
10 - Containers and Vitrualization/Introduction to Docker.md
Normal file
98
10 - Containers and Vitrualization/Introduction to Docker.md
Normal file
@ -0,0 +1,98 @@
|
||||
# Docker
|
||||
|
||||
## 1. Introduction to Docker
|
||||
Docker is a platform for developing, shipping, and running applications in containers. Containers allow developers to package an application with all its dependencies and configurations, ensuring it works consistently across different environments.
|
||||
|
||||
## 2. Key Concepts
|
||||
- Container: A lightweight, standalone, executable package that includes everything needed to run an application.
|
||||
- Image: A read-only template used to create containers.
|
||||
- Dockerfile: A text file containing instructions to build a Docker image.
|
||||
- Docker Hub: A cloud-based registry for sharing and storing Docker images.
|
||||
- Docker Compose: A tool for defining and running multi-container Docker applications.
|
||||
|
||||
## 3. Installing Docker
|
||||
- For Windows and Mac: Download Docker Desktop from the official website.
|
||||
- For Linux: Use your distribution's package manager or follow the official installation guide.
|
||||
|
||||
## 4. Basic Docker Commands
|
||||
- `docker run`: Create and start a container
|
||||
- `docker pull`: Download an image from a registry
|
||||
- `docker build`: Build an image from a Dockerfile
|
||||
- `docker ps`: List running containers
|
||||
- `docker images`: List available images
|
||||
- `docker stop`: Stop a running container
|
||||
- `docker rm`: Remove a container
|
||||
- `docker rmi`: Remove an image
|
||||
|
||||
## 5. Creating a Dockerfile
|
||||
A Dockerfile typically includes:
|
||||
- Base image (`FROM`)
|
||||
- Working directory (`WORKDIR`)
|
||||
- Copying files (`COPY`)
|
||||
- Running commands (`RUN`)
|
||||
- Exposing ports (`EXPOSE`)
|
||||
- Setting environment variables (`ENV`)
|
||||
- Specifying the command to run (`CMD`)
|
||||
|
||||
Example Dockerfile:
|
||||
```dockerfile
|
||||
FROM node:14
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm install
|
||||
COPY . .
|
||||
EXPOSE 3000
|
||||
CMD ["node", "app.js"]
|
||||
```
|
||||
|
||||
## 6. Building and Running Images
|
||||
- Build: `docker build -t myapp:1.0 .`
|
||||
- Run: `docker run -p 3000:3000 myapp:1.0`
|
||||
|
||||
## 7. Docker Compose
|
||||
Docker Compose allows you to define multi-container applications in a YAML file.
|
||||
|
||||
Example docker-compose.yml:
|
||||
```yaml
|
||||
version: '3'
|
||||
services:
|
||||
web:
|
||||
build: .
|
||||
ports:
|
||||
- "3000:3000"
|
||||
db:
|
||||
image: mongo:latest
|
||||
volumes:
|
||||
- ./data:/data/db
|
||||
```
|
||||
|
||||
Run with: `docker-compose up`
|
||||
|
||||
## 8. Docker Networking
|
||||
- Bridge: Default network driver
|
||||
- Host: Removes network isolation between container and host
|
||||
- Overlay: Connects multiple Docker daemons
|
||||
- Macvlan: Assigns a MAC address to a container
|
||||
|
||||
## 9. Docker Volumes
|
||||
Volumes are used for persistent data storage:
|
||||
- Create: `docker volume create myvolume`
|
||||
- Use: `docker run -v myvolume:/app/data myapp:1.0`
|
||||
|
||||
## 10. Docker Security Best Practices
|
||||
- Use official base images
|
||||
- Scan images for vulnerabilities
|
||||
- Limit container resources
|
||||
- Use non-root users inside containers
|
||||
- Implement network segmentation
|
||||
|
||||
## 11. Docker in Production
|
||||
- Orchestration tools: Kubernetes, Docker Swarm
|
||||
- Monitoring: Prometheus, Grafana
|
||||
- Logging: ELK stack (Elasticsearch, Logstash, Kibana)
|
||||
|
||||
## 12. Advanced Topics
|
||||
- Multi-stage builds
|
||||
- Docker content trust
|
||||
- Docker registry
|
||||
- CI/CD integration
|
||||
@ -0,0 +1,129 @@
|
||||
# Kernel-based Virtual Machine (KVM) virtualization
|
||||
|
||||
## 1. Introduction to KVM
|
||||
|
||||
KVM (Kernel-based Virtual Machine) is an open-source virtualization technology built into the Linux kernel. It allows the kernel to function as a hypervisor, enabling a host machine to run multiple isolated virtual environments called virtual machines (VMs) or guests.
|
||||
|
||||
## 2. Key Features of KVM
|
||||
|
||||
- Full virtualization: KVM provides hardware-assisted virtualization using Intel VT or AMD-V technologies.
|
||||
- Scalability: Can support numerous guest VMs on a single host.
|
||||
- Security: Uses SELinux and seccomp for enhanced security.
|
||||
- Performance: Near-native performance for VMs.
|
||||
- Linux integration: Seamlessly integrates with the Linux ecosystem.
|
||||
|
||||
## 3. KVM Architecture
|
||||
|
||||
KVM consists of three main components:
|
||||
|
||||
a) A kernel module (kvm.ko) that provides the core virtualization infrastructure.
|
||||
b) A processor-specific module (kvm-intel.ko or kvm-amd.ko).
|
||||
c) QEMU for hardware emulation.
|
||||
|
||||
## 4. Hardware Requirements
|
||||
|
||||
- 64-bit x86 processor with hardware virtualization support (Intel VT-x or AMD-V)
|
||||
- Sufficient RAM and storage for host and guest systems
|
||||
- BIOS/UEFI with virtualization support enabled
|
||||
|
||||
## 5. Installation
|
||||
|
||||
On most Linux distributions, you can install KVM using the package manager:
|
||||
|
||||
```bash
|
||||
sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils
|
||||
```
|
||||
|
||||
## 6. Creating and Managing VMs
|
||||
|
||||
You can create and manage VMs using command-line tools or graphical interfaces:
|
||||
|
||||
### a) Command-line tools:
|
||||
- virsh: CLI for managing VMs
|
||||
- virt-install: For creating new VMs
|
||||
|
||||
### b) Graphical tools:
|
||||
- virt-manager: User-friendly GUI for VM management
|
||||
- Cockpit: Web-based interface for system administration, including VM management
|
||||
|
||||
## 7. Networking
|
||||
|
||||
KVM supports various networking modes:
|
||||
|
||||
- NAT (Network Address Translation)
|
||||
- Bridged networking
|
||||
- Routed networking
|
||||
- Isolated networking
|
||||
|
||||
## 8. Storage
|
||||
|
||||
KVM supports multiple storage options:
|
||||
|
||||
- Local disk storage
|
||||
- Network-attached storage (NAS)
|
||||
- Storage Area Networks (SAN)
|
||||
- Distributed storage systems (e.g., Ceph)
|
||||
|
||||
## 9. Live Migration
|
||||
|
||||
KVM supports live migration, allowing you to move running VMs between physical hosts with minimal downtime.
|
||||
|
||||
## 10. Performance Tuning
|
||||
|
||||
To optimize KVM performance:
|
||||
|
||||
- Use virtio drivers for guest I/O
|
||||
- Enable huge pages for memory management
|
||||
- Use CPU pinning to dedicate physical cores to VMs
|
||||
- Implement I/O throttling to prevent resource contention
|
||||
|
||||
## 11. Monitoring and Management
|
||||
|
||||
Tools for monitoring KVM environments:
|
||||
|
||||
- libvirt API
|
||||
- virt-top
|
||||
- Prometheus with node_exporter
|
||||
- Grafana for visualization
|
||||
|
||||
## 12. Security Considerations
|
||||
|
||||
- Use SELinux or AppArmor for mandatory access control
|
||||
- Implement network segmentation
|
||||
- Regularly update and patch both host and guest systems
|
||||
- Use secure protocols for remote management
|
||||
|
||||
## 13. Backup and Disaster Recovery
|
||||
|
||||
- Use snapshots for point-in-time backups
|
||||
- Implement regular full VM backups
|
||||
- Consider replication for critical VMs
|
||||
|
||||
## 14. Integration with Cloud Platforms
|
||||
|
||||
KVM is the foundation for many cloud platforms:
|
||||
|
||||
- OpenStack
|
||||
- oVirt
|
||||
- Proxmox VE
|
||||
|
||||
## 15. Comparison with Other Virtualization Technologies
|
||||
|
||||
KVM vs:
|
||||
- VMware vSphere: KVM is open-source and often more cost-effective
|
||||
- Xen: KVM is integrated into the Linux kernel, potentially offering better performance
|
||||
- Hyper-V: KVM provides better Linux guest support
|
||||
|
||||
## 16. Best Practices
|
||||
|
||||
- Regularly test and validate backups
|
||||
- Implement proper capacity planning
|
||||
- Use automation tools for provisioning and management
|
||||
- Keep documentation up-to-date
|
||||
|
||||
## 17. Troubleshooting
|
||||
|
||||
Common issues and solutions:
|
||||
- Performance problems: Check resource allocation and use monitoring tools
|
||||
- Boot failures: Verify VM configuration and hardware compatibility
|
||||
- Network issues: Check network configuration and firewall settings
|
||||
89
10 - Containers and Vitrualization/Linux Containers LXC.md
Normal file
89
10 - Containers and Vitrualization/Linux Containers LXC.md
Normal file
@ -0,0 +1,89 @@
|
||||
# Linux Containers (LXC)
|
||||
|
||||
Linux Containers (LXC) is a lightweight virtualization technology that allows you to run multiple isolated Linux systems on a single host. LXC provides a user-space interface for the Linux kernel containment features, enabling the creation and management of system or application containers.
|
||||
|
||||
## 1. Introduction to LXC
|
||||
LXC uses Linux kernel features such as cgroups, namespaces, and chroot to create isolated environments without the overhead of full virtualization. This makes LXC more efficient than traditional virtual machines (VMs) in terms of resource usage and startup time.
|
||||
|
||||
## 2. Key concepts
|
||||
- Container: An isolated environment that shares the host's kernel but has its own filesystem, network, and process space.
|
||||
- Template: A base image used to create new containers.
|
||||
- Backing store: The storage mechanism used for container filesystems (e.g., directories, block devices, or ZFS datasets).
|
||||
|
||||
## 3. Installation
|
||||
To install LXC on most Linux distributions:
|
||||
|
||||
```
|
||||
sudo apt-get update
|
||||
sudo apt-get install lxc lxc-templates
|
||||
```
|
||||
|
||||
## 4. Creating containers
|
||||
To create a new container:
|
||||
|
||||
```
|
||||
sudo lxc-create -n mycontainer -t download -- -d ubuntu -r focal -a amd64
|
||||
```
|
||||
|
||||
This creates a container named "mycontainer" using the Ubuntu Focal (20.04) template for amd64 architecture.
|
||||
|
||||
## 5. Managing containers
|
||||
- Start a container: `sudo lxc-start -n mycontainer`
|
||||
- Stop a container: `sudo lxc-stop -n mycontainer`
|
||||
- List containers: `sudo lxc-ls -f`
|
||||
- Enter a container: `sudo lxc-attach -n mycontainer`
|
||||
- Delete a container: `sudo lxc-destroy -n mycontainer`
|
||||
|
||||
## 6. Configuration
|
||||
LXC containers are configured using configuration files located in `/var/lib/lxc/[container-name]/config`. Common configuration options include:
|
||||
|
||||
- Network settings
|
||||
- Resource limits
|
||||
- Mount points
|
||||
- Security settings
|
||||
|
||||
## 7. Networking
|
||||
LXC supports various networking modes:
|
||||
- Bridge mode: Containers get their own IP on the host's network.
|
||||
- NAT mode: Containers use NAT to access the external network.
|
||||
- Macvlan: Containers get their own MAC address on the physical network.
|
||||
|
||||
## 8. Storage backends
|
||||
LXC supports multiple storage backends:
|
||||
- Directory-backed storage
|
||||
- LVM-backed storage
|
||||
- ZFS-backed storage
|
||||
- Btrfs-backed storage
|
||||
|
||||
## 9. Security considerations
|
||||
- Use unprivileged containers when possible
|
||||
- Implement proper network isolation
|
||||
- Regularly update container templates and the host system
|
||||
- Use AppArmor or SELinux profiles
|
||||
|
||||
## 10. Advanced features
|
||||
- Snapshots: Create point-in-time copies of containers
|
||||
- Live migration: Move running containers between hosts
|
||||
- Nesting: Run LXC containers inside other LXC containers
|
||||
|
||||
## 11. LXC vs. Docker
|
||||
While both use Linux containerization, they have different focuses:
|
||||
- LXC aims to provide a complete OS-level virtualization
|
||||
- Docker focuses on application containerization
|
||||
|
||||
## 12. Troubleshooting
|
||||
Common issues and solutions:
|
||||
- Network connectivity problems
|
||||
- Resource allocation issues
|
||||
- Permission and security constraints
|
||||
|
||||
## 13. Best practices
|
||||
- Use templates for consistent container creation
|
||||
- Implement proper monitoring and logging
|
||||
- Regularly backup container data
|
||||
- Use container orchestration for large-scale deployments
|
||||
|
||||
## 14. Integration with other tools
|
||||
- LXD: A next-generation system container manager
|
||||
- Ansible: For automating container management
|
||||
- Kubernetes: For orchestrating large numbers of containers
|
||||
@ -0,0 +1,158 @@
|
||||
# Working With Dockerfiles and Images
|
||||
|
||||
## 1. Understanding Dockerfiles
|
||||
|
||||
A Dockerfile is a text file containing instructions to build a Docker image. It automates the process of creating a consistent environment for your application.
|
||||
|
||||
Key Dockerfile instructions:
|
||||
|
||||
- FROM: Specifies the base image
|
||||
- RUN: Executes commands in the container
|
||||
- COPY/ADD: Copies files from host to container
|
||||
- WORKDIR: Sets the working directory
|
||||
- ENV: Sets environment variables
|
||||
- EXPOSE: Declares ports to be exposed
|
||||
- CMD/ENTRYPOINT: Specifies the command to run when the container starts
|
||||
|
||||
## 2. Creating a Dockerfile
|
||||
|
||||
Example Dockerfile for a Python application:
|
||||
|
||||
```dockerfile
|
||||
FROM python:3.9-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 5000
|
||||
|
||||
CMD ["python", "app.py"]
|
||||
```
|
||||
|
||||
## 3. Building Docker Images
|
||||
|
||||
To build an image from a Dockerfile:
|
||||
|
||||
```
|
||||
docker build -t myapp:v1 .
|
||||
```
|
||||
|
||||
This command builds an image named "myapp" with the tag "v1" using the Dockerfile in the current directory.
|
||||
|
||||
## 4. Managing Docker Images
|
||||
|
||||
List images:
|
||||
```
|
||||
docker images
|
||||
```
|
||||
|
||||
Remove an image:
|
||||
```
|
||||
docker rmi myapp:v1
|
||||
```
|
||||
|
||||
Tag an image:
|
||||
```
|
||||
docker tag myapp:v1 myapp:latest
|
||||
```
|
||||
|
||||
## 5. Pushing and Pulling Images
|
||||
|
||||
Push an image to a registry:
|
||||
```
|
||||
docker push username/myapp:v1
|
||||
```
|
||||
|
||||
Pull an image from a registry:
|
||||
```
|
||||
docker pull username/myapp:v1
|
||||
```
|
||||
|
||||
## 6. Multi-stage Builds
|
||||
|
||||
Multi-stage builds allow you to use multiple FROM statements in your Dockerfile. This is useful for creating smaller production images:
|
||||
|
||||
```dockerfile
|
||||
# Build stage
|
||||
FROM golang:1.16 AS builder
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
RUN go build -o myapp
|
||||
|
||||
# Production stage
|
||||
FROM alpine:3.14
|
||||
COPY --from=builder /app/myapp /usr/local/bin/
|
||||
CMD ["myapp"]
|
||||
```
|
||||
|
||||
## 7. Best Practices
|
||||
|
||||
- Use specific base image tags (e.g., python:3.9-slim instead of python:latest)
|
||||
- Minimize the number of layers by combining RUN commands
|
||||
- Use .dockerignore to exclude unnecessary files
|
||||
- Set appropriate permissions for files and directories
|
||||
- Use environment variables for configuration
|
||||
- Don't run containers as root unless necessary
|
||||
|
||||
## 8. Docker Image Inspection
|
||||
|
||||
Inspect image details:
|
||||
```
|
||||
docker inspect myapp:v1
|
||||
```
|
||||
|
||||
View image history:
|
||||
```
|
||||
docker history myapp:v1
|
||||
```
|
||||
|
||||
## 9. Optimizing Docker Images
|
||||
|
||||
- Use smaller base images when possible (e.g., alpine-based images)
|
||||
- Remove unnecessary dependencies and files
|
||||
- Use multi-stage builds to separate build and runtime environments
|
||||
- Leverage build cache by ordering Dockerfile instructions efficiently
|
||||
|
||||
## 10. Working with Docker Registries
|
||||
|
||||
- Docker Hub: Public and private repositories
|
||||
- Amazon Elastic Container Registry (ECR)
|
||||
- Google Container Registry (GCR)
|
||||
- Azure Container Registry (ACR)
|
||||
|
||||
To use a private registry, log in first:
|
||||
```
|
||||
docker login myregistry.azurecr.io
|
||||
```
|
||||
|
||||
## 11. Image Scanning and Security
|
||||
|
||||
Use tools like Docker Scan, Clair, or Trivy to scan images for vulnerabilities:
|
||||
|
||||
```
|
||||
docker scan myapp:v1
|
||||
```
|
||||
|
||||
## 12. Docker Image Versioning
|
||||
|
||||
Use semantic versioning for your images:
|
||||
- Major version: myapp:1
|
||||
- Minor version: myapp:1.2
|
||||
- Patch version: myapp:1.2.3
|
||||
|
||||
Always tag your images with a specific version and avoid using only the "latest" tag in production.
|
||||
|
||||
## 13. Dockerfile Linting
|
||||
|
||||
Use tools like Hadolint to check your Dockerfile for best practices and potential issues:
|
||||
|
||||
```
|
||||
hadolint Dockerfile
|
||||
```
|
||||
|
||||
This guide covers the essentials of working with Dockerfiles and images. As you become more comfortable with these concepts, you can explore advanced topics like Docker Compose for multi-container applications and Docker Swarm or Kubernetes for container orchestration.
|
||||
|
||||
@ -0,0 +1,174 @@
|
||||
# Building and Installing Linux Kernel Modules:
|
||||
|
||||
## 1. Introduction to Kernel Modules
|
||||
|
||||
Kernel modules are pieces of code that can be dynamically loaded and unloaded into the running kernel. They extend the functionality of the kernel without requiring a system reboot. This guide will walk you through the process of writing, building, and installing a simple kernel module.
|
||||
|
||||
## 2. Prerequisites
|
||||
|
||||
- A Linux system with kernel headers installed
|
||||
- Basic knowledge of C programming
|
||||
- GCC compiler
|
||||
- Make utility
|
||||
|
||||
To install kernel headers on Ubuntu/Debian:
|
||||
```bash
|
||||
sudo apt-get install linux-headers-$(uname -r)
|
||||
```
|
||||
|
||||
On CentOS/RHEL:
|
||||
```bash
|
||||
sudo yum install kernel-devel
|
||||
```
|
||||
|
||||
## 3. Writing a Simple Kernel Module
|
||||
|
||||
Let's create a basic "Hello World" kernel module. Create a file named `hello.c`:
|
||||
|
||||
```c
|
||||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Your Name");
|
||||
MODULE_DESCRIPTION("A simple Hello World module");
|
||||
MODULE_VERSION("0.1");
|
||||
|
||||
static int __init hello_init(void) {
|
||||
printk(KERN_INFO "Hello, World!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit hello_exit(void) {
|
||||
printk(KERN_INFO "Goodbye, World!\n");
|
||||
}
|
||||
|
||||
module_init(hello_init);
|
||||
module_exit(hello_exit);
|
||||
```
|
||||
|
||||
## 4. Creating a Makefile
|
||||
|
||||
Create a `Makefile` in the same directory:
|
||||
|
||||
```makefile
|
||||
obj-m += hello.o
|
||||
|
||||
all:
|
||||
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
|
||||
|
||||
clean:
|
||||
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
|
||||
```
|
||||
|
||||
## 5. Building the Kernel Module
|
||||
|
||||
To build the module, run:
|
||||
|
||||
```bash
|
||||
make
|
||||
```
|
||||
|
||||
This will compile your module and create a `hello.ko` file.
|
||||
|
||||
## 6. Loading and Unloading the Module
|
||||
|
||||
To load the module:
|
||||
```bash
|
||||
sudo insmod hello.ko
|
||||
```
|
||||
|
||||
To unload the module:
|
||||
```bash
|
||||
sudo rmmod hello
|
||||
```
|
||||
|
||||
To view kernel messages:
|
||||
```bash
|
||||
dmesg | tail
|
||||
```
|
||||
|
||||
## 7. Automatically Loading Modules at Boot
|
||||
|
||||
To load your module at boot time:
|
||||
|
||||
- 1. Copy the module to the kernel modules directory:
|
||||
```bash
|
||||
sudo cp hello.ko /lib/modules/$(uname -r)/
|
||||
```
|
||||
|
||||
- 2. Update the module dependencies:
|
||||
```bash
|
||||
sudo depmod
|
||||
```
|
||||
|
||||
- 3. Add the module name to `/etc/modules`:
|
||||
```bash
|
||||
echo "hello" | sudo tee -a /etc/modules
|
||||
```
|
||||
|
||||
## 8. Module Parameters
|
||||
|
||||
You can add parameters to your module for runtime configuration. Modify `hello.c`:
|
||||
|
||||
```c
|
||||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Your Name");
|
||||
MODULE_DESCRIPTION("A simple Hello World module with parameters");
|
||||
MODULE_VERSION("0.2");
|
||||
|
||||
static char *name = "world";
|
||||
module_param(name, charp, 0644);
|
||||
MODULE_PARM_DESC(name, "The name to display in /var/log/kern.log");
|
||||
|
||||
static int times = 1;
|
||||
module_param(times, int, 0644);
|
||||
MODULE_PARM_DESC(times, "The number of times to display the name");
|
||||
|
||||
static int __init hello_init(void) {
|
||||
int i;
|
||||
for (i = 0; i < times; i++) {
|
||||
printk(KERN_INFO "Hello, %s!\n", name);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit hello_exit(void) {
|
||||
printk(KERN_INFO "Goodbye, %s!\n", name);
|
||||
}
|
||||
|
||||
module_init(hello_init);
|
||||
module_exit(hello_exit);
|
||||
```
|
||||
|
||||
Now you can pass parameters when loading the module:
|
||||
```
|
||||
sudo insmod hello.ko name="Alice" times=3
|
||||
```
|
||||
|
||||
## 9. Debugging Kernel Modules
|
||||
|
||||
For debugging, you can use:
|
||||
- `printk()` for logging (view with `dmesg`)
|
||||
- Kernel's `EXPORT_SYMBOL` macro to expose symbols for debugging
|
||||
- Kernel's built-in debugger (KDB) or KGDB for remote debugging
|
||||
|
||||
## 10. Best Practices
|
||||
|
||||
- Always check return values of kernel functions
|
||||
- Use appropriate locking mechanisms for shared resources
|
||||
- Follow kernel coding style (run `scripts/checkpatch.pl` on your code)
|
||||
- Be cautious with memory allocation and deallocation
|
||||
|
||||
## 11. Distribution and Maintenance
|
||||
|
||||
- Keep your module updated with kernel changes
|
||||
- Document your module thoroughly
|
||||
- Consider submitting your module to the mainline kernel if it's widely useful
|
||||
|
||||
This guide covers the basics of kernel module development. As you advance, you'll want to explore more complex topics like device drivers, sysfs interfaces, and kernel APIs specific to your module's functionality.
|
||||
@ -0,0 +1,212 @@
|
||||
# Linux Device Driver Basics and Installation
|
||||
|
||||
## 1. Introduction to Linux Device Drivers
|
||||
|
||||
Linux device drivers are essential components of the Linux kernel that allow the operating system to communicate with hardware devices. They act as an interface between the kernel and the hardware, translating generic commands into device-specific operations.
|
||||
|
||||
## 2. Types of Linux Device Drivers
|
||||
|
||||
- Character Device Drivers: Handle devices that transfer data as a stream of characters (e.g., serial ports, keyboards).
|
||||
|
||||
- Block Device Drivers: Manage devices that transfer data in fixed-size blocks (e.g., hard drives, SSDs).
|
||||
|
||||
- Network Device Drivers: Control network interfaces and protocols.
|
||||
|
||||
## 3. Linux Driver Architecture
|
||||
|
||||
The Linux driver architecture consists of several layers:
|
||||
|
||||
- User Space: Where applications run
|
||||
- Kernel Space: Where the kernel and drivers operate
|
||||
- Hardware: The physical devices
|
||||
|
||||
Drivers typically implement a set of standard interfaces defined by the kernel, allowing uniform access to different types of hardware.
|
||||
|
||||
## 4. Key Concepts
|
||||
|
||||
- Kernel Modules: Drivers are often implemented as loadable kernel modules, which can be dynamically inserted into or removed from the running kernel.
|
||||
|
||||
- Device Files: In Linux, devices are represented as files in the /dev directory.
|
||||
|
||||
- Major and Minor Numbers: Used to identify the driver and specific device instance.
|
||||
|
||||
- ioctl(): A system call for device-specific operations.
|
||||
|
||||
- Interrupt Handling: Mechanism for devices to signal the CPU.
|
||||
|
||||
## 5. Writing a Basic Linux Driver
|
||||
|
||||
Here's a simple example of a character device driver:
|
||||
|
||||
```c
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/fs.h>
|
||||
|
||||
#define DEVICE_NAME "example_device"
|
||||
#define DEVICE_CLASS "example_class"
|
||||
|
||||
static int major_number;
|
||||
static struct class* example_class = NULL;
|
||||
static struct device* example_device = NULL;
|
||||
|
||||
static int device_open(struct inode *inode, struct file *file) {
|
||||
printk(KERN_INFO "Device opened\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int device_release(struct inode *inode, struct file *file) {
|
||||
printk(KERN_INFO "Device closed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t device_read(struct file *filp, char *buffer, size_t length, loff_t *offset) {
|
||||
printk(KERN_INFO "Read from device\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t device_write(struct file *filp, const char *buffer, size_t length, loff_t *offset) {
|
||||
printk(KERN_INFO "Write to device\n");
|
||||
return length;
|
||||
}
|
||||
|
||||
static struct file_operations fops = {
|
||||
.open = device_open,
|
||||
.release = device_release,
|
||||
.read = device_read,
|
||||
.write = device_write,
|
||||
};
|
||||
|
||||
static int __init example_init(void) {
|
||||
major_number = register_chrdev(0, DEVICE_NAME, &fops);
|
||||
if (major_number < 0) {
|
||||
printk(KERN_ALERT "Failed to register a major number\n");
|
||||
return major_number;
|
||||
}
|
||||
|
||||
example_class = class_create(THIS_MODULE, DEVICE_CLASS);
|
||||
if (IS_ERR(example_class)) {
|
||||
unregister_chrdev(major_number, DEVICE_NAME);
|
||||
printk(KERN_ALERT "Failed to create device class\n");
|
||||
return PTR_ERR(example_class);
|
||||
}
|
||||
|
||||
example_device = device_create(example_class, NULL, MKDEV(major_number, 0), NULL, DEVICE_NAME);
|
||||
if (IS_ERR(example_device)) {
|
||||
class_destroy(example_class);
|
||||
unregister_chrdev(major_number, DEVICE_NAME);
|
||||
printk(KERN_ALERT "Failed to create device\n");
|
||||
return PTR_ERR(example_device);
|
||||
}
|
||||
|
||||
printk(KERN_INFO "Example device driver loaded\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit example_exit(void) {
|
||||
device_destroy(example_class, MKDEV(major_number, 0));
|
||||
class_unregister(example_class);
|
||||
class_destroy(example_class);
|
||||
unregister_chrdev(major_number, DEVICE_NAME);
|
||||
printk(KERN_INFO "Example device driver unloaded\n");
|
||||
}
|
||||
|
||||
module_init(example_init);
|
||||
module_exit(example_exit);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Your Name");
|
||||
MODULE_DESCRIPTION("A simple example Linux device driver");
|
||||
MODULE_VERSION("0.1");
|
||||
```
|
||||
|
||||
## 6. Building the Driver
|
||||
|
||||
To build the driver, you'll need a Makefile:
|
||||
|
||||
```makefile
|
||||
obj-m += example_driver.o
|
||||
|
||||
all:
|
||||
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
|
||||
|
||||
clean:
|
||||
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
|
||||
```
|
||||
|
||||
## 7. Installing the Driver
|
||||
|
||||
- Compile the driver:
|
||||
```
|
||||
make
|
||||
```
|
||||
|
||||
- Load the module:
|
||||
```
|
||||
sudo insmod example_driver.ko
|
||||
```
|
||||
|
||||
- Verify the module is loaded:
|
||||
```
|
||||
lsmod | grep example_driver
|
||||
```
|
||||
|
||||
- Create a device file (if not automatically created):
|
||||
```
|
||||
sudo mknod /dev/example_device c <major_number> 0
|
||||
```
|
||||
|
||||
## 8. Testing the Driver
|
||||
|
||||
You can test the driver by reading from or writing to the device file:
|
||||
|
||||
```
|
||||
echo "Hello" > /dev/example_device
|
||||
cat /dev/example_device
|
||||
```
|
||||
|
||||
## 9. Uninstalling the Driver
|
||||
|
||||
To remove the driver:
|
||||
|
||||
```
|
||||
sudo rmmod example_driver
|
||||
```
|
||||
|
||||
## 10. Best Practices and Considerations
|
||||
|
||||
- Error Handling: Always check return values and handle errors gracefully.
|
||||
|
||||
- Concurrency: Use appropriate locking mechanisms for shared resources.
|
||||
|
||||
- Portability: Write code that works across different kernel versions when possible.
|
||||
|
||||
- Documentation: Thoroughly document your driver's functionality and usage.
|
||||
|
||||
- Testing: Extensively test your driver under various conditions.
|
||||
|
||||
- Security: Be aware of potential security implications, especially for drivers that interact with user space.
|
||||
|
||||
## 11. Debugging Techniques
|
||||
|
||||
- printk(): Use for logging messages to the kernel log.
|
||||
|
||||
- debugfs: A simple-to-use filesystem for debugging purposes.
|
||||
|
||||
- kgdb: Kernel debugger for source-level debugging.
|
||||
|
||||
ftrace: Kernel internal tracer for analyzing performance and behavior.
|
||||
|
||||
## 12. Advanced Topics
|
||||
|
||||
As you become more familiar with Linux device drivers, you may want to explore:
|
||||
|
||||
- DMA (Direct Memory Access)
|
||||
- Interrupt handling
|
||||
- Power management
|
||||
- PCI and USB subsystems
|
||||
- Linux Device Model
|
||||
- Kernel synchronization primitives
|
||||
|
||||
## Conclusion:
|
||||
Writing Linux device drivers requires a deep understanding of both the Linux kernel and the hardware you're interfacing with. This guide provides a starting point, but developing production-ready drivers often involves much more complexity and consideration of various edge cases and system interactions.
|
||||
138
11 - Linux Kernel and Modules/Kernel Debugging.md
Normal file
138
11 - Linux Kernel and Modules/Kernel Debugging.md
Normal file
@ -0,0 +1,138 @@
|
||||
# Kernel Debugging
|
||||
|
||||
## 1. Preparation
|
||||
|
||||
### Set up a development environment:
|
||||
- Install a Linux distribution (e.g., Ubuntu, Fedora)
|
||||
- Install essential development tools: gcc, make, binutils, etc.
|
||||
- Download kernel source code from kernel.org
|
||||
|
||||
### Configure kernel for debugging:
|
||||
- Enable CONFIG_DEBUG_INFO in kernel configuration
|
||||
- Enable CONFIG_KGDB for remote debugging
|
||||
- Enable other relevant debug options (e.g., CONFIG_DEBUG_KERNEL)
|
||||
|
||||
### Build the kernel with debug symbols:
|
||||
```bash
|
||||
make menuconfig
|
||||
make -j$(nproc)
|
||||
```
|
||||
|
||||
## 2. Kernel Debugging Techniques
|
||||
|
||||
### Printk Debugging:
|
||||
- Use printk() function to add log messages
|
||||
- Set appropriate log levels (KERN_INFO, KERN_DEBUG, etc.)
|
||||
- View logs using dmesg or /var/log/kern.log
|
||||
|
||||
### Kernel Oops and Panic Analysis:
|
||||
- Analyze oops messages in kernel logs
|
||||
- Use addr2line to translate addresses to source code lines
|
||||
- Examine call traces to identify the source of the problem
|
||||
|
||||
### KGDB (Kernel GNU Debugger):
|
||||
- Configure a serial connection or network for remote debugging
|
||||
- Set up a GDB client on the host machine
|
||||
- Connect to the target machine running the kernel
|
||||
- Set breakpoints, step through code, and examine variables
|
||||
|
||||
### Ftrace (Function Tracer):
|
||||
- Enable Ftrace in kernel configuration
|
||||
- Use trace-cmd tool to collect and analyze function call data
|
||||
- Examine function graph to understand kernel execution flow
|
||||
|
||||
### Systemtap:
|
||||
- Write custom scripts to instrument the kernel
|
||||
- Collect detailed performance data and debug information
|
||||
- Analyze complex scenarios without modifying kernel source
|
||||
|
||||
### Kernel Probes (Kprobes):
|
||||
- Insert dynamic breakpoints in the kernel
|
||||
- Gather debugging and performance information
|
||||
- Use jprobes for function entry probing and kretprobes for return probes
|
||||
|
||||
## 3. Advanced Debugging Techniques
|
||||
|
||||
### Memory Debugging:
|
||||
- Use KASAN (Kernel Address Sanitizer) to detect memory errors
|
||||
- Enable CONFIG_DEBUG_PAGEALLOC to catch use-after-free bugs
|
||||
- Utilize SLUB debug features for slab allocator issues
|
||||
|
||||
### Lockdep (Lock Dependency) Checker:
|
||||
- Enable CONFIG_PROVE_LOCKING and CONFIG_DEBUG_LOCKDEP
|
||||
- Detect potential deadlocks and incorrect locking behavior
|
||||
- Analyze lock dependency graphs
|
||||
|
||||
### RCU (Read-Copy-Update) Debugging:
|
||||
- Enable CONFIG_RCU_TRACE for RCU tracing
|
||||
- Use rcutorture module to stress-test RCU implementations
|
||||
- Analyze RCU grace period and callback execution
|
||||
|
||||
### Kernel Live Patching:
|
||||
- Use kpatch or livepatch to apply runtime fixes
|
||||
- Debug issues related to live patching mechanisms
|
||||
- Verify patch consistency and function replacement
|
||||
|
||||
## 4. Tools and Utilities
|
||||
|
||||
### Crash utility:
|
||||
- Analyze kernel core dumps
|
||||
- Examine kernel data structures and memory
|
||||
- Useful for post-mortem analysis of kernel panics
|
||||
|
||||
### Perf:
|
||||
- Profile kernel and user space performance
|
||||
- Identify hotspots and performance bottlenecks
|
||||
- Analyze hardware events and software tracepoints
|
||||
|
||||
### eBPF (extended Berkeley Packet Filter):
|
||||
- Write eBPF programs for advanced tracing and debugging
|
||||
- Use bpftrace for one-liners and short scripts
|
||||
- Develop custom eBPF tools for specific debugging needs
|
||||
|
||||
### Kdump:
|
||||
- Configure and enable kernel crash dump mechanism
|
||||
- Capture memory dumps on kernel panics
|
||||
- Analyze dumps using crash utility or GDB
|
||||
|
||||
## 5. Best Practices
|
||||
|
||||
### Use git for version control:
|
||||
- Maintain a clean development history
|
||||
- Utilize git bisect for identifying problematic commits
|
||||
|
||||
### Maintain a test environment:
|
||||
- Use virtual machines or dedicated hardware for testing
|
||||
- Set up automated testing frameworks (e.g., KernelCI)
|
||||
|
||||
### Collaborate with the community:
|
||||
- Subscribe to relevant mailing lists (e.g., LKML)
|
||||
- Share and discuss issues on appropriate forums
|
||||
- Submit well-formatted patch series for review
|
||||
|
||||
### Document your findings:
|
||||
- Maintain detailed notes of debugging sessions
|
||||
- Create reproducible test cases for bugs
|
||||
- Write clear bug reports and patch descriptions
|
||||
|
||||
## 6. Debugging Real-world Scenarios
|
||||
|
||||
### Boot issues:
|
||||
- Use early printk for early boot problems
|
||||
- Analyze initcall debugging output
|
||||
- Utilize kernel command line parameters for troubleshooting
|
||||
|
||||
### Device driver debugging:
|
||||
- Use debugfs to expose driver information
|
||||
- Implement IOCTL commands for debugging
|
||||
- Utilize kernel's tracepoints in the driver code
|
||||
|
||||
### File system issues:
|
||||
- Enable verbose mount options
|
||||
- Use debugfs to examine file system internals
|
||||
- Analyze block layer tracing for I/O related problems
|
||||
|
||||
### Network stack debugging:
|
||||
- Use network sniffer tools (e.g., tcpdump, Wireshark)
|
||||
- Enable netconsole for remote kernel debugging
|
||||
- Analyze netfilter and netlink debugging information
|
||||
@ -0,0 +1,75 @@
|
||||
# Kernel Upgrades and Patching
|
||||
|
||||
## 1. Preparation:
|
||||
|
||||
- Backup your system
|
||||
- Ensure you have enough disk space
|
||||
- Install necessary tools:
|
||||
```bash
|
||||
sudo apt-get install build-essential libncurses-dev bison flex libssl-dev libelf-dev
|
||||
```
|
||||
|
||||
## 2. Download the kernel source:
|
||||
|
||||
- Visit kernel.org
|
||||
- Download the desired version (e.g., linux-5.x.y.tar.xz)
|
||||
- Extract the archive:
|
||||
```bash
|
||||
tar xvf linux-5.x.y.tar.xz
|
||||
cd linux-5.x.y
|
||||
```
|
||||
|
||||
## 3. Apply patches (if needed):
|
||||
|
||||
- Download the patch file
|
||||
- Apply the patch:
|
||||
```bash
|
||||
patch -p1 < /path/to/patch/file
|
||||
```
|
||||
|
||||
## 4. Configure the kernel:
|
||||
|
||||
- Copy your current config:
|
||||
```bash
|
||||
cp /boot/config-$(uname -r) .config
|
||||
```
|
||||
- Make necessary changes:
|
||||
```bash
|
||||
make menuconfig
|
||||
```
|
||||
- Update the config for the new version:
|
||||
```bash
|
||||
make oldconfig
|
||||
```
|
||||
|
||||
## 5. Build the kernel:
|
||||
|
||||
```bash
|
||||
make -j$(nproc)
|
||||
```
|
||||
|
||||
## 6. Build and install modules:
|
||||
|
||||
```bash
|
||||
sudo make modules_install
|
||||
```
|
||||
|
||||
## 7. Install the kernel:
|
||||
|
||||
```bash
|
||||
sudo make install
|
||||
```
|
||||
|
||||
## 8. Update boot loader (e.g., GRUB):
|
||||
|
||||
```bash
|
||||
sudo update-grub
|
||||
```
|
||||
|
||||
## 9. Reboot and select the new kernel
|
||||
|
||||
## 10. Verify the new kernel:
|
||||
|
||||
```bash
|
||||
uname -r
|
||||
```
|
||||
154
11 - Linux Kernel and Modules/Understanding the Linux Kernel.md
Normal file
154
11 - Linux Kernel and Modules/Understanding the Linux Kernel.md
Normal file
@ -0,0 +1,154 @@
|
||||
# Understanding the Linux Kernel
|
||||
|
||||
## 1. Introduction to the Linux Kernel
|
||||
|
||||
The Linux kernel is the core component of Linux operating systems. It manages system resources, facilitates communication between hardware and software, and provides essential services to system programs and applications. Understanding the Linux kernel is crucial for system administrators, developers, and anyone interested in the inner workings of Linux-based systems.
|
||||
|
||||
## 2. Kernel Architecture
|
||||
|
||||
The Linux kernel follows a monolithic architecture with modular capabilities. Key components include:
|
||||
|
||||
- Process Management
|
||||
- Memory Management
|
||||
- File Systems
|
||||
- Device Drivers
|
||||
- Networking Stack
|
||||
- System Calls Interface
|
||||
|
||||
## 3. Process Management
|
||||
|
||||
The kernel manages processes through:
|
||||
|
||||
- Schedulers: Decides which process runs and for how long
|
||||
- Context Switching: Saves and restores process states
|
||||
- Inter-Process Communication (IPC): Allows processes to communicate and synchronize
|
||||
|
||||
### Key concepts:
|
||||
- Process states (running, waiting, stopped, zombie)
|
||||
- Process control block (PCB)
|
||||
- Threads and their implementation
|
||||
|
||||
## 4. Memory Management
|
||||
|
||||
The kernel handles memory through:
|
||||
|
||||
- Virtual Memory: Provides each process with its own address space
|
||||
- Page Tables: Maps virtual addresses to physical addresses
|
||||
- Memory Allocation: Manages physical memory and swap space
|
||||
|
||||
### Key concepts:
|
||||
- Paging and segmentation
|
||||
- Page fault handling
|
||||
- Kernel and user space separation
|
||||
|
||||
## 5. File Systems
|
||||
|
||||
Linux supports various file systems, including:
|
||||
|
||||
- Ext4: The default file system for many Linux distributions
|
||||
- Btrfs: A modern file system with advanced features
|
||||
- XFS: High-performance journaling file system
|
||||
|
||||
### Key concepts:
|
||||
- Inodes and dentries
|
||||
- Virtual File System (VFS)
|
||||
- Journaling
|
||||
|
||||
## 6. Device Drivers
|
||||
|
||||
Device drivers facilitate communication between the kernel and hardware devices. Types include:
|
||||
|
||||
- Character devices
|
||||
- Block devices
|
||||
- Network devices
|
||||
|
||||
### Key concepts:
|
||||
- Device file system (/dev)
|
||||
- Loadable kernel modules
|
||||
- Hardware abstraction layer
|
||||
|
||||
## 7. Networking Stack
|
||||
|
||||
The Linux networking stack implements various protocols and features:
|
||||
|
||||
- TCP/IP implementation
|
||||
- Socket interface
|
||||
- Network device drivers
|
||||
|
||||
### Key concepts:
|
||||
- Protocol layers (Physical, Data Link, Network, Transport, Application)
|
||||
- Network namespaces
|
||||
- Packet filtering and firewalls
|
||||
|
||||
## 8. System Calls Interface
|
||||
|
||||
System calls provide a way for user-space applications to request kernel services. Common system calls include:
|
||||
|
||||
- Process control (fork, exec, exit)
|
||||
- File operations (open, read, write, close)
|
||||
- Memory management (mmap, brk)
|
||||
|
||||
### Key concepts:
|
||||
- System call table
|
||||
- User space vs. kernel space transitions
|
||||
- POSIX compliance
|
||||
|
||||
## 9. Kernel Development and Customization
|
||||
|
||||
Understanding kernel development involves:
|
||||
|
||||
- Kernel source code structure
|
||||
- Compilation and building process
|
||||
- Kernel configuration options
|
||||
- Patching and updating the kernel
|
||||
|
||||
### Key concepts:
|
||||
- Git for kernel development
|
||||
- Kernel versioning scheme
|
||||
- Mainline vs. distribution-specific kernels
|
||||
|
||||
## 10. Kernel Debugging and Profiling
|
||||
|
||||
Tools and techniques for kernel debugging and profiling include:
|
||||
|
||||
1. printk for kernel logging
|
||||
2. Kernel debuggers (kdb, kgdb)
|
||||
3. Tracing tools (ftrace, perf)
|
||||
4. Kernel crash dumps analysis
|
||||
|
||||
## 11. Security Features
|
||||
|
||||
The Linux kernel implements various security mechanisms:
|
||||
|
||||
- Access control (DAC, capabilities)
|
||||
- SELinux and AppArmor
|
||||
- Kernel hardening techniques
|
||||
- Cryptographic API
|
||||
|
||||
## 12. Performance Tuning
|
||||
|
||||
Optimizing kernel performance involves:
|
||||
|
||||
- CPU scheduler tuning
|
||||
- Memory management optimization
|
||||
- I/O scheduler configuration
|
||||
- Network stack tuning
|
||||
|
||||
## 13. Advanced Topics
|
||||
|
||||
For a deeper understanding, explore:
|
||||
|
||||
1. Real-time extensions (PREEMPT_RT)
|
||||
2. Virtualization support (KVM)
|
||||
3. Container technologies (namespaces, cgroups)
|
||||
4. Power management and ACPI
|
||||
|
||||
## 14. Resources for Further Learning
|
||||
|
||||
To continue your journey in understanding the Linux kernel:
|
||||
|
||||
1. Online documentation: The Linux Kernel documentation [kernel.org](https://kernel.org)
|
||||
2. Mailing lists: Linux Kernel Mailing List (LKML)
|
||||
3. Source code: Explore the kernel source on [git.kernel.org](https://git.kernel.org/)
|
||||
|
||||
Understanding the Linux kernel is a vast and complex topic. This guide provides a high-level overview of the main components and concepts. To truly master the subject, hands-on experience with kernel development, debugging, and system administration is essential.
|
||||
@ -0,0 +1,112 @@
|
||||
# Advanced IPTables Configuration
|
||||
|
||||
## 1. Understanding IPTables Architecture:
|
||||
IPTables is the user-space command line utility for configuring the Linux kernel firewall. It works with chains and tables:
|
||||
|
||||
- Tables: filter, nat, mangle, raw, security
|
||||
- Chains: INPUT, OUTPUT, FORWARD, PREROUTING, POSTROUTING
|
||||
|
||||
## 2. Basic Syntax:
|
||||
```
|
||||
iptables [-t table] command chain rule-specification [options]
|
||||
```
|
||||
|
||||
## 3. Common Commands:
|
||||
- -A: Append rule
|
||||
- -I: Insert rule
|
||||
- -D: Delete rule
|
||||
- -R: Replace rule
|
||||
- -L: List rules
|
||||
- -F: Flush rules
|
||||
|
||||
## 4. Advanced Rule Specifications:
|
||||
|
||||
- a) State Matching:
|
||||
```
|
||||
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
|
||||
```
|
||||
|
||||
- b) Rate Limiting:
|
||||
```
|
||||
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --set
|
||||
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 4 -j DROP
|
||||
```
|
||||
|
||||
- c) String Matching:
|
||||
```
|
||||
iptables -A INPUT -p tcp --dport 80 -m string --string "GET /admin" --algo bm -j DROP
|
||||
```
|
||||
|
||||
- d) Time-based Rules:
|
||||
```
|
||||
iptables -A INPUT -p tcp --dport 80 -m time --timestart 09:00 --timestop 18:00 --weekdays Mon,Tue,Wed,Thu,Fri -j ACCEPT
|
||||
```
|
||||
|
||||
## 5. NAT Configuration:
|
||||
|
||||
- a) SNAT (Source NAT):
|
||||
```
|
||||
iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 203.0.113.1
|
||||
```
|
||||
|
||||
- b) DNAT (Destination NAT):
|
||||
```
|
||||
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.100:8080
|
||||
```
|
||||
|
||||
- c) Port Forwarding:
|
||||
```
|
||||
iptables -t nat -A PREROUTING -p tcp --dport 22 -j REDIRECT --to-port 2222
|
||||
```
|
||||
|
||||
## 6. Logging:
|
||||
```
|
||||
iptables -A INPUT -j LOG --log-prefix "DROPPED: " --log-level 4
|
||||
```
|
||||
|
||||
## 7. Custom Chains:
|
||||
```
|
||||
iptables -N CUSTOM_CHAIN
|
||||
iptables -A INPUT -j CUSTOM_CHAIN
|
||||
iptables -A CUSTOM_CHAIN -p tcp --dport 80 -j ACCEPT
|
||||
```
|
||||
|
||||
## 8. IPv6 Support (ip6tables):
|
||||
```
|
||||
ip6tables -A INPUT -p ipv6-icmp -j ACCEPT
|
||||
```
|
||||
|
||||
## 9. Saving and Restoring Rules:
|
||||
```
|
||||
iptables-save > /etc/iptables/rules.v4
|
||||
iptables-restore < /etc/iptables/rules.v4
|
||||
```
|
||||
|
||||
## 10. Performance Optimization:
|
||||
- Use stateful filtering
|
||||
- Organize rules from most to least used
|
||||
- Use custom chains for logical grouping
|
||||
|
||||
## 11. Security Best Practices:
|
||||
- Default deny policy
|
||||
- Allow only necessary services
|
||||
- Use connection tracking
|
||||
- Implement egress filtering
|
||||
|
||||
## 12. Troubleshooting:
|
||||
- Use `-v` for verbose output
|
||||
- Check logs in `/var/log/messages` or `/var/log/syslog`
|
||||
- Use `tcpdump` for packet analysis
|
||||
|
||||
## 13. Advanced Techniques:
|
||||
- Layer 7 filtering with `iptables` extensions
|
||||
- Geolocation-based filtering using `geoip` module
|
||||
- Integration with fail2ban for dynamic IP blocking
|
||||
|
||||
## 14. Scripting and Automation:
|
||||
- Create shell scripts for complex rule sets
|
||||
- Use configuration management tools (Ansible, Puppet) for deployment
|
||||
|
||||
## 15. Monitoring and Reporting:
|
||||
- Use `iptables -L -v -n` for rule hit counts
|
||||
- Implement log analysis tools (ELK stack, Splunk) for insights
|
||||
@ -0,0 +1,163 @@
|
||||
# Configuring DHCP, DNS, and NAT
|
||||
|
||||
## 1. DHCP (Dynamic Host Configuration Protocol)
|
||||
|
||||
DHCP is used to automatically assign IP addresses and network configuration to devices on a network. In Linux, we typically use the ISC DHCP server.
|
||||
|
||||
### Installation:
|
||||
```
|
||||
sudo apt-get install isc-dhcp-server
|
||||
```
|
||||
|
||||
### Configuration:
|
||||
Edit the main configuration file `/etc/dhcp/dhcpd.conf`:
|
||||
|
||||
```
|
||||
subnet 192.168.1.0 netmask 255.255.255.0 {
|
||||
range 192.168.1.100 192.168.1.200;
|
||||
option routers 192.168.1.1;
|
||||
option domain-name-servers 8.8.8.8, 8.8.4.4;
|
||||
default-lease-time 600;
|
||||
max-lease-time 7200;
|
||||
}
|
||||
```
|
||||
|
||||
This configuration:
|
||||
- Defines a subnet
|
||||
- Sets the IP range for DHCP clients
|
||||
- Specifies the router (gateway)
|
||||
- Sets DNS servers
|
||||
- Configures lease times
|
||||
|
||||
### Start the DHCP server:
|
||||
```
|
||||
sudo systemctl start isc-dhcp-server
|
||||
```
|
||||
|
||||
### Enable it to start on boot:
|
||||
```
|
||||
sudo systemctl enable isc-dhcp-server
|
||||
```
|
||||
|
||||
## 2. DNS (Domain Name System)
|
||||
|
||||
For DNS, we'll use BIND (Berkeley Internet Name Domain).
|
||||
|
||||
### Installation:
|
||||
```
|
||||
sudo apt-get install bind9
|
||||
```
|
||||
|
||||
### Configuration:
|
||||
Edit the main configuration file `/etc/bind/named.conf.options`:
|
||||
|
||||
```
|
||||
options {
|
||||
directory "/var/cache/bind";
|
||||
forwarders {
|
||||
8.8.8.8;
|
||||
8.8.4.4;
|
||||
};
|
||||
dnssec-validation auto;
|
||||
auth-nxdomain no;
|
||||
listen-on-v6 { any; };
|
||||
};
|
||||
```
|
||||
|
||||
This configuration sets up BIND to forward DNS queries to Google's DNS servers.
|
||||
|
||||
For a local zone, edit `/etc/bind/named.conf.local`:
|
||||
|
||||
```
|
||||
zone "example.com" {
|
||||
type master;
|
||||
file "/etc/bind/db.example.com";
|
||||
};
|
||||
```
|
||||
|
||||
### Then create the zone file `/etc/bind/db.example.com`:
|
||||
|
||||
```
|
||||
$TTL 604800
|
||||
@ IN SOA ns1.example.com. admin.example.com. (
|
||||
3 ; Serial
|
||||
604800 ; Refresh
|
||||
86400 ; Retry
|
||||
2419200 ; Expire
|
||||
604800 ) ; Negative Cache TTL
|
||||
;
|
||||
@ IN NS ns1.example.com.
|
||||
@ IN A 192.168.1.10
|
||||
ns1 IN A 192.168.1.10
|
||||
www IN A 192.168.1.20
|
||||
```
|
||||
|
||||
### Restart BIND:
|
||||
```
|
||||
sudo systemctl restart bind9
|
||||
```
|
||||
|
||||
## 3. NAT (Network Address Translation)
|
||||
|
||||
NAT is typically configured using iptables in Linux.
|
||||
|
||||
### First, enable IP forwarding:
|
||||
```
|
||||
echo 1 > /proc/sys/net/ipv4/ip_forward
|
||||
```
|
||||
|
||||
### To make this permanent, edit `/etc/sysctl.conf`:
|
||||
```
|
||||
net.ipv4.ip_forward=1
|
||||
```
|
||||
|
||||
### Configure NAT with iptables:
|
||||
```
|
||||
# Clear existing rules
|
||||
iptables -F
|
||||
iptables -t nat -F
|
||||
|
||||
# Set default policies
|
||||
iptables -P INPUT DROP
|
||||
iptables -P FORWARD DROP
|
||||
iptables -P OUTPUT ACCEPT
|
||||
|
||||
# Allow established connections
|
||||
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
|
||||
|
||||
# Allow internal network to access external network
|
||||
iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
|
||||
|
||||
# NAT configuration
|
||||
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
|
||||
|
||||
# Allow incoming SSH (adjust as needed)
|
||||
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
|
||||
```
|
||||
|
||||
### This configuration:
|
||||
- Clears existing rules
|
||||
- Sets default policies
|
||||
- Allows established connections
|
||||
- Permits internal to external network access
|
||||
- Sets up NAT
|
||||
- Allows incoming SSH connections
|
||||
|
||||
### Save the iptables rules:
|
||||
```
|
||||
sudo iptables-save > /etc/iptables.rules
|
||||
```
|
||||
|
||||
### To load these rules on boot, create a file `/etc/network/if-pre-up.d/iptables` with:
|
||||
|
||||
```
|
||||
#!/bin/sh
|
||||
iptables-restore < /etc/iptables.rules
|
||||
```
|
||||
|
||||
### Make it executable:
|
||||
```
|
||||
chmod +x /etc/network/if-pre-up.d/iptables
|
||||
```
|
||||
|
||||
This guide provides a basic setup for DHCP, DNS, and NAT on a Linux system. Remember to adjust IP addresses, interface names, and other specifics to match your network setup. Also, ensure you have the necessary permissions and consider security implications when configuring these services.
|
||||
@ -0,0 +1,185 @@
|
||||
# Configuring VPNs and Tunnels
|
||||
|
||||
## 1. Understanding VPNs and Tunnels
|
||||
|
||||
VPNs (Virtual Private Networks) and tunnels are technologies used to create secure, encrypted connections over a public network. They're essential for maintaining privacy, bypassing geographical restrictions, and securing communications.
|
||||
|
||||
## 2. Types of VPNs and Tunnels in Linux
|
||||
|
||||
- a) OpenVPN
|
||||
- b) WireGuard
|
||||
- c) IPsec/L2TP
|
||||
- d) PPTP (less secure, not recommended for sensitive data)
|
||||
- e) SSH Tunnels
|
||||
|
||||
3. OpenVPN Configuration
|
||||
|
||||
OpenVPN is one of the most popular and secure VPN solutions for Linux.
|
||||
|
||||
Installation:
|
||||
```
|
||||
sudo apt-get update
|
||||
sudo apt-get install openvpn
|
||||
```
|
||||
|
||||
Configuration:
|
||||
1. Obtain .ovpn configuration file from your VPN provider
|
||||
2. Move the .ovpn file to /etc/openvpn/
|
||||
3. Connect using:
|
||||
```
|
||||
sudo openvpn --config /etc/openvpn/your-config-file.ovpn
|
||||
```
|
||||
|
||||
For automatic connection on boot:
|
||||
1. Rename your .ovpn file to client.conf
|
||||
2. Move it to /etc/openvpn/
|
||||
## 3. Enable the OpenVPN service:
|
||||
```
|
||||
sudo systemctl enable openvpn@client
|
||||
sudo systemctl start openvpn@client
|
||||
```
|
||||
|
||||
## 4. WireGuard Configuration
|
||||
|
||||
WireGuard is a newer, high-performance VPN protocol.
|
||||
|
||||
Installation:
|
||||
```
|
||||
sudo apt-get update
|
||||
sudo apt-get install wireguard
|
||||
```
|
||||
|
||||
### Configuration:
|
||||
- 1. Generate private and public keys:
|
||||
```
|
||||
wg genkey | tee privatekey | wg pubkey > publickey
|
||||
```
|
||||
- 2. Create a configuration file /etc/wireguard/wg0.conf:
|
||||
```
|
||||
[Interface]
|
||||
PrivateKey = your_private_key
|
||||
Address = 10.0.0.2/24
|
||||
DNS = 1.1.1.1
|
||||
|
||||
[Peer]
|
||||
PublicKey = server_public_key
|
||||
Endpoint = server_ip:51820
|
||||
AllowedIPs = 0.0.0.0/0
|
||||
```
|
||||
- 3. Start WireGuard:
|
||||
```
|
||||
sudo wg-quick up wg0
|
||||
```
|
||||
|
||||
## 5. IPsec/L2TP Configuration
|
||||
|
||||
IPsec/L2TP is widely supported and offers good security.
|
||||
|
||||
### Installation:
|
||||
```
|
||||
sudo apt-get update
|
||||
sudo apt-get install strongswan xl2tpd
|
||||
```
|
||||
|
||||
### Configuration:
|
||||
- 1. Edit /etc/ipsec.conf:
|
||||
```
|
||||
conn VPN
|
||||
keyexchange=ikev1
|
||||
authby=secret
|
||||
ike=aes128-sha1-modp1024!
|
||||
esp=aes128-sha1!
|
||||
left=%defaultroute
|
||||
leftprotoport=17/1701
|
||||
right=your_vpn_server_ip
|
||||
rightprotoport=17/1701
|
||||
auto=add
|
||||
```
|
||||
- 2. Edit /etc/ipsec.secrets:
|
||||
```
|
||||
: PSK "your_preshared_key"
|
||||
```
|
||||
- 3. Edit /etc/xl2tpd/xl2tpd.conf:
|
||||
```
|
||||
[lac vpn-connection]
|
||||
lns = your_vpn_server_ip
|
||||
ppp debug = yes
|
||||
pppoptfile = /etc/ppp/options.l2tpd.client
|
||||
length bit = yes
|
||||
```
|
||||
- 4. Create /etc/ppp/options.l2tpd.client:
|
||||
```
|
||||
ipcp-accept-local
|
||||
ipcp-accept-remote
|
||||
refuse-eap
|
||||
require-mschap-v2
|
||||
noccp
|
||||
noauth
|
||||
idle 1800
|
||||
mtu 1410
|
||||
mru 1410
|
||||
defaultroute
|
||||
usepeerdns
|
||||
debug
|
||||
connect-delay 5000
|
||||
name your_username
|
||||
password your_password
|
||||
```
|
||||
- 5. Start the services:
|
||||
```
|
||||
sudo systemctl restart strongswan
|
||||
sudo systemctl restart xl2tpd
|
||||
```
|
||||
|
||||
## 6. SSH Tunnels
|
||||
|
||||
SSH tunnels are versatile for creating encrypted connections.
|
||||
|
||||
### Local port forwarding:
|
||||
```
|
||||
ssh -L local_port:remote_host:remote_port username@ssh_server
|
||||
```
|
||||
|
||||
### Remote port forwarding:
|
||||
```
|
||||
ssh -R remote_port:local_host:local_port username@ssh_server
|
||||
```
|
||||
|
||||
### Dynamic port forwarding (SOCKS proxy):
|
||||
```
|
||||
ssh -D local_port username@ssh_server
|
||||
```
|
||||
|
||||
## 7. Troubleshooting and Verification
|
||||
|
||||
- Check connection status:
|
||||
```
|
||||
ip addr show
|
||||
```
|
||||
- Verify DNS resolution:
|
||||
```
|
||||
nslookup example.com
|
||||
```
|
||||
- Check for IP leaks:
|
||||
```
|
||||
curl ifconfig.me
|
||||
```
|
||||
- Monitor VPN logs:
|
||||
```
|
||||
sudo journalctl -u openvpn
|
||||
```
|
||||
|
||||
## 8. Security Considerations
|
||||
|
||||
- Keep your system and VPN software updated
|
||||
- Use strong authentication methods (certificates, 2FA)
|
||||
- Implement a kill switch to prevent data leaks if the VPN disconnects
|
||||
- Regularly audit your VPN configurations
|
||||
- Use perfect forward secrecy (PFS) when available
|
||||
|
||||
## 9. Performance Optimization
|
||||
|
||||
- Choose nearby servers for better latency
|
||||
- Experiment with different protocols (e.g., UDP vs TCP)
|
||||
- Adjust MTU settings if needed
|
||||
- Consider using split-tunneling for non-sensitive traffic
|
||||
146
12 - Network Configuration and Troubleshooting/IP Routing.md
Normal file
146
12 - Network Configuration and Troubleshooting/IP Routing.md
Normal file
@ -0,0 +1,146 @@
|
||||
# IP Routing
|
||||
|
||||
## 1. Fundamentals of IP Routing in Linux
|
||||
|
||||
IP routing is the process of forwarding IP packets from one network to another. In Linux, the kernel is responsible for routing decisions based on the routing table.
|
||||
|
||||
Key concepts:
|
||||
- IP address
|
||||
- Subnet mask
|
||||
- Default gateway
|
||||
- Routing table
|
||||
|
||||
## 2. The Linux Routing Table
|
||||
|
||||
The routing table is a data structure in the Linux kernel that stores routing information. You can view it using the `route` or `ip route` commands.
|
||||
|
||||
Example:
|
||||
```
|
||||
$ ip route show
|
||||
default via 192.168.1.1 dev eth0
|
||||
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100
|
||||
```
|
||||
|
||||
## 3. Basic Routing Commands
|
||||
|
||||
- a) Adding a route:
|
||||
```
|
||||
ip route add 10.0.0.0/24 via 192.168.1.254
|
||||
```
|
||||
|
||||
- b) Deleting a route:
|
||||
```
|
||||
ip route del 10.0.0.0/24
|
||||
```
|
||||
|
||||
- c) Adding a default gateway:
|
||||
```
|
||||
ip route add default via 192.168.1.1
|
||||
```
|
||||
|
||||
## 4. Network Interfaces
|
||||
|
||||
Linux treats network interfaces as the point where IP packets enter or leave the system. Common types include:
|
||||
- Ethernet (eth0, eth1)
|
||||
- Wireless (wlan0)
|
||||
- Loopback (lo)
|
||||
|
||||
You can view and configure interfaces using the `ip link` and `ip addr` commands.
|
||||
|
||||
## 5. IP Forwarding
|
||||
|
||||
To use a Linux system as a router, you need to enable IP forwarding:
|
||||
|
||||
```
|
||||
echo 1 > /proc/sys/net/ipv4/ip_forward
|
||||
```
|
||||
|
||||
To make this permanent, edit `/etc/sysctl.conf`:
|
||||
```
|
||||
net.ipv4.ip_forward = 1
|
||||
```
|
||||
|
||||
## 6. Policy-Based Routing
|
||||
|
||||
Linux supports policy-based routing, allowing you to make routing decisions based on criteria other than the destination address.
|
||||
|
||||
Key components:
|
||||
- Multiple routing tables
|
||||
- Rules for selecting tables
|
||||
|
||||
Example of creating a new routing table:
|
||||
```
|
||||
echo "200 custom" >> /etc/iproute2/rt_tables
|
||||
ip route add default via 10.0.0.1 table custom
|
||||
ip rule add from 192.168.1.0/24 table custom
|
||||
```
|
||||
|
||||
## 7. Dynamic Routing Protocols
|
||||
|
||||
For larger networks, dynamic routing protocols are essential. Linux supports various routing daemons:
|
||||
|
||||
- Quagga: Supports OSPF, BGP, RIP
|
||||
- BIRD: Lightweight routing daemon for IPv4 and IPv6
|
||||
- FRRouting: Fork of Quagga with additional features
|
||||
|
||||
## 8. Netfilter and iptables
|
||||
|
||||
While primarily used for firewalling, iptables can also influence routing decisions:
|
||||
|
||||
- DNAT (Destination NAT) for port forwarding
|
||||
- SNAT (Source NAT) for masquerading
|
||||
|
||||
Example of DNAT:
|
||||
```
|
||||
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.1.100:8080
|
||||
```
|
||||
|
||||
## 9. Advanced Routing Features
|
||||
|
||||
- a) Equal-Cost Multipath (ECMP) Routing:
|
||||
```
|
||||
ip route add default equalize nexthop via 192.168.1.1 weight 1 nexthop via 192.168.1.2 weight 1
|
||||
```
|
||||
|
||||
- b) Source-based routing:
|
||||
```
|
||||
ip route add 10.0.0.0/24 via 192.168.1.1 src 192.168.1.100
|
||||
```
|
||||
|
||||
## 10. Troubleshooting and Monitoring
|
||||
|
||||
Essential tools for diagnosing routing issues:
|
||||
- traceroute / tracepath
|
||||
- ping
|
||||
- mtr (My TraceRoute)
|
||||
- tcpdump
|
||||
- netstat / ss
|
||||
|
||||
Example of using tcpdump to monitor routing:
|
||||
```
|
||||
tcpdump -i eth0 icmp
|
||||
```
|
||||
|
||||
## 11. IPv6 Routing
|
||||
|
||||
Most of the concepts apply to IPv6 as well, with some differences:
|
||||
- Use of link-local addresses
|
||||
- Neighbor Discovery Protocol (NDP) instead of ARP
|
||||
- Different address notation
|
||||
|
||||
Example of adding an IPv6 route:
|
||||
```
|
||||
ip -6 route add 2001:db8::/64 via fe80::1 dev eth0
|
||||
```
|
||||
|
||||
## 12. Kernel Tuning for Routing Performance
|
||||
|
||||
You can optimize the kernel for routing performance by adjusting sysctl parameters:
|
||||
|
||||
```
|
||||
net.ipv4.ip_forward = 1
|
||||
net.ipv4.conf.all.rp_filter = 1
|
||||
net.ipv4.tcp_syncookies = 1
|
||||
```
|
||||
|
||||
This guide covers the core concepts and practical aspects of IP routing in Linux. Would you like me to elaborate on any specific area or provide more examples?
|
||||
@ -0,0 +1,122 @@
|
||||
# Network Troubleshooting (netstat)
|
||||
|
||||
Netstat (Network Statistics) is a powerful command-line tool used for monitoring network connections, routing tables, interface statistics, and more. It's an essential utility for network administrators and system troubleshooters.
|
||||
|
||||
## 1. Basic Usage:
|
||||
The basic syntax for netstat is:
|
||||
```
|
||||
netstat [options]
|
||||
```
|
||||
|
||||
## 2. Common Options:
|
||||
|
||||
- a) -a: Show all sockets (listening and non-listening)
|
||||
- b) -t: Display TCP connections
|
||||
- c) -u: Display UDP connections
|
||||
- d) -n: Show numerical addresses and port numbers instead of hostnames
|
||||
- e) -p: Show the PID and name of the program to which each socket belongs
|
||||
- f) -r: Display the routing table
|
||||
- g) -i: Show network interface statistics
|
||||
- h) -s: Display summary statistics for each protocol
|
||||
|
||||
## 3. Useful Combinations:
|
||||
|
||||
### a) View all TCP connections:
|
||||
```
|
||||
netstat -at
|
||||
```
|
||||
|
||||
### b) View all UDP connections:
|
||||
```
|
||||
netstat -au
|
||||
```
|
||||
|
||||
### c) View all listening ports:
|
||||
```
|
||||
netstat -l
|
||||
```
|
||||
|
||||
### d) View all established connections:
|
||||
```
|
||||
netstat -tun
|
||||
```
|
||||
|
||||
### e) View processes using network connections:
|
||||
```
|
||||
sudo netstat -tunapl
|
||||
```
|
||||
|
||||
## 4. Interpreting Output:
|
||||
|
||||
The output of netstat typically includes the following columns:
|
||||
|
||||
- Proto: The protocol used (TCP, UDP, etc.)
|
||||
- Recv-Q: The count of bytes not copied by the user program connected to this socket
|
||||
- Send-Q: The count of bytes not acknowledged by the remote host
|
||||
- Local Address: The local end of the socket
|
||||
- Foreign Address: The remote end of the socket
|
||||
- State: The state of the socket (e.g., ESTABLISHED, LISTEN, TIME_WAIT)
|
||||
|
||||
## 5. Advanced Usage:
|
||||
|
||||
### a) Continuous monitoring:
|
||||
```
|
||||
netstat -c
|
||||
```
|
||||
This will display the output every second.
|
||||
|
||||
### b) Display statistics for specific protocols:
|
||||
```
|
||||
netstat -s --tcp
|
||||
netstat -s --udp
|
||||
```
|
||||
|
||||
### c) Show network interface statistics:
|
||||
```
|
||||
netstat -i
|
||||
```
|
||||
|
||||
### d) Display the routing table:
|
||||
```
|
||||
netstat -r
|
||||
```
|
||||
|
||||
## 6. Troubleshooting Scenarios:
|
||||
|
||||
- a) Identifying port conflicts:
|
||||
Use `netstat -tuln` to see which ports are in use and by which processes.
|
||||
|
||||
- b) Checking for listening services:
|
||||
`netstat -tln` shows all TCP ports in LISTEN state.
|
||||
|
||||
- c) Investigating high network usage:
|
||||
Use `netstat -i` to check interface statistics and identify interfaces with high traffic.
|
||||
|
||||
- d) Analyzing connection states:
|
||||
`netstat -ant | awk '{print $6}' | sort | uniq -c | sort -n` gives a count of connections in each state.
|
||||
|
||||
- e) Finding which process is using a specific port:
|
||||
```
|
||||
sudo netstat -tulnp | grep :80
|
||||
```
|
||||
This example checks which process is using port 80.
|
||||
|
||||
## 7. Alternatives to netstat:
|
||||
|
||||
While netstat is powerful, some modern Linux distributions are moving towards newer tools:
|
||||
|
||||
- ss: A more performant replacement for netstat
|
||||
- ip: A replacement for several networking tools, including some netstat functionality
|
||||
|
||||
## 8. Security Considerations:
|
||||
|
||||
- Running netstat with sudo privileges can reveal sensitive information about running processes and open ports.
|
||||
- Be cautious when sharing netstat output, as it may contain information useful to potential attackers.
|
||||
|
||||
## 9. Tips for Effective Use:
|
||||
|
||||
- Combine netstat with other tools like grep, awk, and sort for more powerful analysis.
|
||||
- Use the -c option for real-time monitoring during troubleshooting.
|
||||
- Familiarize yourself with normal network patterns on your system to more easily spot anomalies.
|
||||
|
||||
Understanding and effectively using netstat can significantly enhance your ability to troubleshoot network issues, monitor system performance, and maintain network security on Linux systems.
|
||||
@ -0,0 +1,128 @@
|
||||
# Network Troubleshooting (Nmap)
|
||||
|
||||
Nmap (Network Mapper) is a powerful open-source tool for network discovery and security auditing. It's essential for network administrators and security professionals. This guide will cover various aspects of using Nmap for network troubleshooting.
|
||||
|
||||
## 1. Basic Nmap Usage
|
||||
|
||||
Syntax: nmap [scan type] [options] {target}
|
||||
|
||||
Example: nmap 192.168.1.1
|
||||
|
||||
This performs a basic scan on the specified IP address.
|
||||
|
||||
## 2. Common Scan Types
|
||||
|
||||
- a) TCP SYN Scan (-sS): Default scan type, relatively stealthy.
|
||||
nmap -sS 192.168.1.1
|
||||
|
||||
- b) TCP Connect Scan (-sT): Full TCP handshake, less stealthy but more reliable.
|
||||
nmap -sT 192.168.1.1
|
||||
|
||||
- c) UDP Scan (-sU): Scan UDP ports.
|
||||
nmap -sU 192.168.1.1
|
||||
|
||||
- d) Ping Scan (-sn): Determine which hosts are online without port scanning.
|
||||
nmap -sn 192.168.1.0/24
|
||||
|
||||
## 3. Port Specification
|
||||
|
||||
- a) Scan specific ports:
|
||||
nmap -p 80,443,8080 192.168.1.1
|
||||
|
||||
- b) Scan top N ports:
|
||||
nmap --top-ports 100 192.168.1.1
|
||||
|
||||
- c) Scan all 65535 ports:
|
||||
nmap -p- 192.168.1.1
|
||||
|
||||
## 4. OS and Version Detection
|
||||
|
||||
- a) OS Detection:
|
||||
nmap -O 192.168.1.1
|
||||
|
||||
- b) Version Detection:
|
||||
nmap -sV 192.168.1.1
|
||||
|
||||
- c) Combine OS and Version Detection:
|
||||
nmap -A 192.168.1.1
|
||||
|
||||
## 5. Output Options
|
||||
|
||||
- a) Save output to a file:
|
||||
nmap -oN output.txt 192.168.1.1
|
||||
|
||||
- b) Save in XML format:
|
||||
nmap -oX output.xml 192.168.1.1
|
||||
|
||||
- c) Save in all major formats:
|
||||
nmap -oA output 192.168.1.1
|
||||
|
||||
## 6. Timing and Performance
|
||||
|
||||
Nmap has predefined timing templates from T0 (slowest) to T5 (fastest):
|
||||
nmap -T4 192.168.1.1
|
||||
|
||||
## 7. Firewall/IDS Evasion Techniques
|
||||
|
||||
- a) Fragment packets:
|
||||
nmap -f 192.168.1.1
|
||||
|
||||
- b) Use a decoy:
|
||||
nmap -D RND:10 192.168.1.1
|
||||
|
||||
- c) Spoof MAC address:
|
||||
nmap --spoof-mac 00:11:22:33:44:55 192.168.1.1
|
||||
|
||||
## 8. Script Engine
|
||||
|
||||
Nmap has a powerful scripting engine for advanced tasks:
|
||||
|
||||
- a) Use default scripts:
|
||||
nmap -sC 192.168.1.1
|
||||
|
||||
- b) Run specific scripts:
|
||||
nmap --script=http-title 192.168.1.1
|
||||
|
||||
- c) Update script database:
|
||||
nmap --script-updatedb
|
||||
|
||||
## 9. Troubleshooting Specific Issues
|
||||
|
||||
- a) Checking for open ports:
|
||||
nmap -p- 192.168.1.1
|
||||
|
||||
- b) Identifying services running on non-standard ports:
|
||||
nmap -sV -p- 192.168.1.1
|
||||
|
||||
- c) Detecting potential vulnerabilities:
|
||||
nmap --script vuln 192.168.1.1
|
||||
|
||||
- d) Checking for misconfigured firewalls:
|
||||
nmap -sA 192.168.1.1
|
||||
|
||||
- e) Identifying live hosts on a network:
|
||||
nmap -sn 192.168.1.0/24
|
||||
|
||||
## 10. Best Practices
|
||||
|
||||
- Always obtain permission before scanning networks you don't own.
|
||||
- Use less intrusive scans first, then progress to more comprehensive scans.
|
||||
- Regularly update Nmap to get the latest features and security updates.
|
||||
- Combine Nmap with other tools for a comprehensive network analysis.
|
||||
- Document your findings and create baseline scans for future comparison.
|
||||
|
||||
## 11. Advanced Techniques
|
||||
|
||||
- a) Scan using IPv6:
|
||||
nmap -6 2001:db8::1
|
||||
|
||||
- b) Perform a traceroute:
|
||||
nmap --traceroute 192.168.1.1
|
||||
|
||||
- c) Scan through a proxy:
|
||||
nmap --proxy socks4://proxy-server:1080 192.168.1.1
|
||||
|
||||
- d) Aggressive scan (combines OS detection, version scanning, script scanning, and traceroute):
|
||||
nmap -A 192.168.1.1
|
||||
|
||||
By mastering these Nmap techniques, you can effectively troubleshoot various network issues, from connectivity problems to security vulnerabilities. Remember to use Nmap responsibly and ethically, always respecting network owners' privacy and security.
|
||||
@ -0,0 +1,135 @@
|
||||
# network troubleshooting using the `ss` (Socket Statistics)
|
||||
|
||||
## 1. Introduction to `ss`:
|
||||
`ss` is a powerful utility for investigating sockets. It replaces the older `netstat` command and provides more detailed information about network connections.
|
||||
|
||||
## 2. Basic usage:
|
||||
To display all connections:
|
||||
```
|
||||
ss
|
||||
```
|
||||
|
||||
## 3. Common options:
|
||||
- `-t`: Show TCP sockets
|
||||
- `-u`: Show UDP sockets
|
||||
- `-l`: Show only listening sockets
|
||||
- `-a`: Show both listening and non-listening sockets
|
||||
- `-n`: Don't resolve service names
|
||||
- `-p`: Show process using the socket
|
||||
|
||||
## 4. Displaying TCP connections:
|
||||
```
|
||||
ss -t
|
||||
```
|
||||
|
||||
## 5. Showing listening sockets:
|
||||
```
|
||||
ss -l
|
||||
```
|
||||
|
||||
## 6. Combining options:
|
||||
To show listening TCP sockets with process information:
|
||||
```
|
||||
ss -tlp
|
||||
```
|
||||
|
||||
## 7. Filtering connections:
|
||||
- By state:
|
||||
```
|
||||
ss state established
|
||||
```
|
||||
- By port:
|
||||
```
|
||||
ss sport = :80
|
||||
```
|
||||
- By IP address:
|
||||
```
|
||||
ss dst 192.168.1.1
|
||||
```
|
||||
|
||||
## 8. Advanced filtering:
|
||||
Use expressions for complex filters:
|
||||
```
|
||||
ss -t '( dport = :ssh or sport = :ssh )'
|
||||
```
|
||||
|
||||
## 9. Displaying socket statistics:
|
||||
```
|
||||
ss -s
|
||||
```
|
||||
|
||||
## 10. Checking for specific issues:
|
||||
- High number of TIME_WAIT connections:
|
||||
```
|
||||
ss -t state time-wait | wc -l
|
||||
```
|
||||
- Connections in SYN-SENT state (potential connectivity issues):
|
||||
```
|
||||
ss -t state syn-sent
|
||||
```
|
||||
|
||||
## 11. Investigating socket buffers:
|
||||
```
|
||||
ss -tm
|
||||
```
|
||||
|
||||
## 12. Displaying timer information:
|
||||
```
|
||||
ss -to
|
||||
```
|
||||
|
||||
## 13. Checking for UNIX domain sockets:
|
||||
```
|
||||
ss -x
|
||||
```
|
||||
|
||||
## 14. Combining with other tools:
|
||||
- Use with `grep` for specific searches:
|
||||
```
|
||||
ss -tuln | grep :80
|
||||
```
|
||||
- Pipe to `less` for easier navigation:
|
||||
```
|
||||
ss -tuna | less
|
||||
```
|
||||
|
||||
## 15. Troubleshooting steps:
|
||||
- a. Check for listening services:
|
||||
```
|
||||
ss -tlnp
|
||||
```
|
||||
- b. Verify established connections:
|
||||
```
|
||||
ss -tnp state established
|
||||
```
|
||||
- c. Look for connection attempts:
|
||||
```
|
||||
ss -tnp state syn-sent
|
||||
```
|
||||
- d. Investigate connection closures:
|
||||
```
|
||||
ss -tnp state time-wait
|
||||
```
|
||||
- e. Check for any unusual states or high connection counts
|
||||
|
||||
## 16. Performance considerations:
|
||||
- Use `ss -i` to display TCP internal information
|
||||
- Monitor retransmission rates and window sizes
|
||||
|
||||
## 17. Security checks:
|
||||
- Look for unexpected listening ports
|
||||
- Check for connections from unknown IP addresses
|
||||
|
||||
## 18. Debugging application issues:
|
||||
- Use `-p` option to correlate sockets with processes
|
||||
- Investigate socket states for hung connections
|
||||
|
||||
## 19. Network tuning:
|
||||
- Use socket statistics to identify bottlenecks
|
||||
- Adjust system parameters based on observed behavior
|
||||
|
||||
## 20. Scripting with `ss`:
|
||||
- Use in shell scripts for automated monitoring
|
||||
- Combine with `awk` or `sed` for custom output formatting
|
||||
|
||||
Remember that some `ss` commands may require root privileges to access all information. Always use caution when interpreting network data, especially in production environments.
|
||||
@ -0,0 +1,103 @@
|
||||
# Internet Traffic Control
|
||||
|
||||
## 1. Introduction to Traffic Control (TC)
|
||||
|
||||
Traffic Control (TC) is a set of tools and mechanisms in Linux that allow you to shape, schedule, police, and prioritize network traffic. It's part of the Linux kernel's networking stack and provides powerful capabilities for managing network bandwidth and latency.
|
||||
|
||||
## 2. Key Concepts
|
||||
|
||||
- a) Queueing Disciplines (qdisc):
|
||||
A qdisc is a scheduler that controls how packets are sent or received on a network interface. There are two types:
|
||||
- Classless: Simple, single-queue disciplines
|
||||
- Classful: More complex, can contain multiple classes of traffic
|
||||
|
||||
- b) Classes:
|
||||
Within classful qdiscs, classes allow you to categorize traffic and apply different rules to each category.
|
||||
|
||||
- c) Filters:
|
||||
Used to classify packets into different classes based on various criteria.
|
||||
|
||||
- d) Tokens and Buckets:
|
||||
Many TC algorithms use the concept of tokens and buckets to control traffic rates.
|
||||
|
||||
## 3. Common Queueing Disciplines
|
||||
|
||||
a) pfifo_fast: Default qdisc, a simple FIFO queue with three bands for prioritization.
|
||||
b) tbf (Token Bucket Filter): Limits traffic to a specified rate.
|
||||
c) htb (Hierarchical Token Bucket): Allows complex hierarchical class-based traffic control.
|
||||
d) sfq (Stochastic Fairness Queueing): Attempts to fairly distribute traffic among flows.
|
||||
e) netem: Network emulator for testing, can introduce delay, loss, duplication, and more.
|
||||
|
||||
## 4. Basic TC Commands
|
||||
|
||||
The tc command is the primary tool for configuring Traffic Control. Basic syntax:
|
||||
|
||||
```
|
||||
tc [OPTIONS] OBJECT { COMMAND | help }
|
||||
```
|
||||
|
||||
OBJECT can be:
|
||||
- qdisc (Queueing discipline)
|
||||
- class
|
||||
- filter
|
||||
|
||||
Common COMMANDS include:
|
||||
- add
|
||||
- del
|
||||
- change
|
||||
- show (or list)
|
||||
|
||||
## 5. Examples of TC Usage
|
||||
|
||||
- a) Setting up a simple rate limiter:
|
||||
```
|
||||
tc qdisc add dev eth0 root tbf rate 1mbit burst 32kbit latency 400ms
|
||||
```
|
||||
|
||||
- b) Creating a hierarchical setup with HTB:
|
||||
```
|
||||
# Create root qdisc
|
||||
tc qdisc add dev eth0 root handle 1: htb default 30
|
||||
|
||||
# Add classes
|
||||
tc class add dev eth0 parent 1: classid 1:1 htb rate 100mbit
|
||||
tc class add dev eth0 parent 1:1 classid 1:10 htb rate 50mbit ceil 100mbit
|
||||
tc class add dev eth0 parent 1:1 classid 1:20 htb rate 30mbit ceil 100mbit
|
||||
tc class add dev eth0 parent 1:1 classid 1:30 htb rate 20mbit ceil 100mbit
|
||||
|
||||
# Add filters to classify traffic
|
||||
tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dport 80 0xffff flowid 1:10
|
||||
tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip sport 22 0xffff flowid 1:20
|
||||
```
|
||||
|
||||
## 6. Advanced Features
|
||||
|
||||
a) Ingress qdisc: Control incoming traffic
|
||||
b) Shaping vs. Policing: Shaping buffers traffic, policing drops excess
|
||||
c) Classifying with iptables: Use MARK target to classify packets
|
||||
d) Handling of TCP vs UDP traffic
|
||||
|
||||
## 7. Monitoring and Debugging
|
||||
|
||||
a) Use `tc -s qdisc show dev eth0` to see statistics
|
||||
b) tcpdump can help analyze traffic patterns
|
||||
c) iftop or nethogs for real-time bandwidth usage monitoring
|
||||
|
||||
## 8. Best Practices
|
||||
|
||||
a) Start simple and gradually increase complexity
|
||||
b) Test configurations thoroughly before deploying
|
||||
c) Consider the impact on application performance
|
||||
d) Document your TC setup for future reference
|
||||
|
||||
## 9. Integration with Other Systems
|
||||
|
||||
a) Combine with QoS markings (e.g., DSCP) for end-to-end traffic management
|
||||
b) Use with firewalls for comprehensive network control
|
||||
c) Automate TC configurations with scripts or configuration management tools
|
||||
|
||||
## 10. Limitations and Considerations
|
||||
|
||||
a) Complex setups can impact CPU usage
|
||||
b) Some features may not work with all network drivers
|
||||
c) Virtual environments may have limitations or require special configurations
|
||||
@ -0,0 +1,198 @@
|
||||
# Linux Disk Monitoring and Tuning
|
||||
|
||||
## 1. Disk Monitoring Tools
|
||||
|
||||
### iostat
|
||||
iostat provides detailed I/O statistics for devices and partitions. It shows CPU utilization and disk I/O statistics.
|
||||
|
||||
Usage:
|
||||
```bash
|
||||
iostat [options] [interval] [count]
|
||||
```
|
||||
|
||||
Key metrics:
|
||||
- %util: Percentage of CPU time during which I/O requests were issued
|
||||
- r/s and w/s: Read and write requests per second
|
||||
- rkB/s and wkB/s: Read and write kilobytes per second
|
||||
|
||||
### iotop
|
||||
iotop is an interactive I/O monitoring tool that shows per-process I/O usage.
|
||||
|
||||
Usage:
|
||||
```bash
|
||||
iotop
|
||||
```
|
||||
|
||||
### dstat
|
||||
dstat is a versatile tool for generating system resource statistics.
|
||||
|
||||
Usage:
|
||||
```bash
|
||||
dstat --disk --io --disk-util
|
||||
```
|
||||
|
||||
### vmstat
|
||||
vmstat reports information about processes, memory, paging, block I/O, traps, and CPU activity.
|
||||
|
||||
Usage:
|
||||
```bash
|
||||
vmstat [interval] [count]
|
||||
```
|
||||
|
||||
### fdisk
|
||||
fdisk is a dialog-driven program for creation and manipulation of partition tables.
|
||||
|
||||
Usage:
|
||||
```bash
|
||||
fdisk -l
|
||||
```
|
||||
|
||||
## 2. Disk Performance Testing
|
||||
|
||||
### dd
|
||||
dd can be used for simple disk read/write performance tests.
|
||||
|
||||
Example (write test):
|
||||
```bash
|
||||
dd if=/dev/zero of=testfile bs=1G count=1 oflag=dsync
|
||||
```
|
||||
|
||||
Example (read test):
|
||||
```bash
|
||||
dd if=testfile of=/dev/null bs=1G count=1
|
||||
```
|
||||
|
||||
### fio
|
||||
fio is a flexible I/O tester for benchmark and stress/hardware verification.
|
||||
|
||||
Example:
|
||||
```bash
|
||||
fio --name=random-write --ioengine=posixaio --rw=randwrite --bs=4k --size=4g --numjobs=1 --runtime=60 --time_based --end_fsync=1
|
||||
```
|
||||
|
||||
## 3. File System Monitoring
|
||||
|
||||
### df
|
||||
df reports file system disk space usage.
|
||||
|
||||
Usage:
|
||||
```bash
|
||||
df -h
|
||||
```
|
||||
|
||||
### du
|
||||
du estimates file and directory space usage.
|
||||
|
||||
Usage:
|
||||
```bash
|
||||
du -sh /path/to/directory
|
||||
```
|
||||
|
||||
## 4. Disk Tuning Techniques
|
||||
|
||||
### I/O Scheduler
|
||||
Linux offers different I/O schedulers. Common ones include:
|
||||
- CFQ (Completely Fair Queuing)
|
||||
- Deadline
|
||||
- NOOP
|
||||
|
||||
To check the current scheduler:
|
||||
```bash
|
||||
cat /sys/block/sda/queue/scheduler
|
||||
```
|
||||
|
||||
To change the scheduler:
|
||||
```bash
|
||||
echo "deadline" > /sys/block/sda/queue/scheduler
|
||||
```
|
||||
|
||||
### Read-ahead
|
||||
Adjust the read-ahead value to optimize for your workload:
|
||||
|
||||
```bash
|
||||
blockdev --getra /dev/sda
|
||||
blockdev --setra 8192 /dev/sda
|
||||
```
|
||||
|
||||
### Swappiness
|
||||
Reduce swappiness to minimize disk writes:
|
||||
|
||||
```
|
||||
sysctl vm.swappiness=10
|
||||
```
|
||||
|
||||
### Disk Cache
|
||||
Adjust the ratio of cached dirty memory:
|
||||
|
||||
```bash
|
||||
sysctl -w vm.dirty_ratio=10
|
||||
sysctl -w vm.dirty_background_ratio=5
|
||||
```
|
||||
|
||||
### TRIM (for SSDs)
|
||||
Enable TRIM for SSDs to maintain performance:
|
||||
|
||||
```bash
|
||||
fstrim -v /
|
||||
```
|
||||
|
||||
Or add the `discard` option to the mount options in /etc/fstab.
|
||||
|
||||
### Journaling
|
||||
For ext4 file systems, you can disable journaling for better write performance (at the cost of data integrity):
|
||||
|
||||
```bash
|
||||
tune2fs -O ^has_journal /dev/sda1
|
||||
```
|
||||
|
||||
### Noatime
|
||||
Use the `noatime` mount option to reduce disk writes:
|
||||
|
||||
In /etc/fstab:
|
||||
```ini
|
||||
UUID=xxx / ext4 defaults,noatime 0 1
|
||||
```
|
||||
|
||||
## 5. Monitoring Tools for Long-term Analysis
|
||||
|
||||
### sysstat
|
||||
sysstat includes tools like sar (System Activity Reporter) for long-term performance monitoring.
|
||||
|
||||
To enable data collection:
|
||||
```bash
|
||||
systemctl enable sysstat
|
||||
systemctl start sysstat
|
||||
```
|
||||
|
||||
To view collected data:
|
||||
```bash
|
||||
sar -d
|
||||
```
|
||||
|
||||
### Prometheus + Node Exporter + Grafana
|
||||
For a more comprehensive monitoring solution:
|
||||
- Install and configure Prometheus
|
||||
- Set up Node Exporter on monitored systems
|
||||
- Create dashboards in Grafana for visualization
|
||||
|
||||
## 6. Best Practices
|
||||
|
||||
### Regular Maintenance
|
||||
- Run fsck regularly on unmounted file systems
|
||||
- Use SMART monitoring tools for early warning of disk failures
|
||||
- Perform regular backups
|
||||
|
||||
### Capacity Planning
|
||||
- Monitor disk usage trends
|
||||
- Plan for capacity increases before running out of space
|
||||
|
||||
### RAID Considerations
|
||||
- Use appropriate RAID levels for your use case
|
||||
- Monitor RAID health and replace failed disks promptly
|
||||
|
||||
### SSD-specific Considerations
|
||||
- Enable TRIM
|
||||
- Monitor SSD wear levels
|
||||
- Consider over-provisioning for write-heavy workloads
|
||||
|
||||
This guide covers the basics of Linux disk monitoring and tuning. Remember that optimal settings depend on your specific hardware and workload. Always test changes in a non-production environment first.
|
||||
162
13 - Linux Performance Monitoring and Tuning/Linux CPU Tuning.md
Normal file
162
13 - Linux Performance Monitoring and Tuning/Linux CPU Tuning.md
Normal file
@ -0,0 +1,162 @@
|
||||
# Linux CPU tuning
|
||||
|
||||
## 1. Understanding CPU Governors
|
||||
|
||||
CPU governors control the CPU frequency scaling on Linux systems. The main governors are:
|
||||
|
||||
- performance: Runs the CPU at maximum frequency
|
||||
- powersave: Runs the CPU at minimum frequency
|
||||
- ondemand: Dynamically scales CPU frequency based on system load
|
||||
- conservative: Similar to ondemand, but scales frequency more gradually
|
||||
- schedutil: Uses the CPU scheduler for frequency scaling decisions
|
||||
|
||||
To view available governors:
|
||||
```bash
|
||||
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
|
||||
```
|
||||
|
||||
To set a governor:
|
||||
```bash
|
||||
sudo cpupower frequency-set -g <governor>
|
||||
```
|
||||
|
||||
## 2. CPU Frequency Scaling
|
||||
|
||||
You can manually set CPU frequencies:
|
||||
|
||||
View available frequencies:
|
||||
```bash
|
||||
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
|
||||
```
|
||||
|
||||
Set minimum and maximum frequencies:
|
||||
```bash
|
||||
sudo cpupower frequency-set --min <freq> --max <freq>
|
||||
```
|
||||
|
||||
## 3. CPU Affinity
|
||||
|
||||
CPU affinity allows you to bind processes to specific CPU cores:
|
||||
|
||||
```bash
|
||||
taskset -c 0,1 <command> # Run command on cores 0 and 1
|
||||
```
|
||||
|
||||
## 4. Nice and Ionice
|
||||
|
||||
Adjust process priorities:
|
||||
|
||||
```bash
|
||||
nice -n <value> <command> # Set CPU scheduling priority (-20 to 19)
|
||||
ionice -c <class> -n <value> <command> # Set I/O scheduling priority
|
||||
```
|
||||
|
||||
## 5. CPU Isolation
|
||||
|
||||
Isolate CPUs from the scheduler to dedicate them to specific tasks:
|
||||
|
||||
Add to kernel boot parameters:
|
||||
```bash
|
||||
isolcpus=2,3
|
||||
```
|
||||
|
||||
## 6. IRQ Balancing
|
||||
|
||||
Manage interrupt request (IRQ) distribution:
|
||||
|
||||
Disable IRQ balancing:
|
||||
```bash
|
||||
sudo service irqbalance stop
|
||||
```
|
||||
|
||||
Manually set IRQ affinity:
|
||||
```bash
|
||||
echo <cpu_mask> > /proc/irq/<irq_number>/smp_affinity
|
||||
```
|
||||
|
||||
## 7. CPU Power Management
|
||||
|
||||
Control CPU power-saving features:
|
||||
|
||||
Disable C-states:
|
||||
```bash
|
||||
echo 1 > /sys/devices/system/cpu/cpu0/cpuidle/state1/disable
|
||||
```
|
||||
|
||||
Adjust Intel P-states:
|
||||
```bash
|
||||
echo passive > /sys/devices/system/cpu/intel_pstate/status
|
||||
```
|
||||
|
||||
## 8. Kernel Parameters
|
||||
|
||||
Adjust various kernel parameters for CPU performance:
|
||||
|
||||
Edit /etc/sysctl.conf:
|
||||
```ini
|
||||
kernel.sched_migration_cost_ns = 5000000
|
||||
kernel.sched_autogroup_enabled = 0
|
||||
kernel.sched_wakeup_granularity_ns = 15000000
|
||||
```
|
||||
|
||||
Apply changes:
|
||||
```bash
|
||||
sudo sysctl -p
|
||||
```
|
||||
|
||||
## 9. CPU Topology
|
||||
|
||||
Understand your CPU topology:
|
||||
```bash
|
||||
lscpu
|
||||
lstopo
|
||||
```
|
||||
|
||||
## 10. Monitoring and Profiling
|
||||
|
||||
Use tools to monitor CPU performance:
|
||||
|
||||
- top/htop: Real-time system monitor
|
||||
- perf: Linux profiling tool
|
||||
- stress-ng: CPU stress testing tool
|
||||
- s-tui: Terminal-based CPU monitoring
|
||||
|
||||
## 11. NUMA (Non-Uniform Memory Access)
|
||||
|
||||
For multi-socket systems, manage NUMA settings:
|
||||
|
||||
View NUMA info:
|
||||
```bash
|
||||
numactl --hardware
|
||||
```
|
||||
|
||||
Run a command with NUMA policy:
|
||||
```bash
|
||||
numactl --cpunodebind=0 --membind=0 <command>
|
||||
```
|
||||
|
||||
## 12. Compiler Optimizations
|
||||
|
||||
When compiling software, use CPU-specific optimizations:
|
||||
|
||||
GCC flags:
|
||||
```bash
|
||||
-march=native -mtune=native
|
||||
```
|
||||
|
||||
## 13. CPU Vulnerabilities Mitigations
|
||||
|
||||
Control CPU vulnerability mitigations:
|
||||
|
||||
View current mitigations:
|
||||
```bash
|
||||
grep . /sys/devices/system/cpu/vulnerabilities/*
|
||||
```
|
||||
|
||||
Disable mitigations (may impact security):
|
||||
Add to kernel boot parameters:
|
||||
```bash
|
||||
mitigations=off
|
||||
```
|
||||
|
||||
This guide covers the main aspects of CPU tuning on Linux. Remember that optimal settings depend on your specific hardware and workload. Always test thoroughly and monitor system performance when making changes.
|
||||
@ -0,0 +1,134 @@
|
||||
# Linux Network Performance Monitoring
|
||||
|
||||
Linux Network Performance Monitoring: A Comprehensive Guide
|
||||
|
||||
## 1. Introduction
|
||||
- Importance of network performance monitoring
|
||||
- Overview of Linux tools and techniques
|
||||
|
||||
## 2. Key Network Performance Metrics
|
||||
- Bandwidth
|
||||
- Latency
|
||||
- Packet loss
|
||||
- Throughput
|
||||
- Jitter
|
||||
- Connection states
|
||||
|
||||
## 3. Built-in Linux Commands for Network Monitoring
|
||||
### ping
|
||||
- Basic usage and interpretation
|
||||
- Advanced options (interval, packet size, flood ping)
|
||||
|
||||
### traceroute / tracepath
|
||||
- Tracing network path and identifying bottlenecks
|
||||
- Understanding output and hop analysis
|
||||
|
||||
### netstat
|
||||
- Monitoring network connections and routing tables
|
||||
- Useful options and real-time monitoring
|
||||
|
||||
### ss (Socket Statistics)
|
||||
- Modern replacement for netstat
|
||||
- Monitoring TCP, UDP, and UNIX socket connections
|
||||
|
||||
### ip
|
||||
- Configuring and monitoring network interfaces
|
||||
- Viewing routing information and ARP cache
|
||||
|
||||
## 4. Advanced Command-line Tools
|
||||
### iftop
|
||||
- Real-time bandwidth usage monitoring per connection
|
||||
- Installation and usage guide
|
||||
|
||||
### iptraf
|
||||
- Interactive colorful IP LAN monitor
|
||||
- Detailed statistics on various network protocols
|
||||
|
||||
### nethogs
|
||||
- Monitoring per-process network usage
|
||||
- Identifying bandwidth-hungry applications
|
||||
|
||||
### tcpdump
|
||||
- Packet capture and analysis
|
||||
- Filtering options and output interpretation
|
||||
|
||||
### nload
|
||||
- Monitoring network traffic and bandwidth usage in real-time
|
||||
- Graphical representation in the terminal
|
||||
|
||||
## 5. System-wide Monitoring Tools
|
||||
### Nagios
|
||||
- Overview and setup
|
||||
- Configuring network performance checks
|
||||
- Alerts and notifications
|
||||
|
||||
### Zabbix
|
||||
- Installation and configuration
|
||||
- Creating network monitoring templates
|
||||
- Visualization and reporting
|
||||
|
||||
### Prometheus + Grafana
|
||||
- Setting up Prometheus for metrics collection
|
||||
- Configuring Grafana dashboards for network visualization
|
||||
- Creating custom alerts
|
||||
|
||||
## 6. Specialized Network Monitoring Tools
|
||||
### Wireshark
|
||||
- GUI-based packet analyzer
|
||||
- Capture and analysis techniques
|
||||
- Protocol-specific analysis
|
||||
|
||||
### nmap
|
||||
- Network discovery and security auditing
|
||||
- Port scanning and OS fingerprinting
|
||||
|
||||
### iperf / iperf3
|
||||
- Network performance testing
|
||||
- Measuring maximum achievable bandwidth
|
||||
|
||||
## 7. Kernel Tuning for Network Performance
|
||||
### sysctl parameters
|
||||
- TCP/IP stack optimization
|
||||
- Buffer sizes and connection handling
|
||||
|
||||
### Network interface configuration
|
||||
- MTU optimization
|
||||
- TCP segmentation offload (TSO)
|
||||
- Interrupt coalescing
|
||||
|
||||
## 8. Log Analysis for Network Performance
|
||||
- Important log files (/var/log/syslog, /var/log/messages)
|
||||
- Using tools like logwatch and fail2ban
|
||||
- Centralized logging with ELK stack (Elasticsearch, Logstash, Kibana)
|
||||
|
||||
## 9. Automating Network Performance Monitoring
|
||||
- Writing shell scripts for regular checks
|
||||
- Using cron jobs for scheduled monitoring
|
||||
- Developing custom monitoring solutions with Python
|
||||
|
||||
## 10. Best Practices
|
||||
- Establishing baselines
|
||||
- Regular performance audits
|
||||
10.3. Documentation and change management
|
||||
10.4. Capacity planning
|
||||
|
||||
## 11. Troubleshooting Common Network Performance Issues
|
||||
- High latency
|
||||
- Packet loss
|
||||
- DNS resolution problems
|
||||
- Bandwidth saturation
|
||||
- Network congestion
|
||||
|
||||
## 12. Case Studies
|
||||
- Identifying a network bottleneck in a web server setup
|
||||
- Troubleshooting intermittent connectivity issues
|
||||
- Optimizing network performance for a large-scale database cluster
|
||||
|
||||
## 13. Future Trends in Linux Network Performance Monitoring
|
||||
- AI/ML-based anomaly detection
|
||||
- Container and microservices monitoring
|
||||
- Cloud-native monitoring solutions
|
||||
|
||||
## 14. Conclusion
|
||||
- Recap of key points
|
||||
- Importance of continuous monitoring and optimization
|
||||
@ -0,0 +1,118 @@
|
||||
# Performance Monitoring Tools (top, htop, vmstat)
|
||||
|
||||
## 1. top
|
||||
|
||||
Top is a dynamic real-time system monitoring tool that comes pre-installed on most Linux distributions. It provides a comprehensive overview of system resource usage.
|
||||
|
||||
Key features:
|
||||
- Real-time view of system processes
|
||||
- CPU and memory usage
|
||||
- Load average
|
||||
- Tasks statistics (running, sleeping, stopped, zombie)
|
||||
- Uptime
|
||||
|
||||
Usage:
|
||||
To start top, simply type `top` in the terminal.
|
||||
|
||||
Important commands within top:
|
||||
- 'q': Quit
|
||||
- 'h': Help
|
||||
- 'k': Kill a process
|
||||
- 'r': Renice a process
|
||||
- 'f': Fields management
|
||||
- 'o': Change sort order
|
||||
|
||||
Customization:
|
||||
You can customize top's display by pressing 'f' to select which fields to show, and 'o' to change the sort order.
|
||||
|
||||
## 2. htop
|
||||
|
||||
Htop is an enhanced version of top with a more user-friendly interface and additional features. It's not usually pre-installed, so you may need to install it using your distribution's package manager.
|
||||
|
||||
Key features:
|
||||
- Colorful and intuitive interface
|
||||
- Mouse support
|
||||
- Vertical and horizontal scrolling
|
||||
- Tree view of processes
|
||||
- Detailed CPU, memory, and swap usage
|
||||
|
||||
Usage:
|
||||
To start htop, type `htop` in the terminal.
|
||||
|
||||
Important commands within htop:
|
||||
- F1-F10: Various functions (help, setup, search, etc.)
|
||||
- Space: Tag a process
|
||||
- U: Show only processes of a specific user
|
||||
- t: Tree view
|
||||
- ]: Sort by CPU usage
|
||||
- [: Sort by memory usage
|
||||
|
||||
Customization:
|
||||
Htop offers extensive customization options. Press F2 to access the setup menu, where you can configure meters, colors, and display options.
|
||||
|
||||
## 3. vmstat
|
||||
|
||||
Vmstat (Virtual Memory Statistics) is a command-line tool that provides information about system processes, memory, paging, block I/O, traps, and CPU activity.
|
||||
|
||||
Key features:
|
||||
- Compact output format
|
||||
- Historical data
|
||||
- Detailed memory statistics
|
||||
- Disk I/O statistics
|
||||
- CPU usage breakdown
|
||||
|
||||
Usage:
|
||||
Basic syntax: vmstat [options] [delay [count]]
|
||||
|
||||
Example:
|
||||
vmstat 5 3
|
||||
This will display statistics every 5 seconds for 3 iterations.
|
||||
|
||||
Important columns in vmstat output:
|
||||
- r: Number of runnable processes
|
||||
- b: Number of processes in uninterruptible sleep
|
||||
- swpd: Used swap space
|
||||
- free: Free memory
|
||||
- buff: Memory used as buffers
|
||||
- cache: Memory used as cache
|
||||
- si: Memory swapped in from disk
|
||||
- so: Memory swapped out to disk
|
||||
- bi: Blocks received from a block device
|
||||
- bo: Blocks sent to a block device
|
||||
- in: Interrupts per second
|
||||
- cs: Context switches per second
|
||||
- us, sy, id, wa: CPU time spent in user mode, kernel mode, idle, and waiting for I/O
|
||||
|
||||
Advanced usage:
|
||||
- vmstat -s: Displays a table of various event counters and memory statistics
|
||||
- vmstat -d: Shows disk statistics
|
||||
- vmstat -p /dev/sda1: Displays statistics for a specific partition
|
||||
|
||||
## 4. Comparison and Use Cases:
|
||||
|
||||
### 1. top:
|
||||
- Best for quick system overview
|
||||
- Good for identifying resource-heavy processes
|
||||
- Suitable for systems with limited resources
|
||||
|
||||
### 2. htop:
|
||||
- Ideal for interactive use and detailed process management
|
||||
- Better for systems with many processes
|
||||
- More user-friendly for less experienced users
|
||||
|
||||
### 3. vmstat:
|
||||
- Excellent for analyzing system performance over time
|
||||
- Useful for identifying I/O or memory bottlenecks
|
||||
- Good for scripting and automated monitoring
|
||||
|
||||
# 5. Best Practices:
|
||||
|
||||
- Regular monitoring: Use these tools regularly to establish a baseline for your system's performance.
|
||||
|
||||
- Combine tools: Each tool provides unique insights, so use them in combination for a comprehensive understanding.-3. Look for patterns: Pay attention to trends and patterns in resource usage over time.
|
||||
|
||||
- Customize: Tailor the tools to your specific needs by customizing their output and display options.
|
||||
|
||||
- Correlate with application logs: When you notice performance issues, correlate the data from these tools with your application logs for a fuller picture.
|
||||
|
||||
By mastering these Linux performance monitoring tools, you'll be well-equipped to diagnose and resolve system performance issues effectively.
|
||||
@ -0,0 +1,103 @@
|
||||
# Linux System Load and Memory Management:
|
||||
|
||||
## System Load
|
||||
|
||||
System load in Linux refers to the amount of computational work the system is performing. It's typically expressed as three numbers representing the average number of processes waiting for CPU time over the last 1, 5, and 15 minutes.
|
||||
|
||||
### 1. Understanding Load Averages:
|
||||
- A load average of 1.0 means the system is fully utilized but not overloaded.
|
||||
- Values below 1.0 indicate idle CPU capacity.
|
||||
- Values above 1.0 suggest processes are waiting for CPU time.
|
||||
|
||||
### 2. Interpreting Load Averages:
|
||||
- Consider the number of CPU cores when interpreting load.
|
||||
- For a quad-core system, a load of 4.0 represents full utilization.
|
||||
|
||||
### 3. Monitoring Load:
|
||||
- Use commands like `top`, `uptime`, or `w` to view current load averages.
|
||||
- The `/proc/loadavg` file contains raw load data.
|
||||
|
||||
### 4. Causes of High Load:
|
||||
- CPU-intensive tasks
|
||||
- I/O bottlenecks
|
||||
- Memory pressure leading to swapping
|
||||
- Resource contention
|
||||
|
||||
## Memory Management
|
||||
|
||||
Linux employs sophisticated memory management techniques to optimize system performance:
|
||||
|
||||
### 1. Virtual Memory:
|
||||
- Linux uses virtual memory to provide each process with its own address space.
|
||||
- This allows for memory protection and efficient use of physical RAM.
|
||||
|
||||
### 2. Page Cache:
|
||||
- Linux caches recently accessed disk data in RAM for faster access.
|
||||
- The page cache improves I/O performance significantly.
|
||||
|
||||
### 3. Swap Space:
|
||||
- Swap is used when physical RAM is full.
|
||||
- It allows the system to move less frequently used pages to disk.
|
||||
|
||||
### 4. OOM Killer:
|
||||
- The Out-Of-Memory (OOM) Killer terminates processes when the system runs out of memory.
|
||||
- It selects processes based on various heuristics to free up memory.
|
||||
|
||||
### 5. Memory Allocation:
|
||||
- The kernel uses algorithms like buddy allocation for efficient memory management.
|
||||
- User-space allocators like glibc's malloc handle application memory requests.
|
||||
|
||||
### 6. Transparent Huge Pages (THP):
|
||||
- THP allows the use of larger memory pages to improve performance for some workloads.
|
||||
|
||||
## Monitoring and Tuning
|
||||
|
||||
### 1. Monitoring Tools:
|
||||
- `free`: Shows memory usage summary
|
||||
- `vmstat`: Provides virtual memory statistics
|
||||
- `top`/`htop`: Real-time system monitoring
|
||||
- `sar`: Collects and reports system activity information
|
||||
|
||||
### 2. Key Files and Directories:
|
||||
- `/proc/meminfo`: Detailed memory usage information
|
||||
- `/proc/sys/vm/`: Kernel memory management parameters
|
||||
|
||||
### 3. Important Parameters:
|
||||
- `vm.swappiness`: Controls the kernel's propensity to swap
|
||||
- `vm.min_free_kbytes`: Minimum free memory for critical allocations
|
||||
- `vm.overcommit_memory`: Memory overcommit policy
|
||||
|
||||
### 4. Tuning Strategies:
|
||||
- Adjust swappiness for optimal swap usage
|
||||
- Configure huge pages for large memory applications
|
||||
- Optimize I/O to reduce memory pressure
|
||||
- Use cgroups to manage resource allocation
|
||||
|
||||
## Best Practices
|
||||
|
||||
### 1. Regular Monitoring:
|
||||
- Set up monitoring and alerting for load and memory usage.
|
||||
- Use tools like Prometheus, Grafana, or Nagios for comprehensive monitoring.
|
||||
|
||||
### 2. Performance Profiling:
|
||||
- Use tools like `perf` to identify performance bottlenecks.
|
||||
- Analyze application memory usage patterns.
|
||||
|
||||
### 3. Capacity Planning:
|
||||
- Regularly review system resources and plan for future growth.
|
||||
- Consider vertical scaling (more RAM/CPU) or horizontal scaling (more nodes).
|
||||
|
||||
### 4. Application Optimization:
|
||||
- Optimize applications for efficient memory usage.
|
||||
- Use appropriate data structures and algorithms.
|
||||
- Consider using memory-efficient programming languages or frameworks.
|
||||
|
||||
### 5. System Configuration:
|
||||
- Tune kernel parameters based on workload characteristics.
|
||||
- Configure appropriate limits in `/etc/security/limits.conf`.
|
||||
|
||||
### 6. Regular Maintenance:
|
||||
- Keep the system updated with the latest security patches.
|
||||
- Perform regular cleanup of temporary files and old log data.
|
||||
|
||||
Understanding and effectively managing system load and memory in Linux is crucial for maintaining optimal performance and stability. Regular monitoring, proper tuning, and following best practices can help ensure your Linux systems run efficiently under various workloads.
|
||||
@ -0,0 +1,107 @@
|
||||
# Advanced Network Troubleshooting
|
||||
|
||||
## Introduction
|
||||
As Linux systems become increasingly important in modern computing environments, the ability to effectively troubleshoot network-related issues is a crucial skill for system administrators and IT professionals. This guide will cover advanced techniques and tools for identifying and resolving complex network problems in a Linux environment.
|
||||
|
||||
## Table of Contents
|
||||
1. [Network Diagnostics Tools](#network-diagnostics-tools)
|
||||
2. [Packet Capture and Analysis](#packet-capture-and-analysis)
|
||||
3. [Network Performance Monitoring](#network-performance-monitoring)
|
||||
4. [Routing and Firewall Troubleshooting](#routing-and-firewall-troubleshooting)
|
||||
5. [Network Protocol Analysis](#network-protocol-analysis)
|
||||
6. [Advanced Troubleshooting Techniques](#advanced-troubleshooting-techniques)
|
||||
7. [Conclusion](#conclusion)
|
||||
|
||||
## 1. Network Diagnostics Tools
|
||||
|
||||
### 1.1 `ping`
|
||||
The `ping` command is a fundamental tool for network troubleshooting. It can be used to test the connectivity between two hosts, check for packet loss, and measure round-trip time (RTT). Advanced options include:
|
||||
- `ping -c <count>`: Specify the number of packets to send
|
||||
- `ping -i <interval>`: Set the interval between packets (in seconds)
|
||||
- `ping -W <timeout>`: Set the timeout (in seconds) for the entire ping operation
|
||||
|
||||
### 1.2 `traceroute`
|
||||
`traceroute` is used to trace the path that packets take from the local host to a remote host. This can help identify where network issues may be occurring. Useful options include:
|
||||
- `traceroute -n`: Disable DNS resolution and show IP addresses instead of hostnames
|
||||
- `traceroute -m <max_hops>`: Set the maximum number of hops to trace
|
||||
|
||||
### 1.3 `dig`
|
||||
The `dig` (Domain Information Groper) command is a powerful tool for troubleshooting DNS-related issues. It can be used to perform DNS lookups, check the records associated with a domain, and more. Some useful options include:
|
||||
- `dig @<server> <domain>`: Specify a custom DNS server to use for the lookup
|
||||
- `dig +trace <domain>`: Perform a recursive trace of the domain's DNS hierarchy
|
||||
|
||||
### 1.4 `iptables`
|
||||
`iptables` is the command-line tool used to configure the Linux firewall. It can be used to inspect the current firewall rules, add new rules, and troubleshoot firewall-related issues.
|
||||
- `iptables -L`: List the current firewall rules
|
||||
- `iptables -A <chain> <rule>`: Add a new rule to the specified chain
|
||||
|
||||
## 2. Packet Capture and Analysis
|
||||
|
||||
### 2.1 `tcpdump`
|
||||
`tcpdump` is a command-line tool for capturing and analyzing network traffic. It can be used to inspect packets, filter traffic based on various criteria, and identify network issues.
|
||||
- `tcpdump -i <interface> -n`: Capture traffic on a specific interface and display IP addresses instead of hostnames
|
||||
- `tcpdump -r <capture_file>`: Analyze a previously captured packet capture file
|
||||
|
||||
### 2.2 `Wireshark`
|
||||
Wireshark is a powerful GUI-based network protocol analyzer. It provides a rich set of features for capturing, filtering, and analyzing network traffic, including:
|
||||
- Intuitive user interface for navigating and inspecting captured packets
|
||||
- Advanced filtering and display options
|
||||
- Protocol dissection and analysis capabilities
|
||||
|
||||
## 3. Network Performance Monitoring
|
||||
|
||||
### 3.1 `iperf`
|
||||
`iperf` is a tool used to measure network throughput and performance. It can be used to test the maximum bandwidth between two hosts, as well as other network metrics like latency and jitter.
|
||||
- `iperf -s`: Run the tool in server mode, listening for incoming connections
|
||||
- `iperf -c <host>`: Run the tool in client mode, connecting to the specified server
|
||||
|
||||
### 3.2 `nethogs`
|
||||
`nethogs` is a network traffic monitor that displays a list of processes using the network in real-time. It can be useful for identifying bandwidth-hogging applications or detecting unusual network activity.
|
||||
|
||||
### 3.3 `nload`
|
||||
`nload` is a real-time network traffic monitoring tool that displays incoming and outgoing bandwidth usage in an easy-to-read graph. It can be helpful for visualizing network performance and identifying bandwidth spikes or bottlenecks.
|
||||
|
||||
## 4. Routing and Firewall Troubleshooting
|
||||
|
||||
### 4.1 `ip` and `route`
|
||||
The `ip` command is a powerful tool for managing and troubleshooting network interfaces and routing tables. The `route` command can also be used for similar purposes.
|
||||
- `ip addr show`: Display information about network interfaces
|
||||
- `ip route show`: Display the current routing table
|
||||
|
||||
### 4.2 `iptables`
|
||||
In addition to the basic `iptables` commands mentioned earlier, there are more advanced techniques for troubleshooting firewall-related issues:
|
||||
- `iptables -vnL`: Display firewall rules with verbose output, including packet and byte counts
|
||||
- `iptables -t <table> -L`: List the rules for a specific iptables table (e.g., `nat`, `mangle`)
|
||||
|
||||
## 5. Network Protocol Analysis
|
||||
|
||||
### 5.1 `strace`
|
||||
`strace` is a powerful tool for tracing system calls and signals. It can be used to debug network-related issues by analyzing the low-level interactions between an application and the kernel's network subsystem.
|
||||
- `strace -p <pid>`: Trace the system calls of a running process
|
||||
- `strace -e trace=network <command>`: Trace only network-related system calls
|
||||
|
||||
### 5.2 `lsof`
|
||||
`lsof` (list open files) can be used to identify which processes are using network sockets and connections. This can be helpful for troubleshooting issues related to port usage or application-level network problems.
|
||||
- `lsof -i`: List all open network connections
|
||||
- `lsof -i :<port>`: List connections using a specific port
|
||||
|
||||
## 6. Advanced Troubleshooting Techniques
|
||||
|
||||
### 6.1 Capturing and Analyzing Kernel Logs
|
||||
The Linux kernel maintains a wealth of information about system events, including network-related issues. Examining kernel logs can provide valuable insights for advanced troubleshooting.
|
||||
- `dmesg`: Display the kernel's ring buffer, which contains recent log entries
|
||||
- `journalctl`: The systemd journal, which provides a more comprehensive view of system logs
|
||||
|
||||
### 6.2 Using Debugging Symbols and Kernel Modules
|
||||
Debugging symbols and kernel modules can be used to obtain more detailed information about the inner workings of the Linux network stack. This can be especially useful for identifying and resolving complex network-related issues.
|
||||
- `apt-get install linux-headers-$(uname -r)`: Install the necessary kernel headers
|
||||
- `modprobe <module>`: Load a specific kernel module
|
||||
|
||||
### 6.3 Network Namespaces and Containerization
|
||||
Network namespaces and containerization technologies like Docker can be used to isolate and troubleshoot network issues in a more controlled environment.
|
||||
- `ip netns add <namespace>`: Create a new network namespace
|
||||
- `docker run --network <network> <image>`: Run a container with a specific network configuration
|
||||
|
||||
## 7. Conclusion
|
||||
|
||||
Advanced network troubleshooting in Linux requires a deep understanding of networking concepts, familiarity with a wide range of diagnostic tools, and the ability to analyze complex system behavior. By mastering the techniques outlined in this guide, you'll be well-equipped to identify and resolve even the most challenging network-related issues in your Linux environment.
|
||||
@ -0,0 +1,81 @@
|
||||
# Advanced System Troubleshooting
|
||||
|
||||
## **Table of Contents**
|
||||
1. Introduction to Advanced Linux Troubleshooting
|
||||
2. Gathering System Information
|
||||
3. Analyzing System Logs
|
||||
4. Troubleshooting Boot Issues
|
||||
5. Diagnosing Hardware Problems
|
||||
6. Troubleshooting Network Connectivity
|
||||
7. Resolving Software Conflicts
|
||||
8. Advanced Troubleshooting Tools
|
||||
9. Best Practices for Effective Troubleshooting
|
||||
10. Conclusion
|
||||
|
||||
## 1. Introduction to Advanced Linux Troubleshooting
|
||||
Advanced system troubleshooting in Linux involves a deep understanding of the operating system, its components, and the tools available to diagnose and resolve complex issues. This guide will cover a wide range of troubleshooting techniques and strategies that can help you effectively identify and fix problems on your Linux system.
|
||||
|
||||
## 2. Gathering System Information
|
||||
The first step in any troubleshooting process is to gather as much information about the system as possible. This includes:
|
||||
- Gathering system hardware details using commands like `lshw`, `lspci`, and `dmidecode`.
|
||||
- Checking the kernel version, distribution, and other system information using commands like `uname`, `lsb_release`, and `cat /etc/os-release`.
|
||||
- Identifying running processes, network connections, and system resources using commands like `top`, `htop`, `ss`, and `iotop`.
|
||||
|
||||
## 3. Analyzing System Logs
|
||||
Linux maintains a variety of log files that can provide valuable insights into system issues. Some key log files to examine include:
|
||||
- `/var/log/syslog` or `/var/log/messages`: General system logs
|
||||
- `/var/log/kern.log`: Kernel-related logs
|
||||
- `/var/log/auth.log`: Authentication and authorization logs
|
||||
- `/var/log/Xorg.0.log`: X Window System logs
|
||||
- `/var/log/dmesg`: Kernel ring buffer logs
|
||||
|
||||
You can use tools like `journalctl`, `tail`, and `grep` to effectively navigate and analyze these log files.
|
||||
|
||||
## 4. Troubleshooting Boot Issues
|
||||
When encountering boot-related problems, you can try the following steps:
|
||||
- Check the GRUB boot menu and kernel parameters
|
||||
- Inspect the `/var/log/boot.log` and `/var/log/dmesg` logs for any errors or warnings
|
||||
- Use the `systemctl` command to check the status of critical system services
|
||||
- Perform a system recovery using a live CD/USB or the built-in recovery mode
|
||||
|
||||
## 5. Diagnosing Hardware Problems
|
||||
Hardware issues can be challenging to troubleshoot, but you can use the following techniques:
|
||||
- Run hardware diagnostics tools like `memtest86+`, `badblocks`, and `smartctl`
|
||||
- Check for hardware-related error messages in the system logs
|
||||
- Verify hardware compatibility and drivers
|
||||
- Perform hardware component tests, such as RAM, CPU, and storage device checks
|
||||
|
||||
## 6. Troubleshooting Network Connectivity
|
||||
Network-related issues can be complex, but you can start by:
|
||||
- Checking network interface configuration using `ip`, `ifconfig`, and `nmcli`
|
||||
- Verifying DNS resolution and connectivity using `ping`, `traceroute`, and `dig`
|
||||
- Inspecting network-related log files, such as `/var/log/syslog` and `/var/log/kern.log`
|
||||
- Using tools like `tcpdump` and `wireshark` to capture and analyze network traffic
|
||||
|
||||
## 7. Resolving Software Conflicts
|
||||
Software conflicts can arise due to incompatible packages, configuration issues, or library dependencies. You can address these problems by:
|
||||
- Checking for package updates and conflicts using package management tools like `apt`, `yum`, or `dnf`
|
||||
- Inspecting configuration files for any conflicts or errors
|
||||
- Identifying and resolving shared library dependencies using tools like `ldd`
|
||||
- Performing a system reset or reinstallation as a last resort
|
||||
|
||||
## 8. Advanced Troubleshooting Tools
|
||||
There are various advanced troubleshooting tools available in Linux, including:
|
||||
- `strace`: Trace system calls and signals
|
||||
- `ltrace`: Trace library calls
|
||||
- `gdb`: The GNU Debugger for debugging applications
|
||||
- `SystemTap`: A comprehensive instrumentation framework
|
||||
- `perf`: Performance analysis tools for Linux
|
||||
- `bpftrace`: A powerful debugger for Linux
|
||||
|
||||
## 9. Best Practices for Effective Troubleshooting
|
||||
To effectively troubleshoot Linux systems, keep the following best practices in mind:
|
||||
- Maintain a systematic and methodical approach
|
||||
- Gather as much relevant information as possible
|
||||
- Utilize multiple troubleshooting tools and techniques
|
||||
- Document the troubleshooting process and findings
|
||||
- Regularly backup and maintain your system
|
||||
- Stay up-to-date with the latest Linux developments
|
||||
|
||||
## 10. Conclusion
|
||||
Advanced system troubleshooting in Linux requires a deep understanding of the operating system, its components, and the various tools available. By following the techniques and best practices outlined in this guide, you will be better equipped to diagnose and resolve complex issues on your Linux systems.
|
||||
@ -0,0 +1,126 @@
|
||||
Automating installations and setting up PXE (Preboot Execution Environment) boots on Linux Mint can streamline the deployment process for multiple systems. Here’s a guide to help you get started:
|
||||
|
||||
### Automated Installations
|
||||
|
||||
1. **Using Preseed Files**:
|
||||
- Preseed files allow you to automate the installation process by providing answers to the installation prompts.
|
||||
- Create a preseed file (`preseed.cfg`) with your configuration:
|
||||
```plaintext
|
||||
d-i debian-installer/locale string en_US
|
||||
d-i keyboard-configuration/xkb-keymap select us
|
||||
d-i netcfg/get_hostname string mint
|
||||
d-i netcfg/get_domain string local
|
||||
d-i mirror/country string manual
|
||||
d-i mirror/http/hostname string archive.ubuntu.com
|
||||
d-i mirror/http/directory string /ubuntu
|
||||
d-i mirror/http/proxy string
|
||||
d-i passwd/root-password password rootpassword
|
||||
d-i passwd/root-password-again password rootpassword
|
||||
d-i passwd/user-fullname string User
|
||||
d-i passwd/username string user
|
||||
d-i passwd/user-password password userpassword
|
||||
d-i passwd/user-password-again password userpassword
|
||||
d-i clock-setup/utc boolean true
|
||||
d-i time/zone string UTC
|
||||
d-i partman-auto/method string regular
|
||||
d-i partman-auto/choose_recipe select atomic
|
||||
d-i partman/confirm boolean true
|
||||
d-i partman/confirm_nooverwrite boolean true
|
||||
d-i partman/confirm_write_new_label boolean true
|
||||
```
|
||||
- Use the preseed file during installation by appending it to the boot parameters:
|
||||
```plaintext
|
||||
linux /install/vmlinuz auto=true priority=critical preseed/url=http://yourserver/preseed.cfg
|
||||
```
|
||||
|
||||
2. **Using Kickstart**:
|
||||
- Kickstart files are another method for automating installations, commonly used with Red Hat-based distributions but also supported by Debian-based systems.
|
||||
- Create a kickstart file (`ks.cfg`) with your configuration:
|
||||
```plaintext
|
||||
lang en_US
|
||||
keyboard us
|
||||
timezone UTC
|
||||
rootpw rootpassword
|
||||
user user --password userpassword
|
||||
reboot
|
||||
```
|
||||
- Use the kickstart file during installation by appending it to the boot parameters:
|
||||
```plaintext
|
||||
linux /install/vmlinuz ks=http://yourserver/ks.cfg
|
||||
```
|
||||
|
||||
### Setting Up PXE Boot
|
||||
|
||||
1. **Install and Configure a TFTP Server**:
|
||||
- Install the TFTP server:
|
||||
```bash
|
||||
sudo apt-get install tftpd-hpa
|
||||
```
|
||||
- Configure the TFTP server by editing `/etc/default/tftpd-hpa`:
|
||||
```plaintext
|
||||
TFTP_USERNAME="tftp"
|
||||
TFTP_DIRECTORY="/var/lib/tftpboot"
|
||||
TFTP_ADDRESS="0.0.0.0:69"
|
||||
TFTP_OPTIONS="--secure"
|
||||
```
|
||||
- Restart the TFTP server:
|
||||
```bash
|
||||
sudo systemctl restart tftpd-hpa
|
||||
```
|
||||
|
||||
2. **Install and Configure a DHCP Server**:
|
||||
- Install the DHCP server:
|
||||
```bash
|
||||
sudo apt-get install isc-dhcp-server
|
||||
```
|
||||
- Configure the DHCP server by editing `/etc/dhcp/dhcpd.conf`:
|
||||
```plaintext
|
||||
subnet 192.168.1.0 netmask 255.255.255.0 {
|
||||
range 192.168.1.10 192.168.1.100;
|
||||
option routers 192.168.1.1;
|
||||
option domain-name-servers 8.8.8.8, 8.8.4.4;
|
||||
filename "pxelinux.0";
|
||||
next-server 192.168.1.1;
|
||||
}
|
||||
```
|
||||
- Restart the DHCP server:
|
||||
```bash
|
||||
sudo systemctl restart isc-dhcp-server
|
||||
```
|
||||
|
||||
3. **Prepare PXE Boot Files**:
|
||||
- Download and extract the PXE boot files:
|
||||
```bash
|
||||
sudo apt-get install syslinux
|
||||
sudo cp /usr/lib/syslinux/pxelinux.0 /var/lib/tftpboot/
|
||||
sudo mkdir -p /var/lib/tftpboot/pxelinux.cfg
|
||||
sudo cp /usr/lib/syslinux/menu.c32 /var/lib/tftpboot/
|
||||
sudo cp /usr/lib/syslinux/memdisk /var/lib/tftpboot/
|
||||
sudo cp /usr/lib/syslinux/mboot.c32 /var/lib/tftpboot/
|
||||
sudo cp /usr/lib/syslinux/chain.c32 /var/lib/tftpboot/
|
||||
```
|
||||
- Create a PXE configuration file (`/var/lib/tftpboot/pxelinux.cfg/default`):
|
||||
```plaintext
|
||||
DEFAULT menu.c32
|
||||
PROMPT 0
|
||||
TIMEOUT 300
|
||||
ONTIMEOUT local
|
||||
MENU TITLE PXE Boot Menu
|
||||
|
||||
LABEL Linux Mint
|
||||
MENU LABEL Install Linux Mint
|
||||
KERNEL /install/vmlinuz
|
||||
APPEND initrd=/install/initrd.gz auto=true priority=critical preseed/url=http://yourserver/preseed.cfg
|
||||
```
|
||||
|
||||
4. **Boot from PXE**:
|
||||
- Configure your client machines to boot from the network (PXE) in the BIOS/UEFI settings.
|
||||
- The client machines should now boot from the PXE server and start the automated installation process.
|
||||
|
||||
These steps should help you set up automated installations and PXE boots on Linux Mint¹²³⁴. If you have any specific questions or need further assistance, feel free to ask!
|
||||
|
||||
Source: Conversation with Copilot, 7/19/2024
|
||||
- [(1) How To: Boot Linux Mint 19.3 Over Network PXE Using SERVA ... - Ares Galaxy.]( https://www.aresgalaxy.org/system-administration/how-to/boot-linux-mint-19-3-over-network-pxe-using-serva-on-windows-7-8-10.)
|
||||
- [(2) Setup PXE Boot Server using cloud-init for Ubuntu 20.04 ... - GoLinuxCloud.](https://www.golinuxcloud.com/pxe-boot-server-cloud-init-ubuntu-20-04/.)
|
||||
- [(3) Setting up a 'PXE Network Boot Server' for Multiple Linux ... - Tecmint.](https://www.tecmint.com/install-pxe-network-boot-server-in-centos-7/.)
|
||||
- [(4) Setup Network boot for installing OS using PXE server.](https://www.protocolten.com/postbase/setup-network-boot-for-installing-os-using-pxe-server.)
|
||||
@ -0,0 +1,66 @@
|
||||
# Understanding the boot process and troubleshooting boot issues in Linux Mint can help you resolve many common problems. Here's a breakdown of the boot process and some troubleshooting steps:
|
||||
|
||||
## Linux Mint Boot Process
|
||||
|
||||
1. **BIOS/UEFI Initialization**:
|
||||
- When you power on your computer, the BIOS (Basic Input/Output System) or UEFI (Unified Extensible Firmware Interface) initializes the hardware and performs a POST (Power-On Self-Test).
|
||||
- The BIOS/UEFI then looks for a bootable device (e.g., hard drive, USB, CD/DVD) and loads the bootloader from the Master Boot Record (MBR) or GUID Partition Table (GPT).
|
||||
|
||||
2. **Bootloader**:
|
||||
- The bootloader (GRUB in most Linux distributions) is responsible for loading the Linux kernel into memory.
|
||||
- GRUB displays a menu where you can select the operating system or kernel version to boot.
|
||||
|
||||
3. **Kernel Initialization**:
|
||||
- The Linux kernel is loaded into memory and initializes the hardware.
|
||||
- The kernel mounts the root filesystem and starts the `init` process (or `systemd` in modern distributions).
|
||||
|
||||
4. **Init/Systemd**:
|
||||
- The `init` or `systemd` process is the first user-space process and has PID 1.
|
||||
- It starts all other processes and services according to the configuration files.
|
||||
|
||||
### Troubleshooting Boot Issues
|
||||
|
||||
1. **Check BIOS/UEFI Settings**:
|
||||
- Ensure that your boot device is correctly configured in the BIOS/UEFI settings.
|
||||
- Disable Secure Boot if it causes issues with booting Linux Mint¹.
|
||||
|
||||
2. **Run a File System Check**:
|
||||
- Boot from a live USB or CD and run a file system check on your root partition:
|
||||
```bash
|
||||
sudo fsck /dev/sdXn
|
||||
```
|
||||
- Replace `/dev/sdXn` with your actual root partition identifier.
|
||||
|
||||
3. **Reinstall GRUB**:
|
||||
- Boot from a live USB or CD and open a terminal.
|
||||
- Mount your root partition and reinstall GRUB:
|
||||
```bash
|
||||
sudo mount /dev/sdXn /mnt
|
||||
sudo grub-install --root-directory=/mnt /dev/sdX
|
||||
sudo update-grub
|
||||
```
|
||||
- Replace `/dev/sdXn` with your root partition and `/dev/sdX` with your disk.
|
||||
|
||||
4. **Check Boot Logs**:
|
||||
- Review boot logs for errors:
|
||||
```bash
|
||||
cat /var/log/boot.log
|
||||
journalctl -b
|
||||
```
|
||||
|
||||
5. **Use Boot Repair Tool**:
|
||||
- Install and run the Boot Repair tool from a live session:
|
||||
```bash
|
||||
sudo add-apt-repository ppa:yannubuntu/boot-repair
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y boot-repair
|
||||
boot-repair
|
||||
```
|
||||
- Follow the on-screen instructions to repair your boot configuration²³⁴.
|
||||
|
||||
These steps should help you diagnose and fix common boot issues in Linux Mint. If you encounter specific errors or need further assistance, feel free to ask!
|
||||
|
||||
- [(1) A Comprehensive Guide to Fixing Boot Problems in Linux Mint.](https://www.fosslinux.com/105028/the-comprehensive-guide-to-fixing-boot-problems-in-linux-mint.htm.)
|
||||
- [(2) How to Determine and Fix Boot Issues in Linux - Tecmint.](https://www.tecmint.com/find-and-fix-linux-boot-issues/.)
|
||||
- [(3) Linux Mint Troubleshooting Guide: Solutions to Common Issues.](https://www.fosslinux.com/104779/the-guide-to-troubleshooting-common-linux-mint-issues.htm.)
|
||||
- [(4) Solve Your Issues with Linux Mint Boot Repair: A Quick Guide.](https://www.howto-do.it/linux-mint-boot-repair/.)
|
||||
@ -0,0 +1,90 @@
|
||||
# Data Recovery Techniques
|
||||
|
||||
## 1. Understanding Data Loss Scenarios
|
||||
- Accidental deletion
|
||||
- File system corruption
|
||||
- Hardware failure
|
||||
- Malware or cyber attacks
|
||||
- Improper system shutdown
|
||||
|
||||
## 2. Preparation for Data Recovery
|
||||
- Stop using the affected drive immediately
|
||||
- Boot from a live Linux distribution (e.g., Ubuntu Live USB)
|
||||
- Prepare a separate storage device for recovered data
|
||||
|
||||
## 3. File Recovery Tools
|
||||
### a) TestDisk
|
||||
- Powerful, open-source tool for recovering lost partitions
|
||||
- Can fix partition tables and recover deleted partitions
|
||||
- Usage: `sudo testdisk /dev/sdX` (replace X with the appropriate drive letter)
|
||||
|
||||
### b) PhotoRec
|
||||
- File carver that can recover various file types
|
||||
- Works even when the file system is severely damaged
|
||||
- Usage: `sudo photorec /dev/sdX`
|
||||
|
||||
### c) Foremost
|
||||
- Forensic data recovery tool
|
||||
- Recovers files based on headers, footers, and internal data structures
|
||||
- Usage: `sudo foremost -i /dev/sdX -o /path/to/output/directory`
|
||||
|
||||
### d) Scalpel
|
||||
- Another file carver with a configurable database of file types
|
||||
- Usage: `sudo scalpel /dev/sdX -o /path/to/output/directory`
|
||||
|
||||
## 4. Command-Line Data Recovery Techniques
|
||||
### a) Using dd to create a disk image
|
||||
- `sudo dd if=/dev/sdX of=/path/to/disk_image.img bs=4M conv=noerror,sync`
|
||||
- This creates a bit-by-bit copy of the drive for safer recovery attempts
|
||||
|
||||
### b) Recovering deleted files with extundelete (for ext3/ext4 filesystems)
|
||||
- `sudo extundelete /dev/sdX --restore-all`
|
||||
|
||||
### c) Using grep to search for specific file content
|
||||
- `sudo grep -a -C 100 "unique_string" /dev/sdX > recovered_data.txt`
|
||||
|
||||
## 5. File System-Specific Recovery Techniques
|
||||
### a) Ext3/Ext4
|
||||
- Use e2fsck for filesystem check and repair: `sudo e2fsck -f /dev/sdX`
|
||||
- Recover journal: `sudo debugfs -w /dev/sdX`
|
||||
|
||||
### b) NTFS (for dual-boot systems or external drives)
|
||||
- Use ntfsfix: `sudo ntfsfix /dev/sdX`
|
||||
|
||||
### c) XFS
|
||||
- Use xfs_repair: `sudo xfs_repair /dev/sdX`
|
||||
|
||||
## 6. Advanced Recovery Techniques
|
||||
### a) File Carving with Sleuthkit
|
||||
- `sudo fls -r /dev/sdX`
|
||||
- `sudo icat /dev/sdX [inode] > recovered_file`
|
||||
|
||||
### b) Using ddrescue for damaged drives
|
||||
- `sudo ddrescue /dev/sdX /path/to/image.img /path/to/logfile.log`
|
||||
|
||||
### c) Recovering RAID arrays
|
||||
- Use mdadm to reassemble the array: `sudo mdadm --assemble --scan`
|
||||
|
||||
## 7. Data Recovery from SSDs
|
||||
- Use hdparm to check if TRIM is enabled: `sudo hdparm -I /dev/sdX | grep TRIM`
|
||||
- If TRIM is enabled, recovery chances are significantly reduced
|
||||
- Use specialized SSD recovery software like R-Studio or ReclaiMe
|
||||
|
||||
## 8. Prevention and Best Practices
|
||||
- Regularly backup important data
|
||||
- Use journaling file systems
|
||||
- Implement RAID for critical systems
|
||||
- Properly shut down systems
|
||||
- Use UPS to prevent power-related issues
|
||||
|
||||
## 9. When to Seek Professional Help
|
||||
- Physical drive damage
|
||||
- Critical data with high monetary or sentimental value
|
||||
- Legal or compliance requirements
|
||||
|
||||
## 10. Legal and Ethical Considerations
|
||||
- Ensure you have the right to recover the data
|
||||
- Be aware of data protection laws and regulations
|
||||
- Handle sensitive recovered data with care
|
||||
|
||||
Remember that data recovery success rates vary depending on the specific scenario and the time elapsed since data loss. Always prioritize creating a backup before attempting any recovery techniques to avoid further data loss.
|
||||
@ -0,0 +1,72 @@
|
||||
## Deploying custom Linux environments on Linux Mint can be a powerful way to tailor the operating system to your specific needs. Here are some methods and tools you can use:
|
||||
|
||||
### Creating a Custom Linux Mint ISO
|
||||
|
||||
1. **Using Cubic (Custom Ubuntu ISO Creator)**:
|
||||
- **Install Cubic**:
|
||||
```bash
|
||||
sudo apt-add-repository ppa:cubic-wizard/release
|
||||
sudo apt update
|
||||
sudo apt install cubic
|
||||
```
|
||||
- **Customize the ISO**:
|
||||
- Launch Cubic and select the original ISO file.
|
||||
- Enter the chroot environment to make changes, such as installing packages, modifying configurations, and adding custom scripts.
|
||||
- Save and build the customized ISO¹.
|
||||
|
||||
2. **Using Linux Live Kit**:
|
||||
- **Download and Extract**:
|
||||
```bash
|
||||
wget https://github.com/Tomas-M/linux-live/archive/master.zip
|
||||
unzip master.zip
|
||||
cd linux-live-master
|
||||
```
|
||||
- **Customize Your System**:
|
||||
- Install and configure the software you need on your base system.
|
||||
- **Create the Live ISO**:
|
||||
```bash
|
||||
sudo ./build
|
||||
```
|
||||
|
||||
### Building a Custom Linux Distribution
|
||||
|
||||
1. **Using Linux From Scratch (LFS)**:
|
||||
- **Follow the LFS Guide**:
|
||||
- The LFS project provides a comprehensive guide to building a custom Linux system from source code. This method is more advanced and allows for deep customization².
|
||||
|
||||
2. **Using Buildroot**:
|
||||
- **Install Buildroot**:
|
||||
```bash
|
||||
sudo apt-get install buildroot
|
||||
```
|
||||
- **Configure and Build**:
|
||||
- Use Buildroot to configure and compile a minimal Linux system tailored to your needs.
|
||||
|
||||
### Deploying Custom Environments
|
||||
|
||||
1. **Using Virtual Machines**:
|
||||
- **Install VirtualBox or VMware**:
|
||||
```bash
|
||||
sudo apt-get install virtualbox
|
||||
```
|
||||
- **Create and Configure VMs**:
|
||||
- Use the custom ISO to install the OS on virtual machines for testing and deployment.
|
||||
|
||||
2. **Using Containers**:
|
||||
- **Install LXC**:
|
||||
```bash
|
||||
sudo apt-get install lxc
|
||||
```
|
||||
- **Create and Manage Containers**:
|
||||
- Create containers with your custom environment and manage them using LXC commands.
|
||||
|
||||
### Additional Resources
|
||||
|
||||
For more detailed instructions, you can refer to guides like [It's FOSS](https://itsfoss.com/create-custom-linux-mint-iso/)¹ and [Byte Bite Bit](https://bytebitebit.com/operating-system/linux/how-to-make-a-linux-distro/)².
|
||||
|
||||
If you have any specific requirements or need further assistance, feel free to ask!
|
||||
|
||||
Source: Conversation with Copilot, 7/19/2024
|
||||
- [(1) How to Create Custom Linux Mint or Ubuntu ISO - It's FOSS.](https://itsfoss.com/create-custom-linux-mint-iso/.)
|
||||
- [(2) How to Make a Linux Distro: A Step-by-Step Guide for Developers.](https://bytebitebit.com/operating-system/linux/how-to-make-a-linux-distro/.)
|
||||
- [(3) Linux Mint - Community.](https://community.linuxmint.com/tutorial/view/1784.)
|
||||
@ -0,0 +1,91 @@
|
||||
## Deploying environment-specific cloud desktop servers on Linux Mint can be a powerful way to provide remote access to customized desktop environments. Here are some methods and tools to help you achieve this:
|
||||
|
||||
### Using Cloud-init for Automated Deployment
|
||||
|
||||
1. **Install Cloud-init**:
|
||||
- Cloud-init is a tool for automating the initial setup of cloud instances. It can be used to configure your Linux Mint environment during the first boot.
|
||||
- Install Cloud-init:
|
||||
```bash
|
||||
sudo apt-get install cloud-init
|
||||
```
|
||||
|
||||
2. **Create a Cloud-init Configuration File**:
|
||||
- Create a `user-data` file with your desired configuration:
|
||||
```yaml
|
||||
#cloud-config
|
||||
users:
|
||||
- name: user
|
||||
ssh-authorized-keys:
|
||||
- ssh-rsa AAAAB3...your-public-key
|
||||
sudo: ['ALL=(ALL) NOPASSWD:ALL']
|
||||
groups: sudo
|
||||
shell: /bin/bash
|
||||
packages:
|
||||
- vim
|
||||
- git
|
||||
- docker.io
|
||||
runcmd:
|
||||
- echo "Custom setup complete"
|
||||
```
|
||||
|
||||
3. **Deploy the Configuration**:
|
||||
- Use the configuration file during the deployment of your cloud instance. This can be done through your cloud provider's interface or by attaching the configuration file to the instance.
|
||||
|
||||
### Using Docker for Cloud Desktops
|
||||
|
||||
1. **Install Docker**:
|
||||
- Docker can be used to create containerized desktop environments that can be accessed remotely.
|
||||
- Install Docker:
|
||||
```bash
|
||||
sudo apt-get install docker.io
|
||||
```
|
||||
|
||||
2. **Run a Desktop Environment in a Container**:
|
||||
- Use a Docker image that provides a desktop environment, such as `linuxserver/webtop`:
|
||||
```bash
|
||||
docker run -d \
|
||||
--name=webtop \
|
||||
-e PUID=1000 \
|
||||
-e PGID=1000 \
|
||||
-e TZ=Etc/UTC \
|
||||
-p 3000:3000 \
|
||||
--shm-size="1gb" \
|
||||
linuxserver/webtop
|
||||
```
|
||||
- Access the desktop environment through your web browser at `http://your-server-ip:3000`.
|
||||
|
||||
### Using Virtual Machines
|
||||
|
||||
1. **Install VirtualBox**:
|
||||
- VirtualBox can be used to create virtual machines with different Linux distributions.
|
||||
- Install VirtualBox:
|
||||
```bash
|
||||
sudo apt-get install virtualbox
|
||||
```
|
||||
|
||||
2. **Create and Configure VMs**:
|
||||
- Create virtual machines for each environment-specific deployment.
|
||||
- Configure each VM with the necessary software and settings.
|
||||
|
||||
### Using LTSP (Linux Terminal Server Project)
|
||||
|
||||
1. **Install LTSP**:
|
||||
- LTSP allows you to boot multiple clients from a central server, providing a consistent desktop environment.
|
||||
- Install LTSP:
|
||||
```bash
|
||||
sudo apt-get install ltsp
|
||||
```
|
||||
|
||||
2. **Configure LTSP**:
|
||||
- Follow the LTSP documentation to set up and configure your server and clients.
|
||||
|
||||
### Additional Resources
|
||||
|
||||
For more detailed instructions, you can refer to guides like [FOSS Linux](https://www.fosslinux.com/105884/the-beginners-guide-to-linux-mint-cloud-computing.htm)² and [LinuxServer.io](https://www.linuxserver.io/blog/2021-05-05-meet-webtops-a-linux-desktop-environment-in-your-browser)³.
|
||||
|
||||
If you have any specific questions or need further assistance, feel free to ask!
|
||||
|
||||
Source: Conversation with Copilot, 7/19/2024
|
||||
- [(1) The beginner’s guide to Linux Mint cloud computing - FOSS Linux.](https://www.fosslinux.com/105884/the-beginners-guide-to-linux-mint-cloud-computing.htm.)
|
||||
- [(2) Meet Webtops A Linux Desktop Environment In Your Browser.](https://www.linuxserver.io/blog/2021-05-05-meet-webtops-a-linux-desktop-environment-in-your-browser.)
|
||||
- [(3) Cloud-init but for Ubuntu/Mint desktop? : r/sysadmin - Reddit.](https://www.reddit.com/r/sysadmin/comments/z1em4z/cloudinit_but_for_ubuntumint_desktop/.)
|
||||
@ -0,0 +1,69 @@
|
||||
## Managing multiple Linux distributions on a single system can be quite efficient and flexible. Here are some methods and tools to help you manage multi-distro systems on Linux Mint:
|
||||
|
||||
### Dual Booting
|
||||
|
||||
1. **Install Multiple Distros**:
|
||||
- You can install multiple Linux distributions on separate partitions of your hard drive. During the installation process, ensure you select the correct partition for each distro.
|
||||
- Use a tool like **GParted** to manage your partitions:
|
||||
```bash
|
||||
sudo apt-get install gparted
|
||||
sudo gparted
|
||||
```
|
||||
|
||||
2. **Configure GRUB**:
|
||||
- GRUB (GRand Unified Bootloader) will allow you to select which OS to boot into. After installing multiple distros, update GRUB to include all installed systems:
|
||||
```bash
|
||||
sudo update-grub
|
||||
```
|
||||
|
||||
### Using Ventoy
|
||||
|
||||
1. **Install Ventoy**:
|
||||
- Ventoy is a tool that allows you to boot multiple Linux distributions from a single USB drive without needing to reflash it each time¹.
|
||||
- Download and install Ventoy:
|
||||
```bash
|
||||
wget https://github.com/ventoy/Ventoy/releases/download/v1.0.76/ventoy-1.0.76-linux.tar.gz
|
||||
tar -xvf ventoy-1.0.76-linux.tar.gz
|
||||
cd ventoy-1.0.76
|
||||
sudo ./Ventoy2Disk.sh -i /dev/sdX
|
||||
```
|
||||
- Replace `/dev/sdX` with your USB drive identifier.
|
||||
|
||||
2. **Add ISOs to Ventoy**:
|
||||
- Simply copy the ISO files of the distributions you want to the USB drive. Ventoy will automatically detect and list them at boot.
|
||||
|
||||
### Using Distrobox
|
||||
|
||||
1. **Install Distrobox**:
|
||||
- Distrobox allows you to run multiple Linux distributions inside the terminal using Docker or Podman²³.
|
||||
- Install Docker or Podman:
|
||||
```bash
|
||||
sudo apt-get install docker.io
|
||||
```
|
||||
- Install Distrobox:
|
||||
```bash
|
||||
curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/install | sudo sh
|
||||
```
|
||||
|
||||
2. **Create and Manage Containers**:
|
||||
- Create a new container with a specific distro:
|
||||
```bash
|
||||
distrobox-create --name my-container --image ubuntu:latest
|
||||
```
|
||||
- Enter the container:
|
||||
```bash
|
||||
distrobox-enter my-container
|
||||
```
|
||||
|
||||
### Additional Resources
|
||||
|
||||
For more detailed instructions, you can refer to guides like [How to Geek](https://www.howtogeek.com/802328/how-to-boot-multiple-linux-distributions-with-ventoy/)¹ and [MakeUseOf](https://www.makeuseof.com/run-multiple-linux-distros-inside-terminal-distrobox/)².
|
||||
|
||||
If you have any specific questions or need further assistance, feel free to ask!
|
||||
|
||||
Source: Conversation with Copilot, 7/19/2024
|
||||
- [(1) How to Boot Multiple Linux Distributions With Ventoy.](https://www.howtogeek.com/802328/how-to-boot-multiple-linux-distributions-with-ventoy/.)
|
||||
- [(2) How to Run Multiple Linux Distributions Inside the Terminal Using Distrobox.](https://www.makeuseof.com/run-multiple-linux-distros-inside-terminal-distrobox/.)
|
||||
- [(3) DistroBox: Try Out Multiple Linux Distributions via the Terminal.](https://linuxtldr.com/installing-distrobox/.)
|
||||
- [(4) How to dual boot two Linux distributions - The Linux User.](https://thelinuxuser.com/dual-boot-two-linux-distributions/.)
|
||||
- [(5) en.wikipedia.org.](https://en.wikipedia.org/wiki/Linux_distribution.)
|
||||
88
14 - Linux Troubleshooting and Recovery/System Recovery.md
Normal file
88
14 - Linux Troubleshooting and Recovery/System Recovery.md
Normal file
@ -0,0 +1,88 @@
|
||||
# Linux System Recovery
|
||||
|
||||
## 1. Assess the Problem
|
||||
First, determine the nature of the issue:
|
||||
- Boot failure
|
||||
- File system corruption
|
||||
- Broken package dependencies
|
||||
- Kernel panic
|
||||
- Forgotten root password
|
||||
|
||||
## 2. Boot into Recovery Mode
|
||||
Most Linux distributions offer a recovery mode:
|
||||
- Restart your system
|
||||
- Press and hold Shift (for GRUB2) during boot
|
||||
- Select "Advanced options" then "Recovery mode"
|
||||
|
||||
## 3. Check File System Integrity
|
||||
Use fsck (file system check) utility:
|
||||
```
|
||||
fsck /dev/sdXY
|
||||
```
|
||||
Replace X with the drive letter and Y with the partition number.
|
||||
|
||||
## 4. Mount File Systems
|
||||
If necessary, remount the root file system as read-write:
|
||||
```
|
||||
mount -o remount,rw /
|
||||
```
|
||||
|
||||
## 5. Network Connectivity
|
||||
Enable networking for package management:
|
||||
```
|
||||
dhclient -v
|
||||
```
|
||||
|
||||
## 6. Package Management Recovery
|
||||
Fix broken dependencies:
|
||||
```
|
||||
apt --fix-broken install # For Debian-based systems
|
||||
dnf distro-sync # For Fedora-based systems
|
||||
```
|
||||
|
||||
## 7. Kernel Issues
|
||||
Boot into an older kernel version from GRUB menu. If successful, investigate the issue with the newer kernel.
|
||||
|
||||
## 8. Reset Root Password
|
||||
If you've forgotten the root password:
|
||||
```
|
||||
passwd root
|
||||
```
|
||||
|
||||
## 9. Recover GRUB
|
||||
If GRUB is corrupted:
|
||||
- a. Boot from a live USB
|
||||
- b. Mount your root partition
|
||||
- c. Chroot into it
|
||||
- d. Reinstall GRUB:
|
||||
```
|
||||
grub-install /dev/sdX
|
||||
update-grub
|
||||
```
|
||||
|
||||
## 10. Repair Corrupted Files
|
||||
Use tools like `dd` or `ddrescue` to recover data from failing drives.
|
||||
|
||||
## 11. Log Analysis
|
||||
Check system logs for clues:
|
||||
```
|
||||
journalctl -xb # For systemd-based systems
|
||||
less /var/log/syslog # For traditional syslog systems
|
||||
```
|
||||
|
||||
## 12. Backup and Restore
|
||||
Always maintain backups. Use tools like `rsync` or `tar` for backing up, and restore when needed.
|
||||
|
||||
## 13. Rescue Disk
|
||||
Keep a rescue disk (like SystemRescue) handy for severe cases.
|
||||
|
||||
## 14. Data Recovery
|
||||
For deleted files, use tools like `testdisk` or `photorec`.
|
||||
|
||||
## 15. Safe Mode and Single-User Mode
|
||||
Boot into these modes for minimal system access to perform repairs.
|
||||
|
||||
## 16. Reinstallation
|
||||
As a last resort, reinstall the system while preserving /home if possible.
|
||||
|
||||
Remember: Always approach system recovery cautiously. If you're unsure, consult documentation or seek help from the Linux community.
|
||||
@ -0,0 +1,197 @@
|
||||
# Troubleshooting Hardware and Device Drivers
|
||||
|
||||
## 1. Identifying Hardware and Drivers
|
||||
|
||||
### a) List all hardware:
|
||||
```
|
||||
lshw
|
||||
```
|
||||
This command provides detailed information about your system's hardware configuration.
|
||||
|
||||
### b) List PCI devices:
|
||||
```
|
||||
lspci
|
||||
```
|
||||
Shows all PCI devices connected to your system.
|
||||
|
||||
### c) List USB devices:
|
||||
```
|
||||
lsusb
|
||||
```
|
||||
Displays all USB devices connected to your system.
|
||||
|
||||
### d) Check loaded kernel modules:
|
||||
```
|
||||
lsmod
|
||||
```
|
||||
Lists all currently loaded kernel modules (drivers).
|
||||
|
||||
## 2. Checking System Logs
|
||||
|
||||
### a) View kernel messages:
|
||||
```
|
||||
dmesg
|
||||
```
|
||||
Displays kernel-related messages, including hardware detection and driver loading.
|
||||
|
||||
### b) Check system logs:
|
||||
```
|
||||
journalctl
|
||||
```
|
||||
For systems using systemd, this command shows system logs.
|
||||
|
||||
## 3. Managing Drivers
|
||||
|
||||
### a) Load a module:
|
||||
```
|
||||
sudo modprobe module_name
|
||||
```
|
||||
|
||||
### b) Unload a module:
|
||||
```
|
||||
sudo modprobe -r module_name
|
||||
```
|
||||
|
||||
### c) Blacklist a module:
|
||||
Add the following line to /etc/modprobe.d/blacklist.conf:
|
||||
```
|
||||
blacklist module_name
|
||||
```
|
||||
|
||||
## 4. Troubleshooting Specific Hardware Types
|
||||
|
||||
### a) Network interfaces:
|
||||
- Check network interface status:
|
||||
```
|
||||
ip link show
|
||||
```
|
||||
- Bring an interface up or down:
|
||||
```
|
||||
sudo ip link set interface_name up/down
|
||||
```
|
||||
|
||||
### b) Graphics:
|
||||
- Check graphics card information:
|
||||
```
|
||||
lspci | grep VGA
|
||||
```
|
||||
- For NVIDIA GPUs, use:
|
||||
```
|
||||
nvidia-smi
|
||||
```
|
||||
|
||||
### c) Audio:
|
||||
- List audio devices:
|
||||
```
|
||||
aplay -l
|
||||
```
|
||||
- Check ALSA mixer settings:
|
||||
```
|
||||
alsamixer
|
||||
```
|
||||
|
||||
## 5. Firmware Issues
|
||||
|
||||
### a) Check for missing firmware:
|
||||
```
|
||||
dmesg | grep firmware
|
||||
```
|
||||
|
||||
### b) Install firmware packages:
|
||||
```
|
||||
sudo apt install linux-firmware
|
||||
```
|
||||
(For Debian/Ubuntu-based systems)
|
||||
|
||||
## 6. Kernel Parameters
|
||||
|
||||
Modify kernel parameters by editing /etc/default/grub and updating GRUB_CMDLINE_LINUX_DEFAULT. After changes, run:
|
||||
```
|
||||
sudo update-grub
|
||||
```
|
||||
|
||||
## 7. Driver Compilation
|
||||
|
||||
### If you need to compile a driver:
|
||||
- a) Install build essentials:
|
||||
```
|
||||
sudo apt install build-essential linux-headers-$(uname -r)
|
||||
```
|
||||
|
||||
- b) Download driver source, then typically:
|
||||
```
|
||||
make
|
||||
sudo make install
|
||||
```
|
||||
|
||||
## 8. Debugging Tools
|
||||
|
||||
- a) strace: Trace system calls and signals
|
||||
```
|
||||
strace command
|
||||
```
|
||||
|
||||
- b) ltrace: Library call tracer
|
||||
```
|
||||
ltrace command
|
||||
```
|
||||
|
||||
## 9. Hardware Information Tools
|
||||
|
||||
- a) inxi: Comprehensive hardware information
|
||||
```
|
||||
inxi -Fxz
|
||||
```
|
||||
|
||||
- b) hwinfo: Another detailed hardware information tool
|
||||
```
|
||||
hwinfo --short
|
||||
```
|
||||
|
||||
## 10. Kernel Configuration
|
||||
|
||||
Check current kernel configuration:
|
||||
```
|
||||
zcat /proc/config.gz
|
||||
```
|
||||
(If available)
|
||||
|
||||
## 11. Udev Rules
|
||||
|
||||
Manage device events and permissions by creating or modifying rules in /etc/udev/rules.d/.
|
||||
|
||||
## 12. Benchmarking and Stress Testing
|
||||
|
||||
- a) CPU stress test:
|
||||
```
|
||||
stress --cpu 8 --timeout 20s
|
||||
```
|
||||
|
||||
- b) Disk benchmark:
|
||||
```
|
||||
sudo hdparm -tT /dev/sda
|
||||
```
|
||||
|
||||
## 13. Power Management
|
||||
|
||||
a) Check CPU frequency scaling:
|
||||
```
|
||||
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
|
||||
```
|
||||
|
||||
b) Set performance mode:
|
||||
```
|
||||
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
|
||||
```
|
||||
|
||||
## 14. Troubleshooting Steps
|
||||
|
||||
1. Identify the problem hardware or driver
|
||||
2. Check system logs for errors
|
||||
3. Ensure correct drivers are installed and loaded
|
||||
4. Try different kernel parameters
|
||||
5. Update or downgrade drivers if necessary
|
||||
6. Check for conflicts with other hardware or software
|
||||
7. Test hardware in a live Linux environment to isolate OS issues
|
||||
|
||||
Remember to backup important data before making significant system changes. If you're unsure about any step, research further or seek help from the Linux community forums specific to your distribution.
|
||||
@ -0,0 +1,213 @@
|
||||
# Automated Installations
|
||||
|
||||
Automated installation, also known as unattended installation or silent installation, is the process of installing and configuring software without requiring manual intervention. This approach is crucial for efficiently managing large-scale deployments, maintaining consistency across systems, and reducing human error.
|
||||
|
||||
## Key Components:
|
||||
|
||||
- I. Installation Scripts
|
||||
- II. Answer Files
|
||||
- III. Deployment Tools
|
||||
- IV. Package Managers
|
||||
- V. Image-Based Deployment
|
||||
|
||||
## I. Installation Scripts
|
||||
|
||||
Installation scripts automate the process of installing software by executing a series of predefined commands. These scripts can be written in various languages such as Bash, PowerShell, or Python.
|
||||
|
||||
Key features:
|
||||
- Pre-installation checks
|
||||
- Dependency management
|
||||
- File/directory operations
|
||||
- Configuration settings
|
||||
- Post-installation tasks
|
||||
|
||||
Example (Bash script):
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
# Pre-installation checks
|
||||
if [ ! -f /path/to/dependency ]; then
|
||||
echo "Dependency not found. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Install software
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y software-package
|
||||
|
||||
# Configure settings
|
||||
sed -i 's/old_setting/new_setting/' /etc/software/config.conf
|
||||
|
||||
# Post-installation tasks
|
||||
systemctl enable software-service
|
||||
systemctl start software-service
|
||||
|
||||
echo "Installation complete."
|
||||
```
|
||||
|
||||
## II. Answer Files
|
||||
|
||||
Answer files (also called response files or unattended installation files) contain predetermined responses to installation prompts. These files allow for consistent configurations across multiple installations.
|
||||
|
||||
Common formats:
|
||||
- XML (Windows)
|
||||
- Kickstart files (Linux)
|
||||
- AutoYaST (SUSE Linux)
|
||||
- Preseed (Debian/Ubuntu)
|
||||
|
||||
Example (Windows answer file, autounattend.xml):
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<unattend xmlns="urn:schemas-microsoft-com:unattend">
|
||||
<settings pass="windowsPE">
|
||||
<component name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="[PUBLIC_KEY_TOKEN]" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<DiskConfiguration>
|
||||
<Disk wcm:action="add">
|
||||
<CreatePartitions>
|
||||
<CreatePartition wcm:action="add">
|
||||
<Order>1</Order>
|
||||
<Type>Primary</Type>
|
||||
<Size>100%</Size>
|
||||
</CreatePartition>
|
||||
</CreatePartitions>
|
||||
<ModifyPartitions>
|
||||
<ModifyPartition wcm:action="add">
|
||||
<Format>NTFS</Format>
|
||||
<Label>Windows</Label>
|
||||
<Order>1</Order>
|
||||
<PartitionID>1</PartitionID>
|
||||
</ModifyPartition>
|
||||
</ModifyPartitions>
|
||||
<DiskID>0</DiskID>
|
||||
<WillWipeDisk>true</WillWipeDisk>
|
||||
</Disk>
|
||||
</DiskConfiguration>
|
||||
<ImageInstall>
|
||||
<OSImage>
|
||||
<InstallTo>
|
||||
<DiskID>0</DiskID>
|
||||
<PartitionID>1</PartitionID>
|
||||
</InstallTo>
|
||||
</OSImage>
|
||||
</ImageInstall>
|
||||
<UserData>
|
||||
<ProductKey>
|
||||
<Key>[YOUR_PRODUCT_KEY]</Key>
|
||||
</ProductKey>
|
||||
<AcceptEula>true</AcceptEula>
|
||||
</UserData>
|
||||
</component>
|
||||
</settings>
|
||||
</unattend>
|
||||
```
|
||||
|
||||
## III. Deployment Tools
|
||||
|
||||
Deployment tools streamline the process of distributing and installing software across multiple systems.
|
||||
|
||||
Popular deployment tools:
|
||||
- Microsoft Deployment Toolkit (MDT)
|
||||
- System Center Configuration Manager (SCCM)
|
||||
- Ansible
|
||||
- Puppet
|
||||
- Chef
|
||||
|
||||
Example (Ansible playbook):
|
||||
|
||||
```yaml
|
||||
---
|
||||
- hosts: all
|
||||
become: yes
|
||||
tasks:
|
||||
- name: Update apt cache
|
||||
apt:
|
||||
update_cache: yes
|
||||
|
||||
- name: Install required packages
|
||||
apt:
|
||||
name:
|
||||
- nginx
|
||||
- postgresql
|
||||
state: present
|
||||
|
||||
- name: Copy configuration files
|
||||
copy:
|
||||
src: "{{ item.src }}"
|
||||
dest: "{{ item.dest }}"
|
||||
loop:
|
||||
- { src: 'files/nginx.conf', dest: '/etc/nginx/nginx.conf' }
|
||||
- { src: 'files/pg_hba.conf', dest: '/etc/postgresql/12/main/pg_hba.conf' }
|
||||
|
||||
- name: Start and enable services
|
||||
systemd:
|
||||
name: "{{ item }}"
|
||||
state: started
|
||||
enabled: yes
|
||||
loop:
|
||||
- nginx
|
||||
- postgresql
|
||||
```
|
||||
|
||||
## IV. Package Managers
|
||||
|
||||
Package managers automate the process of installing, upgrading, and removing software packages. They handle dependencies and ensure system consistency.
|
||||
|
||||
Common package managers:
|
||||
- apt (Debian/Ubuntu)
|
||||
- yum/dnf (Red Hat/CentOS)
|
||||
- pacman (Arch Linux)
|
||||
- Chocolatey (Windows)
|
||||
- Homebrew (macOS)
|
||||
|
||||
Example (Chocolatey package):
|
||||
|
||||
```powershell
|
||||
# Create a Chocolatey package
|
||||
choco new mypackage
|
||||
|
||||
# Edit the mypackage.nuspec file
|
||||
# Edit the tools\chocolateyinstall.ps1 file
|
||||
|
||||
# Pack the package
|
||||
choco pack
|
||||
|
||||
# Push the package to a repository
|
||||
choco push mypackage.1.0.0.nupkg --source "https://push.chocolatey.org/"
|
||||
|
||||
# Install the package
|
||||
choco install mypackage -y
|
||||
```
|
||||
|
||||
## V. Image-Based Deployment
|
||||
|
||||
Image-based deployment involves creating a preconfigured system image and deploying it to multiple machines. This method ensures consistency and reduces installation time.
|
||||
|
||||
Key steps:
|
||||
- Create a reference machine
|
||||
- Sysprep the reference machine
|
||||
- Capture the image
|
||||
- Deploy the image
|
||||
|
||||
Tools for image-based deployment:
|
||||
- Clonezilla
|
||||
- Acronis True Image
|
||||
- Symantec Ghost
|
||||
- FOG Project
|
||||
|
||||
Best Practices for Automated Installations:
|
||||
|
||||
- 1. Thoroughly test scripts and configurations before deployment
|
||||
- 2. Use version control for installation scripts and configuration files
|
||||
- 3. Implement error handling and logging in installation scripts
|
||||
- 4. Regularly update and patch deployed systems
|
||||
- 5. Secure sensitive information (e.g., passwords, license keys) in installation files
|
||||
- 6. Document the automated installation process for future reference
|
||||
- 7. Consider using infrastructure-as-code tools for managing deployments
|
||||
- 8. Implement a rollback strategy in case of failed installations
|
||||
- 9. Monitor the installation process and collect metrics for optimization
|
||||
|
||||
## Conclusion:
|
||||
|
||||
Automated installations are essential for efficient system management and software deployment. By leveraging installation scripts, answer files, deployment tools, package managers, and image-based deployment techniques, organizations can streamline their IT operations, reduce errors, and ensure consistency across their infrastructure.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user