RHEL

  

Configure Static IP 






Configure YUM





















Set Hostname





  • The #, it would indicate the root user.
  • The $ might indicate that the root shell is customized or that a non-root user is running a shell with administrative privileges.





  • Linux File System:




    Key Directories in the Linux File System

    1. / (Root Directory)

      • The top-most directory in Linux, containing all other directories.
      • Everything starts from here.
    2. /bin (Essential User Binaries)

      • Contains essential binary executables (commands) like lscpmvcatechogrep, etc.
    3. /boot (Boot Files)

      • Stores boot-related files, including the Linux kernel (vmlinuz), GRUB bootloader files, and initramfs.
    4. /dev (Device Files)

      • Contains files representing system devices (e.g., /dev/sda for disks, /dev/tty for terminals, /dev/null, etc.).
    5. /etc (Configuration Files)

      • Stores system-wide configuration files (e.g., /etc/passwd/etc/hostname/etc/network/interfaces).
    6. /home (User Home Directories)

      • Stores user-specific files and settings (e.g., /home/user1/home/user2).
    7. /lib & /lib64 (Shared Libraries)

      • Contains essential system libraries required for programs in /bin and /sbin.
    8. /media (Mount Points for Removable Media)

      • Used for automatically mounting external devices (e.g., USB drives, CDs).
    9. /mnt (Temporary Mount Points)

      • Used for manually mounting file systems like network shares or external drives.
    10. /opt (Optional Software Packages)

    • Contains third-party software and add-on applications.
    1. /proc (Process Information)
    • A virtual filesystem containing system and process-related information (e.g., /proc/cpuinfo/proc/meminfo).
    1. /root (Root User’s Home Directory)
    • The home directory for the superuser (root), separate from /home.
    1. /run (Runtime Variable Data)
    • Stores system information that changes during runtime (e.g., process IDs, sockets).
    1. /sbin (System Binaries)
    • Contains system administration commands like fdiskiptablesshutdown.
    1. /srv (Service Data)
    • Stores files related to services like HTTP (/srv/www) or FTP.
    1. /sys (System Information)
    • Provides a view of the system's hardware and kernel settings.
    1. /tmp (Temporary Files)
    • Used for temporary file storage, cleared upon reboot.
    1. /usr (User Binaries and Programs)
    • Contains user applications, libraries, documentation (/usr/bin/usr/lib/usr/share).
    1. /var (Variable Data Files)
    • Stores logs (/var/log), caches, and dynamically changing files.

    Special File Types in Linux

    • Regular Files (-) – Normal files like text, images, binaries.
    • Directories (d) – Containers that hold files (ls -l shows them with d at the start).
    • Symbolic Links (l) – Shortcuts pointing to other files (ln -s).
    • Block Devices (b) – Storage devices like hard disks (/dev/sda).
    • Character Devices (c) – Devices like keyboards (/dev/tty).
    • Named Pipes (p) – Special files for process communication.
    • Sockets (s) – Network communication endpoints.










    Change Password:



































    Soft Link:








    Hard Link:








































    Each field in /etc/passwd is separated by a colon (:) and has a specific meaning:

    1. Username: linux → The login name of the user.
    2. Password Placeholder: x → This means the password is stored in /etc/shadow (not visible here).
    3. User ID (UID): 1002 → The unique ID assigned to this user.
    4. Group ID (GID): 1002 → The primary group ID assigned to the user.
    5. Comment/Description Field: (empty) → Typically used for full names or descriptions.
    6. Home Directory: /home/linux → The user's home directory.
    7. Login Shell: /bin/bash → The default shell for this user (Bash shell).











    Now I want user "linux" to write the file "hulk"










    Issue Explanation:

    • The file hulk is located in /root, which is the home directory of the root user.
    • By default, only the root user has access to /root, and other users (including linux) cannot even list the files inside it.
    • The ACL permission on hulk allows linux to read and write the file, but since linux cannot even enter /root, they cannot access hulk.

    Grant linux execute (x) permission on /root

    To allow linux to access hulk, you need to give them execute (x) permission on /root. This allows the user to traverse the directory.

    Set ACL for linux on /root






    To remove a specific entry:












    usermod, groupmod, gpasswd, chage, chown & chgrp



    Add user to a Group

    Method 1: Using usermod (Recommended)

    sudo usermod -aG <groupname> <username>(Secondary Group)

    sudo usermod -g <groupname> <username>(Primary group)



    Method 2: Using gpasswd

    sudo gpasswd -a <username> <groupname>






    Remove a user from a group:

    sudo gpasswd -d username groupname








    The /etc/passwd file contains user account information. Use this command to count the total number of users




    The /etc/group file contains all the system groups. Use this command to count them.




    Create a New User:

    Use the useradd command to create a new user:

    sudo useradd -m -s /bin/bash <username>

  • -m → Creates a home directory (/home/<username>).
  • -s /bin/bash → Sets Bash as the default shell (optional).

  • Set a Password for the User:

    sudo passwd <username>




    1️⃣ Primary Group

    • The primary group is the default group assigned to a user when they create or modify files.
    • Every user has exactly one primary group.
    • The primary group is defined in the /etc/passwd file.
    id -gn <username>




    2️⃣ Secondary Group

    • secondary group (also called a supplementary group) allows users to be part of multiple groups for additional permissions.
    • A user can belong to multiple secondary groups.
    id -Gn <username>






    The /etc/group file in Linux stores information about groups on the system. Each line represents a group and follows this format:

    group_name:x:GID:member1,member2,member3

    group_name → Name of the group.

    • Example: sudousersdevelopers.

    2️⃣ x → Placeholder for the group password (rarely used).

    • Historically, a password could be stored here, but now it’s in /etc/gshadow.
    • Always appears as x.

    3️⃣ GID (Group ID) → Unique numerical identifier for the group.

    • Example: 0 (root), 10001001, etc.
    • Used by the system for access control.

    4️⃣ members → Comma-separated list of users in the group.

    • Only secondary group members are listed here.
    • Primary group members are not shown (they are assigned in /etc/passwd).

    The usermod command in Linux is used to modify user account properties. Below is a list of all the possible options you can use with usermod and their explanations:

    Basic Syntax
    sudo usermod [options] <username>


    Change the Primary Group
    sudo usermod -g <groupname> <username>


    Add the User to a Secondary Group
    sudo usermod -aG <groupname> <username>


    Change the Home Directory
    sudo usermod -d /new/home/path <username>


    Moves the user's home directory (but doesn’t move existing files).
    sudo usermod -d /new/home/path -m <username>


    Change the Username
    sudo usermod -l <new_username> <old_username>


    Change the User’s UID (User ID)
    sudo usermod -u <new_uid> <username>


    Change the User’s GID (Group ID)
    sudo usermod -g <new_gid> <username>


    Lock the account (prevents login):
    sudo usermod -L <username>


    Unlock the account (restores login access):
    sudo usermod -U <username>


    Expire a User Account Immediately:
    sudo usermod -e 0 <username>


    Set a specific expiry date (YYYY-MM-DD format):
    sudo usermod -e 2025-12-31 <username>


    Change the User’s Shell
    sudo usermod -s /bin/zsh <username>


    Remove User from All Secondary Groups
    sudo usermod -G "" <username>



    The chage command in Linux is used to manage user password aging policies. It allows administrators to set password expiration dates, force password changes, and more.


    Basic Syntax

    sudo chage [options] <username>


    Table of chage Options

    OptionDescription
    -lList password aging info for a user
    -ESet account expiration date
    -MSet maximum password age (expiry in days)
    -mSet minimum password age before changing
    -WSet password expiry warning days
    -dSet the last password change date
    -ISet inactive days before account is locked



    Explanation of Each Option

    • -m 0 → The user can change their password at any time, even immediately after setting it.
    • -M 90 → The password must be changed every 90 days (maximum validity).
    • -W 10 → The user will receive a warning 10 days before the password expires.
    • -E 2025-02-28 → The user account will expire on February 28, 2025 (after this date, the user cannot log in).
    Meaning:

  • test2 can change his password anytime.
  • If he doesn’t change it, the system will force him to change it after 90 days.
  • 10 days before expiration, he will see warnings.
  • After February 28, 2025, his account will expire, and he won’t be able to log in.

  • Verify:






    The groupmod command in Linux is used to modify group properties, such as changing the group name or Group ID (GID). Below are all the possible options for groupmod and their explanations.


    Basic Syntax

    sudo groupmod [options] <groupname>


    Change a Group Name

    sudo groupmod -n <new_groupname> <old_groupname>


    Change a Group ID (GID)

    sudo groupmod -g <new_gid> <groupname>


    Change Group Name and GID Together

    sudo groupmod -n <new_groupname> -g <new_gid> <old_groupname>


    Force Change of GID (Even if It's in Use)

    sudo groupmod -g <new_gid> -o <groupname>



    Table of groupmod Options

    OptionDescription
    -n <new_name>Rename a group
    -g <new_gid>Change Group ID (GID)
    -oAllow duplicate GIDs (use with -g)




    The gpasswd command in Linux is used to administer /etc/group file, allowing you to manage group memberships and set group passwords. Below are all possible commands and their explanations:


    Basic Syntax

    sudo gpasswd [options] <groupname>



    Add a User to a Group

    sudo gpasswd -a <username> <groupname>



    Remove a User from a Group

    sudo gpasswd -d <username> <groupname>



    Set or Change a Group Password

    sudo gpasswd <groupname>



    Allow a User to Administer a Group

    sudo gpasswd -A <username1>,<username2> <groupname>

    sudo gpasswd -A alice,bob developers(Alice and Bob become administrators of the developers group.)



    Grant Users Permission to Add/Remove Members

    sudo gpasswd -M <username1>,<username2> <groupname>(Replaces the entire group membership list with specified users.)

    sudo gpasswd -M alice,bob developers(Now, only Alice and Bob are members of the developers group.)



    Restrict Group Membership to Group Admins

    sudo gpasswd -r <groupname>(Removes the group password, restricting access to only group admins.)

    sudo gpasswd -r developers(Only admins can now add members to developers.)




    The chown command in Linux is used to change the ownership of files and directories. Here are all possible ways you can use chown:


    Basic Syntax

    chown [OPTIONS] USER[:GROUP] FILE...



    Change Owner

    chown newuser file(Changes the owner of file to newuser)


    Changes the owner of file to newuser

    chown newuser:newgroup file(Changes the owner to newuser and group to newgroup.)



    Change Only the Group (Using :)

    chown :newgroup file(Changes only the group, leaving the owner unchanged.)



    Changes only the group, leaving the owner unchanged.

    chown -R newuser:newgroup directory(Changes ownership for all files and subdirectories.)


    Change Ownership for Multiple Files

    chown newuser:newgroup file1 file2 dir1(chown newuser:newgroup file1 file2 dir1)



    Use Numeric UID and GID

    chown 1001:1002 file(Sets user ID to 1001 and group ID to 1002.)



    Suppress Error Messages

    chown -f newuser file(Fails silently if an error occurs.)



    The chgrp command in Linux is used to change the group ownership of files and directories. Here are all possible ways you can use chgrp:


    Basic Syntax

    chgrp [OPTIONS] GROUP FILE...



    Change Group Ownership

    chgrp newgroup file(Changes the group of file to newgroup.)



    Change Group Ownership Recursively

    chgrp -R newgroup directory(Changes the group of all files and directories within directory recursively.)


    Use Numeric GID

    chgrp 1002 file(Sets the group ID to 1002 for file.)



    Change Group Ownership for Multiple Files

    chgrp newgroup file1 file2 dir1



    Change Group Ownership Using a Reference File

    chgrp --reference=ref_file target_file(Sets the group ownership of target_file to match ref_file.)























































                                                                     Print the byte count





    Linux Fundamentals 


    1. Commands Syntax 
    2. File Permissions (chmod) 
    3. File Ownership (chown, chgrp)
    4. Getting Help (man, whatis etc.) 
    5. TAB completion and up arrow keys
    6. Adding text to file 
    7. Standard output to a file (tee command)
    8. Pipes ( | )
    9. File Maintenance Commands 
    10. File Display Commands 
    11. Filters / Text Processing Commands (cut, sort, grep, awk, sed, uniq, wc) 
    12. Compare Files (diff, cmp) 
    13. Compress and un-compress files/directories (tar, gzip, gunzip) 
    14. Truncate file size (truncate) 
    15. Combining and Splitting Files (cat and split) 
    16. Linux vs. Windows Commands 


    1. File Permissions (chmod)

    • Commandchmod
    • Syntaxchmod [options] [permissions] [file]
      • Explanation: Change file permissions for a file or directory.
      • Example: chmod 755 file.txt
        • Sets rwx (read, write, execute) permissions for the owner, and rx (read, execute) permissions for group and others.
      • Example: chmod +x script.sh
        • Adds execute permission for the file script.sh.
      • Permissions:
        • r = read (4)
        • w = write (2)
        • x = execute (1)
        • e.g., 755 means owner gets rwx (7), group gets rx (5), others get rx (5).

    2. File Ownership (chown, chgrp)

    • Commandchown

      • Syntaxchown [owner]:[group] [file]
      • Explanation: Change the owner and group of a file.
      • Example: chown john:admins file.txt
        • Sets the owner of file.txt to john and the group to admins.
    • Commandchgrp

      • Syntaxchgrp [group] [file]
      • Explanation: Change the group ownership of a file.
      • Example: chgrp developers file.txt
        • Changes the group ownership of file.txt to developers.

    3. Getting Help (man, whatis, info)

    • Commandman

      • Syntaxman [command]
      • Explanation: Display the manual (help) page for a command.
      • Example: man ls
        • Shows detailed documentation for the ls command.
    • Commandwhatis

      • Syntaxwhatis [command]
      • Explanation: Display a one-line description of a command.
      • Example: whatis ls
        • Shows a brief description of the ls command.
    • Commandinfo

      • Syntaxinfo [command]
      • Explanation: Access the info documentation for a command (typically more detailed than man).
      • Example: info ls
        • Shows more detailed documentation for the ls command.

    4. TAB Completion and Up Arrow Keys

    • TAB Completion:

      • Explanation: Press TAB to auto-complete file names, directories, and commands.
      • Example: Typing cd /home/ and pressing TAB will auto-complete the directory path.
    • Up Arrow:

      • Explanation: Press the up arrow key to cycle through previously entered commands in the terminal.

    5. Adding Text to a File

    • Commandecho
      • Syntaxecho "text" > [file] (overwrite)
      • Example: echo "Hello World" > file.txt
        • Overwrites the content of file.txt with "Hello World".
      • Syntaxecho "text" >> [file] (append)
      • Example: echo "Hello Again" >> file.txt
        • Appends "Hello Again" to file.txt.

    6. Standard Output to a File (tee command)

    • Commandtee
      • Syntaxcommand | tee [file]
      • Explanation: Direct standard output to a file and display it on the terminal.
      • Example: echo "Hello World" | tee file.txt
        • Writes "Hello World" to file.txt and displays it on the terminal.
      • Syntaxtee -a [file]
      • Explanation: Append output to the file.
      • Example: echo "New Line" | tee -a file.txt
        • Appends "New Line" to file.txt.

    7. Pipes ( | )

    • Syntaxcommand1 | command2
      • Explanation: Use the output of command1 as the input to command2.
      • Example: ls -l | grep "text"
        • Lists files and filters them with grep to show those containing "text".
      • Example: cat file.txt | sort
        • Sorts the contents of file.txt.

    8. File Maintenance Commands

    • Commandcp

      • Syntaxcp [source] [destination]
      • Explanation: Copy files or directories.
      • Example: cp file.txt /home/user/
    • Commandmv

      • Syntaxmv [source] [destination]
      • Explanation: Move or rename files.
      • Example: mv file.txt newfile.txt
    • Commandrm

      • Syntaxrm [file]
      • Explanation: Remove files.
      • Example: rm file.txt
    • Commandln

      • Syntaxln -s [target] [linkname]
      • Explanation: Create a symbolic link.
      • Example: ln -s /path/to/original /path/to/link

    9. File Display Commands

    • Commandcat

      • Syntaxcat [file]
      • Explanation: Display the content of a file.
      • Example: cat file.txt
    • Commandless

      • Syntaxless [file]
      • Explanation: View file contents interactively (scrollable).
      • Example: less file.txt
    • Commandmore

      • Syntaxmore [file]
      • Explanation: View the content of a file, one page at a time.
      • Example: more file.txt

    10. Filters / Text Processing Commands (cut, sort, grep, awk, sed, uniq, wc)

    • cut:

      • Syntaxcut -d [delimiter] -f [fields] [file]
      • Explanation: Extract specific fields from a file.
      • Example: cut -d "," -f 1 file.csv
    • sort:

      • Syntaxsort [file]
      • Explanation: Sort lines in a file.
      • Example: sort file.txt
    • grep:

      • Syntaxgrep [pattern] [file]
      • Explanation: Search for a pattern in a file.
      • Example: grep "error" file.txt
    • awk:

      • Syntaxawk '{print $1}' [file]
      • Explanation: Process and analyze text files.
      • Example: awk '{print $1}' file.txt (prints the first column).
    • sed:

      • Syntaxsed [options] '[command]' [file]
      • Explanation: Stream editor for text manipulation.
      • Example: sed 's/old/new/' file.txt
        • Replaces "old" with "new" in file.txt.
    • uniq:

      • Syntaxuniq [file]
      • Explanation: Remove duplicate lines in a file.
      • Example: uniq file.txt
    • wc:

      • Syntaxwc [file]
      • Explanation: Count lines, words, and characters.
      • Example: wc file.txt

    11. Compare Files (diff, cmp)

    • diff:

      • Syntaxdiff [file1] [file2]
      • Explanation: Compare two files line by line.
      • Example: diff file1.txt file2.txt
    • cmp:

      • Syntaxcmp [file1] [file2]
      • Explanation: Compare two files byte by byte.
      • Example: cmp file1.txt file2.txt

    12. Compress and Un-compress Files/Directories (tar, gzip, gunzip)

    • tar:

      • Syntaxtar -cvf [archive.tar] [file]

      • Explanation: Create a tarball archive.

      • Example: tar -cvf archive.tar /home/user/

      • Syntaxtar -xvf [archive.tar]

      • Explanation: Extract files from a tarball.

      • Example: tar -xvf archive.tar

    • gzip:

      • Syntaxgzip [file]
      • Explanation: Compress a file with gzip.
      • Example: gzip file.txt
    • gunzip:

      • Syntaxgunzip [file.gz]
      • Explanation: Decompress a gzip file.
      • Example: gunzip file.txt.gz

    13. Truncate File Size (truncate)

    • truncate:
      • Syntaxtruncate -s [size] [file]
      • Explanation: Resize a file (extend or truncate).
      • Example: truncate -s 0 file.txt
        • Sets the size of file.txt to zero.
      • Example: truncate -s +100k file.txt
        • Increases the size of file.txt by 100KB.

    14. Combining and Splitting Files (cat and split)

    • cat:

      • Syntaxcat [file1] [file2] > [combinedfile]
      • Explanation: Concatenate files and combine them into one.
      • Example: cat file1.txt file2.txt > combined.txt
    • split:

      • Syntaxsplit -l [lines] [file] [prefix]
      • Explanation: Split a file into smaller files.
      • Example: split -l 1000 largefile.txt smallfile_
        • Splits largefile.txt into chunks of 1000 lines.

    15. Linux vs. Windows Commands

    • ls (Linux) → dir (Windows)
    • cp (Linux) → copy (Windows)
    • mv (Linux) → move (Windows)
    • rm (Linux) → del (Windows)
    • cat (Linux) → type (Windows)
    • clear (Linux) → cls (Windows)


    Linux System Administration


    1.  Linux File Editors (vi text editor) 
    2. “sed” command 
    3. User account management 
    4. Switch users and Sudo access 
    5. Monitor users 
    6. Talking to users (users, wall, write) 
    7. Linux Directory Service - Account Authentication 
    8. System utility commands (date, uptime, hostname, which, cal, bc etc.) 
    9. Processes and schedules (systemctl, ps, top, kill, crontab and at) 
    10. System Monitoring Commands (top, df, dmesg, iostat 1, netstat, free etc.) 
    11. OS Maintenance Commands (shutdown, reboot, halt, init etc.) 
    12. System logs monitor (/var/log) 
    13. Changing System Hostname (hostnamectl) 
    14. Finding System Information (uname, cat /etc/redhat-release, cat /etc/*rel*, dmidecode) 
    15. System Architecture (arch) 
    16. Terminal control keys 
    17. Terminal Commands (clear, exit, script) 
    18. Recover root Password (single user mode) 
    19. SOS Report 
    20. Environment variables 

    1. Linux File Editors (vi text editor)

    • Commandvi
      • Syntaxvi [file]
      • Explanation: The vi editor is used to edit text files in Linux. It opens a file in either "normal" mode (for navigation and editing) or "insert" mode (for entering text).
      • Example: vi file.txt — Opens file.txt in the vi editor.
      • Basic Usage:
        • Press i to enter insert mode (to start typing).
        • Press Esc to return to normal mode.
        • Type :wq to save and quit, or :q! to quit without saving.

    2. sed Command

    • Commandsed
      • Syntaxsed [options] 'command' [file]
      • Explanationsed is a stream editor for filtering and transforming text in a pipeline.
      • Example: sed 's/old/new/' file.txt
        • Replaces the first occurrence of "old" with "new" in each line of file.txt.
      • Example: sed -i 's/old/new/g' file.txt
        • Replaces all occurrences of "old" with "new" (in-place modification).

    3. User Account Management

    • Commanduseradd

      • Syntaxuseradd [options] [username]
      • Explanation: Adds a new user account to the system.
      • Example: useradd john
        • Creates a user john on the system.
      • Example: useradd -m -s /bin/bash john
        • Creates the user john with a home directory and default shell /bin/bash.
    • Commandusermod

      • Syntaxusermod [options] [username]
      • Explanation: Modify user account properties.
      • Example: usermod -aG groupname john
        • Adds john to the groupname group.
    • Commanduserdel

      • Syntaxuserdel [options] [username]
      • Explanation: Delete a user account.
      • Example: userdel john
        • Deletes the user john.

    4. Switch Users and Sudo Access

    • Commandsu
      • Syntaxsu [username]
      • Explanation: Switch to another user account.
      • Example: su - john
        • Switches to the john user account.
    • Commandsudo
      • Syntaxsudo [command]
      • Explanation: Execute a command with superuser privileges.
      • Example: sudo apt-get update
        • Runs the apt-get update command with root privileges.

    5. Monitor Users

    • Commandwho

      • Syntaxwho
      • Explanation: Displays a list of logged-in users.
      • Example: who
        • Shows all logged-in users with their terminal and login time.
    • Commandw

      • Syntaxw
      • Explanation: Shows who is logged in and what they are doing.
      • Example: w
        • Displays a detailed list of users with their current processes and login times.
    • Commandlast

      • Syntaxlast
      • Explanation: Displays the last logins of users.
      • Example: last
        • Shows a list of recent user logins, including time, IP address, and session length.

    6. Talking to Users (users, wall, write)

    • Commandusers

      • Syntaxusers
      • Explanation: Lists currently logged-in users.
      • Example: users
        • Displays usernames of users who are currently logged in.
    • Commandwall

      • Syntaxwall [message]
      • Explanation: Sends a message to all logged-in users.
      • Example: wall "System will be going down for maintenance at 5 PM"
        • Sends a broadcast message to all logged-in users.
    • Commandwrite

      • Syntaxwrite [username]
      • Explanation: Send a message to a specific logged-in user.
      • Example: write john
        • Starts a chat session with the user john.

    7. Linux Directory Service - Account Authentication

    • Explanation: Authentication can be configured with services like LDAP (Lightweight Directory Access Protocol), Active Directory, or NIS (Network Information Service) to manage user accounts across the network.
      • Example: nsswitch.conf and /etc/ldap.conf files are used to configure authentication.

    8. System Utility Commands (date, uptime, hostname, which, cal, bc etc.)

    • Commanddate

      • Syntaxdate
      • Explanation: Displays or sets the system date and time.
      • Example: date
        • Displays the current date and time.
    • Commanduptime

      • Syntaxuptime
      • Explanation: Displays the system's uptime (how long the system has been running).
      • Example: uptime
        • Shows the system's uptime, number of users, and average load.
    • Commandhostname

      • Syntaxhostname
      • Explanation: Displays or sets the system’s hostname.
      • Example: hostname
        • Displays the current hostname.
    • Commandwhich

      • Syntaxwhich [command]
      • Explanation: Displays the path of a command.
      • Example: which ls
        • Shows the path of the ls command.
    • Commandcal

      • Syntaxcal [month] [year]
      • Explanation: Displays a calendar.
      • Example: cal 12 2023
        • Displays the calendar for December 2023.
    • Commandbc

      • Syntaxbc
      • Explanation: An arbitrary-precision calculator language.
      • Example: echo "3 + 5" | bc
        • Calculates and outputs the result (8).

    9. Processes and Schedules (systemctl, ps, top, kill, crontab, at)

    • Commandsystemctl

      • Syntaxsystemctl [options] [service]
      • Explanation: Control system services with systemd.
      • Example: systemctl status apache2
        • Displays the status of the Apache2 service.
    • Commandps

      • Syntaxps [options]
      • Explanation: Display information about running processes.
      • Example: ps aux
        • Lists all running processes.
    • Commandtop

      • Syntaxtop
      • Explanation: Display real-time system resource usage and process information.
      • Example: top
        • Shows CPU and memory usage, and a list of running processes.
    • Commandkill

      • Syntaxkill [PID]
      • Explanation: Terminate a process by its process ID (PID).
      • Example: kill 1234
        • Kills the process with PID 1234.
    • Commandcrontab

      • Syntaxcrontab -e
      • Explanation: Edit the cron jobs for scheduling tasks.
      • Example: crontab -e
        • Opens the cron file for the current user to add scheduled tasks.
    • Commandat

      • Syntaxat [time]
      • Explanation: Schedule a task to run at a specific time.
      • Example: at 14:00
        • Schedules a task to run at 2:00 PM.

    10. System Monitoring Commands (top, df, dmesg, iostat, netstat, free)

    • Commanddf

      • Syntaxdf -h
      • Explanation: Displays disk space usage in a human-readable format.
      • Example: df -h
        • Shows available disk space for all mounted file systems.
    • Commanddmesg

      • Syntaxdmesg
      • Explanation: Displays system boot logs and kernel-related messages.
      • Example: dmesg | grep error
        • Filters the system messages for errors.
    • Commandiostat

      • Syntaxiostat 1
      • Explanation: Display CPU and I/O statistics.
      • Example: iostat -x 1
        • Shows extended stats every second.
    • Commandnetstat

      • Syntaxnetstat -tuln
      • Explanation: Displays network connections and listening ports.
      • Example: netstat -tuln
        • Lists all active TCP and UDP ports.
    • Commandfree

      • Syntaxfree -h
      • Explanation: Displays memory usage.
      • Example: free -h
        • Shows memory usage in a human-readable format (e.g., GB or MB).

    11. OS Maintenance Commands (shutdown, reboot, halt, init)

    • Commandshutdown

      • Syntaxshutdown -h now
      • Explanation: Shut down the system immediately.
      • Example: shutdown -r now
        • Reboots the system immediately.
    • Commandreboot

      • Syntaxreboot
      • Explanation: Reboots the system.
      • Example: reboot
        • Restarts the system.
    • Commandhalt

      • Syntaxhalt
      • Explanation: Immediately stops all system processes.
      • Example: halt
        • Halts the system.
    • Commandinit

      • Syntaxinit [level]
      • Explanation: Change the runlevel of the system.
      • Example: init 0
        • Shuts down the system.

    12. System Logs Monitor (/var/log)

    • Explanation: Log files can be found in /var/log directory. Common log files include:
      • /var/log/syslog — General system logs.
      • /var/log/auth.log — Authentication logs.
      • tail -f /var/log/syslog
        • Monitor real-time log updates.

    13. Changing System Hostname (hostnamectl)

    • Commandhostnamectl
      • Syntaxhostnamectl set-hostname [new-hostname]
      • Explanation: Change the system's hostname.
      • Example: hostnamectl set-hostname newhostname
        • Sets the system hostname to newhostname.

    14. Finding System Information (uname, cat /etc/rel, dmidecode)

    • Commanduname -a
      • Syntaxuname -a
      • Explanation: Displays system information such as kernel version, machine architecture, etc.
    • Commandcat /etc/*rel*
      • Syntaxcat /etc/*rel*
      • Explanation: Displays information about the Linux distribution.
    • Commanddmidecode
      • Syntaxdmidecode
      • Explanation: Provides detailed information about the system's hardware components.
      • Example: dmidecode -t system
        • Displays information about the system's hardware.

    15. System Architecture (arch)

    • Commandarch
      • Syntaxarch
      • Explanation: Displays the system's architecture (e.g., x86_64).
      • Example: arch
        • Displays system architecture type.

    16. Terminal Control Keys

    • Explanation:
      • Ctrl + C: Terminate the running process.
      • Ctrl + Z: Pause the running process and send it to the background.
      • Ctrl + D: Exit the terminal.

    17. Terminal Commands (clear, exit, script)

    • Commandclear

      • Syntaxclear
      • Explanation: Clears the terminal screen.
      • Example: clear
        • Clears the terminal.
    • Commandexit

      • Syntaxexit
      • Explanation: Close the terminal session.
      • Example: exit
        • Exits the terminal session.
    • Commandscript

      • Syntaxscript [filename]
      • Explanation: Starts a script that records all terminal output.
      • Example: script session.log
        • Starts recording terminal output to session.log.

    18. Recover Root Password (single user mode)

    • Explanation: To recover the root password, boot the system in single-user mode (rescue mode) and reset the password:
      1. Reboot the system.
      2. Press e to edit the GRUB boot menu.
      3. Add single or 1 at the end of the linux line.
      4. Press Ctrl + X to boot in single-user mode.
      5. Reset the password with passwd root.
      6. Reboot the system.

    19. SOS Report

    • Commandsosreport
      • Syntaxsosreport
      • Explanation: Generates a detailed system diagnostic report for troubleshooting.
      • Example: sosreport
        • Collects system information and saves it to a tarball file for debugging.

    20. Environment Variables

    • Commandprintenv

      • Syntaxprintenv
      • Explanation: Displays all environment variables.
      • Example: printenv PATH
        • Shows the PATH environment variable.
    • Commandexport

      • Syntaxexport [variable]=[value]
      • Explanation: Set environment variables.
      • Example: export PATH=$PATH:/new/path
        • Adds /new/path to the PATH variable.


    Networking, Servers and System Updates



    1. Enabling internet in Linux VM 
    2. Network Components 
    3. Network files and commands (ping, ifconfig, netstat, tcpdump, networking config files) 
    4. NIC Information (ethtool) 
    5. NIC or port bonding 
    6. Download files with URLs (wget) 
    7. curl and ping commands 
    8. File transfer commands (ftp, scp etc.) 
    9. System updates and repositories (rpm and yum) 
    10. System Upgrade/Patch Management 
    11. Create Local Repository from CD/DVD 
    12. Advance Package Management 
    13. Rollback Patches and Updates 
    14. SSH and Telnet 
    15. DNS 
    16. Hostname and IP Lookup (nslookup and dig) 
    17. NTP 
    18. chronyd 
    19. Sendmail 
    20. Apache Web Server (http) 
    21. Central Logger (rsyslogd) 
    22. Securing Linux Machine (OS Hardening) 
    23. OpenLDAP Installation 
    24. Tracing Network Traffic (traceroute)

    1. Enabling Internet in Linux VM

    • Explanation: To enable internet on a Linux VM, you typically need to configure the network interface and ensure it has access to a gateway and DNS. This can be done through network manager tools or editing the network configuration files manually.
      • Example: Using nmcli (Network Manager Command Line Interface) to enable the connection.
        • nmcli connection up [connection_name]
        • Alternatively, you can configure /etc/sysconfig/network-scripts/ifcfg-eth0 for static IP or DHCP.

    2. Network Components

    • Explanation: The network components include network interfaces (NICs), IP addressing, DNS servers, gateways, and routing rules. You need to configure these components to enable communication between the system and the network.

    3. Network Files and Commands (ping, ifconfig, netstat, tcpdump, networking config files)

    • ping:

      • Syntaxping [hostname or IP address]
      • Explanation: Sends ICMP echo requests to a host to check if it’s reachable.
      • Example: ping google.com — Pings google.com to check connectivity.
    • ifconfig (deprecated in favor of ip command in newer systems):

      • Syntaxifconfig [interface]
      • Explanation: Display or configure network interfaces.
      • Example: ifconfig eth0 — Displays the configuration of the eth0 interface.
    • netstat:

      • Syntaxnetstat [options]
      • Explanation: Displays network connections, routing tables, and interface statistics.
      • Example: netstat -tuln — Displays listening ports and active connections.
    • tcpdump:

      • Syntaxtcpdump [options]
      • Explanation: Captures network packets for analysis.
      • Example: tcpdump -i eth0 — Captures packets on the eth0 interface.
    • Networking Configuration Files:

      • /etc/sysconfig/network-scripts/ifcfg-eth0: Network interface configuration.
      • /etc/hosts: Static hostname-to-IP address mapping.
      • /etc/resolv.conf: DNS resolver configuration.

    4. NIC Information (ethtool)

    • Commandethtool
      • Syntaxethtool [interface]
      • Explanation: Displays or modifies NIC (Network Interface Card) settings.
      • Example: ethtool eth0 — Displays information about the eth0 interface, such as speed and duplex mode.

    5. NIC or Port Bonding

    • Explanation: NIC bonding is the process of combining multiple network interfaces to form a single logical interface for redundancy or increased bandwidth. This can be done by configuring /etc/sysconfig/network-scripts/ifcfg-bond0.
      • Example: bonding mode 1 — Configures active-backup mode for NIC bonding.

    6. Download Files with URLs (wget)

    • Commandwget
      • Syntaxwget [options] [URL]
      • Explanation: Non-interactive utility to download files from the web.
      • Example: wget https://example.com/file.tar.gz — Downloads a file from the specified URL.

    7. curl and ping Commands

    • curl:

      • Syntaxcurl [options] [URL]
      • Explanation: Transfers data from or to a server using various protocols (HTTP, FTP, etc.).
      • Example: curl -O https://example.com/file.zip — Downloads a file from the URL.
    • ping:

      • Syntaxping [hostname or IP address]
      • Explanation: Sends ICMP echo requests to a host to check if it’s reachable.
      • Example: ping google.com — Pings google.com to check network connectivity.

    8. File Transfer Commands (ftp, scp, etc.)

    • ftp:

      • Syntaxftp [hostname]
      • Explanation: Transfers files over the FTP protocol.
      • Example: ftp ftp.example.com — Opens an FTP session with ftp.example.com.
    • scp:

      • Syntaxscp [options] [source] [destination]
      • Explanation: Securely copies files between local and remote systems over SSH.
      • Example: scp file.txt user@remote:/path/to/destination — Copies file.txt to a remote server.

    9. System Updates and Repositories (rpm and yum)

    • rpm (Red Hat Package Manager):

      • Syntaxrpm [options] [package]
      • Explanation: Installs, updates, or queries RPM packages.
      • Example: rpm -ivh package.rpm — Installs a package.
    • yum:

      • Syntaxyum [options] [command]
      • Explanation: Package manager for RPM-based distributions (like CentOS, RHEL).
      • Example: yum install httpd — Installs the Apache web server.

    10. System Upgrade/Patch Management

    • yum update:
      • Syntaxyum update
      • Explanation: Updates all installed packages to the latest version.
      • Example: yum update — Updates the system’s installed packages.

    11. Create Local Repository from CD/DVD

    • Explanation: To create a local repository, you would mount the CD/DVD and configure the repository by editing /etc/yum.repos.d/local.repo to point to the mounted media.
      • Example:
        • Mount the CD: mount /dev/cdrom /mnt
        • Create repo file: nano /etc/yum.repos.d/local.repo
        • Add:
          ini
          [localrepo] name=Local Repo baseurl=file:///mnt enabled=1 gpgcheck=0

    12. Advanced Package Management

    • yum groupinstall:
      • Syntaxyum groupinstall [group_name]
      • Explanation: Installs a group of related packages.
      • Example: yum groupinstall "Development Tools" — Installs a set of development tools.

    13. Rollback Patches and Updates

    • yum history undo:
      • Syntaxyum history undo [transaction_id]
      • Explanation: Rolls back a previous transaction.
      • Example: yum history undo 5 — Rolls back the 5th transaction.

    14. SSH and Telnet

    • SSH:

      • Syntaxssh [user@]hostname
      • Explanation: Securely connects to a remote system over SSH.
      • Example: ssh user@192.168.1.10 — Connects to a remote system via SSH.
    • Telnet:

      • Syntaxtelnet [hostname]
      • Explanation: Connects to a remote system over Telnet (not secure).
      • Example: telnet example.com 23 — Connects to example.com on port 23.

    15. DNS

    • Explanation: DNS (Domain Name System) translates domain names into IP addresses. You can configure DNS in /etc/resolv.conf.
      • Example: Add nameservers to /etc/resolv.conf:
        ini
        nameserver 8.8.8.8 nameserver 8.8.4.4

    16. Hostname and IP Lookup (nslookup and dig)

    • nslookup:

      • Syntaxnslookup [domain_name]
      • Explanation: Queries DNS records for a domain.
      • Example: nslookup example.com — Finds the IP address of example.com.
    • dig:

      • Syntaxdig [domain_name]
      • Explanation: Another tool for querying DNS.
      • Example: dig example.com — Performs a DNS lookup for example.com.

    17. NTP

    • Commandntpd or chronyd
      • Explanation: Network Time Protocol (NTP) synchronizes the system clock with a remote server.
      • Example: systemctl start ntpd — Starts the NTP service.

    18. chronyd

    • Commandchronyc
      • Syntaxchronyc [command]
      • Explanation: Command-line interface for the Chrony service to manage time synchronization.
      • Example: chronyc tracking — Displays the time synchronization status.

    19. Sendmail

    • Commandsendmail
      • Syntaxsendmail [options]
      • Explanation: Mail transfer agent (MTA) used to send emails.
      • Example: sendmail user@example.com < email.txt — Sends the contents of email.txt to the specified email address.

    20. Apache Web Server (http)

    • Commandhttpd
      • Syntaxsystemctl start httpd
      • Explanation: Starts the Apache web server.
      • Example: systemctl start httpd — Starts the Apache web server service.

    21. Central Logger (rsyslogd)

    • Commandrsyslogd
      • Syntaxsystemctl start rsyslog
      • Explanation: Starts the rsyslog service, which is responsible for logging system events.
      • Example: systemctl start rsyslog — Starts the logging service.

    22. Securing Linux Machine (OS Hardening)

    • Explanation: OS hardening involves securing the Linux machine by:
      • Disabling unused services.
      • Setting strong password policies.
      • Configuring firewalls (e.g., firewalld or iptables).
      • Implementing SELinux policies.

    23. OpenLDAP Installation

    • Commandyum install openldap-server openldap-clients
      • Explanation: Installs OpenLDAP server and client utilities for directory services.
      • Example: yum install openldap-server openldap-clients

    24. Tracing Network Traffic (traceroute)

    • Commandtraceroute
      • Syntaxtraceroute [hostname or IP address]
      • Explanation: Traces the path packets take to reach a destination.
      • Example: traceroute google.com — Shows the route taken to reach google.com




    Disk Management and Run Levels 



    1. System run levels 
    2. Linux Boot Process 
    3. Message of the Day 
    4. Customize Message of the Day 
    5. Storage 
    6. Disk partition (df, fdisk, etc.) 
    7. Add Disk and Create Standard Partition 
    8. Logical Volume Management (LVM) 
    9. LVM Configuration during Installation 
    10. Add Disk and Create LVM Partition 
    11. Extend disk using LVM 
    12. Adding swap space 
    13. RAID 
    14. File System Check (fsck and xfs_repair) 
    15. System Backup (dd Command) 
    16. Network File System (NFS) 


    1. System Run Levels

    • Explanation: Run levels define the state of the system in terms of which services are running. Common run levels are:

      • 0: Halt (shutdown)
      • 1: Single-user mode (for system repair)
      • 3: Multi-user mode without GUI
      • 5: Multi-user mode with GUI (default on most Linux systems)
      • 6: Reboot
    • Commandinit

      • Syntaxinit [runlevel]
      • Explanation: Change the system’s run level.
      • Example: init 3 — Switch to multi-user mode without GUI.
    • Commandrunlevel

      • Syntaxrunlevel
      • Explanation: Displays the current and previous run levels.
      • Example: runlevel — Shows the current runlevel.

    2. Linux Boot Process

    • Explanation: The Linux boot process includes several stages:

      • BIOS/UEFI initializes hardware.
      • Bootloader (GRUB) loads the kernel.
      • The kernel initializes the system.
      • The init process starts, which runs system services.
      • The system enters the default runlevel.
    • Files/Directives: The GRUB configuration is typically stored in /etc/default/grub.


    3. Message of the Day

    • Explanation: The Message of the Day (MOTD) is a text message that is displayed to users upon login.

    • File/etc/motd

      • Explanation: You can edit the /etc/motd file to customize the message.
      • Example: nano /etc/motd — Open and edit the MOTD file.

    4. Customize Message of the Day

    • Explanation: To customize the MOTD, you can add text to /etc/motd or /etc/issue (for pre-login message).
      • Example:
        • nano /etc/motd — Edit the MOTD to display custom messages.

    5. Storage

    • Explanation: Storage in Linux can be managed through various devices and partitions. You can use tools like fdiskpartedlsblk to manage storage.

    • Commandlsblk

      • Syntaxlsblk
      • Explanation: Lists all block devices.
      • Example: lsblk — Displays all connected storage devices.

    6. Disk Partition (df, fdisk, etc.)

    • df:

      • Syntaxdf [options]
      • Explanation: Displays disk space usage for all mounted filesystems.
      • Example: df -h — Displays disk space in human-readable format.
    • fdisk:

      • Syntaxfdisk [device]
      • Explanation: A tool to manipulate disk partitions.
      • Example: fdisk /dev/sda — Open the partitioning tool for the sda disk.

    7. Add Disk and Create Standard Partition

    • Commandfdisk

      • Syntaxfdisk /dev/sdX
      • Explanation: Partition a new disk using fdisk.
      • Example:
        1. fdisk /dev/sdb — Select the disk to partition.
        2. Type n to create a new partition.
        3. Type w to write changes.
    • Commandmkfs

      • Syntaxmkfs -t [filesystem_type] [partition]
      • Explanation: Formats a partition with the specified filesystem type.
      • Example: mkfs.ext4 /dev/sdb1 — Formats /dev/sdb1 with the ext4 filesystem.

    8. Logical Volume Management (LVM)

    • Explanation: LVM is a system for managing disk space in a more flexible way compared to traditional partitioning. It allows you to create logical volumes, which can span across multiple physical devices.

    9. LVM Configuration during Installation

    • Explanation: During installation, you can configure LVM by choosing to create a logical volume group and logical volumes. This is usually done through the installer GUI or in text-based installations like CentOS or RHEL.

    10. Add Disk and Create LVM Partition

    • Steps:
      1. Create a Physical Volume (PV): pvcreate /dev/sdb
      2. Create a Volume Group (VG): vgcreate my_vg /dev/sdb
      3. Create a Logical Volume (LV): lvcreate -L 10G -n my_lv my_vg
      4. Format the Logical Volume: mkfs.ext4 /dev/my_vg/my_lv

    11. Extend Disk using LVM

    • Steps:
      1. Add a new physical volume: pvcreate /dev/sdc
      2. Extend the volume group: vgextend my_vg /dev/sdc
      3. Extend the logical volume: lvextend -l +100%FREE /dev/my_vg/my_lv
      4. Resize the filesystem: resize2fs /dev/my_vg/my_lv

    12. Adding Swap Space

    • Commandmkswap

      • Syntaxmkswap [partition]
      • Explanation: Initializes a partition as swap space.
      • Example: mkswap /dev/sdb1 — Sets /dev/sdb1 as swap.
    • Commandswapon

      • Syntaxswapon [partition]
      • Explanation: Activates the swap space.
      • Example: swapon /dev/sdb1 — Enables the swap partition.
    • File/etc/fstab

      • Explanation: Add the swap entry to /etc/fstab for automatic mounting during boot.
      • Example:
        ini

        /dev/sdb1 swap swap defaults 0 0

    13. RAID (Redundant Array of Independent Disks)

    • Explanation: RAID is used to combine multiple disks to improve performance, redundancy, or both. It’s usually managed with mdadm in Linux.

    • Commandmdadm

      • Syntaxmdadm --create [raid_device] --level=[level] --raid-devices=[n] [devices]
      • Explanation: Creates a new RAID array.
      • Example: mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc — Creates a RAID 1 array with /dev/sdb and /dev/sdc.

    14. File System Check (fsck and xfs_repair)

    • fsck:

      • Syntaxfsck [options] [device]
      • Explanation: Checks and repairs a filesystem.
      • Example: fsck /dev/sda1 — Checks and repairs the filesystem on /dev/sda1.
    • xfs_repair:

      • Syntaxxfs_repair [device]
      • Explanation: Repairs an XFS filesystem.
      • Example: xfs_repair /dev/sda1 — Repairs the XFS filesystem on /dev/sda1.

    15. System Backup (dd Command)

    • Commanddd
      • Syntaxdd if=[source] of=[destination] [options]
      • Explanation: Creates a low-level copy of data from one device to another, often used for backups.
      • Example: dd if=/dev/sda of=/dev/sdb bs=64K conv=noerror,sync — Clones /dev/sda to /dev/sdb with block size 64K.

    16. Network File System (NFS)

    • Explanation: NFS allows a system to share directories over the network. You can mount shared directories from an NFS server on the client system.

    • Install NFS server:

      • Commandyum install nfs-utils
      • Explanation: Installs NFS utilities.
      • Example: yum install nfs-utils
    • Export a directory (on NFS server):

      • File/etc/exports
      • Example:
        ini

        /data *(rw,sync,no_root_squash)
    • Start NFS server:

      • Commandsystemctl start nfs-server
      • Explanation: Starts the NFS service.
    • Mount NFS share (on NFS client):

      • Commandmount -t nfs [server_ip]:/data /mnt
      • Explanation: Mounts the NFS share from the server to the local /mnt directory





    System Administration

    1. Check system uptime and load average:

      • Use uptime or w to see uptime and load average.
      • Use top or cat /proc/loadavg for more details.
    2. Analyze high CPU or memory usage:

      • Use tophtopps aux --sort=-%cpu, or vmstat to check CPU usage.
      • Use free -m or cat /proc/meminfo for memory usage.
      • Use iotop for disk I/O analysis.
    3. Difference between hard link and soft link:

      • Hard link: Directly points to the inode, cannot cross filesystems.
      • Soft link (symbolic link): Points to another file’s path, can cross filesystems.
      • Create: ln file1 hardlink1 (hard), ln -s file1 symlink1 (soft).
    4. Troubleshoot slow-performing Linux system:

      • Check CPU: tophtop.
      • Check Memory: free -mvmstat.
      • Check Disk I/O: iotopiostat.
      • Check Network: netstatssiftop.
      • Check Logs: journalctl/var/log/messages.
    5. Find largest files and directories:

      • du -ah / | sort -rh | head -10 (Top 10 large files)
      • find / -type f -exec du -Sh {} + | sort -rh | head -10
    6. Recover a forgotten root password:

      • Boot into single-user mode or rescue mode.
      • Use passwd root to reset the password.
    7. Purpose of sysctl.conf and modifying kernel parameters:

      • Stores kernel parameters, e.g., vm.swappinessnet.ipv4.ip_forward.
      • Modify at runtime: sysctl -w net.ipv4.ip_forward=1
      • Persistent change: Edit /etc/sysctl.conf and apply with sysctl -p.
    8. Remount a filesystem as read-only:

      sh

      mount -o remount,ro /mnt
    9. Difference between crontab and systemd timers:

      • crontab is simpler but lacks advanced logging.
      • systemd timers are more powerful with dependencies and logs.

    User & Permission Management

    1. Lock/unlock a user account:



      passwd -l username # Lock passwd -u username # Unlock
    2. Difference between chmodchown, and chgrp:

      • chmod: Changes file permissions (chmod 755 file).
      • chown: Changes file owner (chown user file).
      • chgrp: Changes group ownership (chgrp group file).
    3. umask usage:

      • Controls default file permissions.
      • Example: umask 022 results in 755 for new directories.
    4. Give sudo access to a user without editing /etc/sudoers:



      echo "username ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/username
    5. Difference between /etc/passwd and /etc/shadow:

      • /etc/passwd: Stores user information.
      • /etc/shadow: Stores encrypted passwords.

    Networking

    1. Check open ports:



      netstat -tulnp ss -tulnp
    2. Difference between iptables and firewalld:

      • iptables: Legacy firewall, rule-based.
      • firewalld: Dynamic, supports zones.
    3. Troubleshoot DNS resolution issues:



      nslookup example.com dig example.com host example.com
    4. Add a persistent static route:



      ip route add 192.168.1.0/24 via 192.168.0.1
    5. Difference between pingtraceroute, and mtr:

      • ping: Checks reachability.
      • traceroute: Shows route taken.
      • mtr: Combines both.
    6. Check which process is using a port:



      lsof -i :80 netstat -tulnp | grep 80

    Process & Performance Monitoring

    1. Difference between nice and renice:

      • nice: Sets priority when starting a process.
      • renice: Changes priority of a running process.
    2. Send a process to the background and bring it back:



      command & fg %1
    3. What is nohup?

      • Runs processes immune to hang-ups:


        nohup command &
    4. List and kill all processes of a user:



      ps -u username pkill -u username
    5. Monitor real-time performance:



      top, htop, iostat, vmstat, sar

    File System & Storage

    1. Check and repair filesystem errors:



      fsck -y /dev/sda1
    2. LVM extension without unmounting:


      lvextend -L +10G /dev/vgname/lvname resize2fs /dev/vgname/lvname
    3. Create and mount a new filesystem:



      mkfs.ext4 /dev/sdb1 mount /dev/sdb1 /mnt
    4. Difference between ext4xfs, and btrfs:

      • ext4: Stable, widely used.
      • xfs: Better for large files.
      • btrfs: Snapshot and RAID support.
    5. List mounted filesystems:



      df -h mount | column -t

    Logs & Debugging

    1. System logs location:

      • /var/log/syslog/var/log/messages/var/log/dmesg.
    2. Track failed login attempts:



      cat /var/log/auth.log | grep "Failed password"
    3. Filter logs using journalctl:



      journalctl -u nginx --since "1 hour ago"
    4. Configure log rotation:

      • /etc/logrotate.conf or /etc/logrotate.d/.

    Package Management

    1. List installed packages:



      rpm -qa | grep package_name # RHEL dpkg -l | grep package_name # Debian
    2. Difference between yum and dnf:

      • dnf is faster and handles dependencies better.
    3. Upgrade Linux kernel safely:



      yum update kernel # RHEL apt update && apt upgrade # Debian
    4. Check files owned by a package:



      rpm -ql package_name dpkg -L package_name

    Security

    1. Check system vulnerabilities:



      lynis audit system
    2. What is SELinux?

      • Mandatory access control system.
      • Troubleshoot with setenforce 0.
    3. Difference between ssh-keygen and ssh-copy-id:

      • ssh-keygen: Creates SSH keys.
      • ssh-copy-id: Copies keys to a server.
    4. Restrict SSH access:

      • Edit /etc/ssh/sshd_config, modify AllowUsers.


    --------------------------------------------------------------------------------------------------------------------------
    --------------------------------------------------------------------------------------------------------------------------
    --------------------------------------------------------------------------------------------------------------------------















































































    Comments