RHEL
Configure Static IP
Configure YUM
Set Hostname
#, it would indicate the root user.$ 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
/(Root Directory)- The top-most directory in Linux, containing all other directories.
- Everything starts from here.
/bin(Essential User Binaries)- Contains essential binary executables (commands) like
ls,cp,mv,cat,echo,grep, etc.
- Contains essential binary executables (commands) like
/boot(Boot Files)- Stores boot-related files, including the Linux kernel (
vmlinuz), GRUB bootloader files, and initramfs.
- Stores boot-related files, including the Linux kernel (
/dev(Device Files)- Contains files representing system devices (e.g.,
/dev/sdafor disks,/dev/ttyfor terminals,/dev/null, etc.).
- Contains files representing system devices (e.g.,
/etc(Configuration Files)- Stores system-wide configuration files (e.g.,
/etc/passwd,/etc/hostname,/etc/network/interfaces).
- Stores system-wide configuration files (e.g.,
/home(User Home Directories)- Stores user-specific files and settings (e.g.,
/home/user1,/home/user2).
- Stores user-specific files and settings (e.g.,
/lib&/lib64(Shared Libraries)- Contains essential system libraries required for programs in
/binand/sbin.
- Contains essential system libraries required for programs in
/media(Mount Points for Removable Media)- Used for automatically mounting external devices (e.g., USB drives, CDs).
/mnt(Temporary Mount Points)- Used for manually mounting file systems like network shares or external drives.
/opt(Optional Software Packages)
- Contains third-party software and add-on applications.
/proc(Process Information)
- A virtual filesystem containing system and process-related information (e.g.,
/proc/cpuinfo,/proc/meminfo).
/root(Root User’s Home Directory)
- The home directory for the superuser (root), separate from
/home.
/run(Runtime Variable Data)
- Stores system information that changes during runtime (e.g., process IDs, sockets).
/sbin(System Binaries)
- Contains system administration commands like
fdisk,iptables,shutdown.
/srv(Service Data)
- Stores files related to services like HTTP (
/srv/www) or FTP.
/sys(System Information)
- Provides a view of the system's hardware and kernel settings.
/tmp(Temporary Files)
- Used for temporary file storage, cleared upon reboot.
/usr(User Binaries and Programs)
- Contains user applications, libraries, documentation (
/usr/bin,/usr/lib,/usr/share).
/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 -lshows them withdat 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:
Hard Link:
Each field in /etc/passwd is separated by a colon (:) and has a specific meaning:
- Username:
linux→ The login name of the user. - Password Placeholder:
x→ This means the password is stored in/etc/shadow(not visible here). - User ID (UID):
1002→ The unique ID assigned to this user. - Group ID (GID):
1002→ The primary group ID assigned to the user. - Comment/Description Field: (empty) → Typically used for full names or descriptions.
- Home Directory:
/home/linux→ The user's home directory. - Login Shell:
/bin/bash→ The default shell for this user (Bash shell).
Issue Explanation:
- The file
hulkis located in/root, which is the home directory of therootuser. - By default, only the
rootuser has access to/root, and other users (includinglinux) cannot even list the files inside it. - The ACL permission on
hulkallowslinuxto read and write the file, but sincelinuxcannot even enter/root, they cannot accesshulk.
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
usermod (Recommended)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:
useradd command to create a new user:-m → Creates a home directory (/home/<username>).-s /bin/bash → Sets Bash as the default shell (optional).Set a Password for the User:
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/passwdfile.
2️⃣ Secondary Group
- A 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.
The /etc/group file in Linux stores information about groups on the system. Each line represents a group and follows this format:
group_name → Name of the group.
- Example:
sudo,users,developers.
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),1000,1001, 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>
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.
Table of chage Options
| Option | Description |
|---|---|
-l | List password aging info for a user |
-E | Set account expiration date |
-M | Set maximum password age (expiry in days) |
-m | Set minimum password age before changing |
-W | Set password expiry warning days |
-d | Set the last password change date |
-I | Set 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).
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.
Table of groupmod Options
| Option | Description |
|---|---|
-n <new_name> | Rename a group |
-g <new_gid> | Change Group ID (GID) |
-o | Allow 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:
developers group.)developers group.)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:
file to newuser)file to newuser
chown newuser:newgroup file(Changes the owner to newuser and group to newgroup.):)1001 and group ID to 1002.)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:
file to newgroup.)directory recursively.)1002 for file.)target_file to match ref_file.)Linux Fundamentals
- Commands Syntax
- File Permissions (chmod)
- File Ownership (chown, chgrp)
- Getting Help (man, whatis etc.)
- TAB completion and up arrow keys
- Adding text to file
- Standard output to a file (tee command)
- Pipes ( | )
- File Maintenance Commands
- File Display Commands
- Filters / Text Processing Commands (cut, sort, grep, awk, sed, uniq, wc)
- Compare Files (diff, cmp)
- Compress and un-compress files/directories (tar, gzip, gunzip)
- Truncate file size (truncate)
- Combining and Splitting Files (cat and split)
- Linux vs. Windows Commands
1. File Permissions (chmod)
- Command:
chmod - Syntax:
chmod [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, andrx(read, execute) permissions for group and others.
- Sets
- Example:
chmod +x script.sh- Adds execute permission for the file
script.sh.
- Adds execute permission for the file
- Permissions:
r= read (4)w= write (2)x= execute (1)- e.g.,
755means owner getsrwx(7), group getsrx(5), others getrx(5).
2. File Ownership (chown, chgrp)
Command:
chown- Syntax:
chown [owner]:[group] [file] - Explanation: Change the owner and group of a file.
- Example:
chown john:admins file.txt- Sets the owner of
file.txttojohnand the group toadmins.
- Sets the owner of
- Syntax:
Command:
chgrp- Syntax:
chgrp [group] [file] - Explanation: Change the group ownership of a file.
- Example:
chgrp developers file.txt- Changes the group ownership of
file.txttodevelopers.
- Changes the group ownership of
- Syntax:
3. Getting Help (man, whatis, info)
Command:
man- Syntax:
man [command] - Explanation: Display the manual (help) page for a command.
- Example:
man ls- Shows detailed documentation for the
lscommand.
- Shows detailed documentation for the
- Syntax:
Command:
whatis- Syntax:
whatis [command] - Explanation: Display a one-line description of a command.
- Example:
whatis ls- Shows a brief description of the
lscommand.
- Shows a brief description of the
- Syntax:
Command:
info- Syntax:
info [command] - Explanation: Access the info documentation for a command (typically more detailed than
man). - Example:
info ls- Shows more detailed documentation for the
lscommand.
- Shows more detailed documentation for the
- Syntax:
4. TAB Completion and Up Arrow Keys
TAB Completion:
- Explanation: Press
TABto auto-complete file names, directories, and commands. - Example: Typing
cd /home/and pressingTABwill auto-complete the directory path.
- Explanation: Press
Up Arrow:
- Explanation: Press the up arrow key to cycle through previously entered commands in the terminal.
5. Adding Text to a File
- Command:
echo- Syntax:
echo "text" > [file](overwrite) - Example:
echo "Hello World" > file.txt- Overwrites the content of
file.txtwith "Hello World".
- Overwrites the content of
- Syntax:
echo "text" >> [file](append) - Example:
echo "Hello Again" >> file.txt- Appends "Hello Again" to
file.txt.
- Appends "Hello Again" to
- Syntax:
6. Standard Output to a File (tee command)
- Command:
tee- Syntax:
command | 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.txtand displays it on the terminal.
- Writes "Hello World" to
- Syntax:
tee -a [file] - Explanation: Append output to the file.
- Example:
echo "New Line" | tee -a file.txt- Appends "New Line" to
file.txt.
- Appends "New Line" to
- Syntax:
7. Pipes ( | )
- Syntax:
command1 | command2- Explanation: Use the output of
command1as the input tocommand2. - Example:
ls -l | grep "text"- Lists files and filters them with
grepto show those containing "text".
- Lists files and filters them with
- Example:
cat file.txt | sort- Sorts the contents of
file.txt.
- Sorts the contents of
- Explanation: Use the output of
8. File Maintenance Commands
Command:
cp- Syntax:
cp [source] [destination] - Explanation: Copy files or directories.
- Example:
cp file.txt /home/user/
- Syntax:
Command:
mv- Syntax:
mv [source] [destination] - Explanation: Move or rename files.
- Example:
mv file.txt newfile.txt
- Syntax:
Command:
rm- Syntax:
rm [file] - Explanation: Remove files.
- Example:
rm file.txt
- Syntax:
Command:
ln- Syntax:
ln -s [target] [linkname] - Explanation: Create a symbolic link.
- Example:
ln -s /path/to/original /path/to/link
- Syntax:
9. File Display Commands
Command:
cat- Syntax:
cat [file] - Explanation: Display the content of a file.
- Example:
cat file.txt
- Syntax:
Command:
less- Syntax:
less [file] - Explanation: View file contents interactively (scrollable).
- Example:
less file.txt
- Syntax:
Command:
more- Syntax:
more [file] - Explanation: View the content of a file, one page at a time.
- Example:
more file.txt
- Syntax:
10. Filters / Text Processing Commands (cut, sort, grep, awk, sed, uniq, wc)
cut:
- Syntax:
cut -d [delimiter] -f [fields] [file] - Explanation: Extract specific fields from a file.
- Example:
cut -d "," -f 1 file.csv
- Syntax:
sort:
- Syntax:
sort [file] - Explanation: Sort lines in a file.
- Example:
sort file.txt
- Syntax:
grep:
- Syntax:
grep [pattern] [file] - Explanation: Search for a pattern in a file.
- Example:
grep "error" file.txt
- Syntax:
awk:
- Syntax:
awk '{print $1}' [file] - Explanation: Process and analyze text files.
- Example:
awk '{print $1}' file.txt(prints the first column).
- Syntax:
sed:
- Syntax:
sed [options] '[command]' [file] - Explanation: Stream editor for text manipulation.
- Example:
sed 's/old/new/' file.txt- Replaces "old" with "new" in
file.txt.
- Replaces "old" with "new" in
- Syntax:
uniq:
- Syntax:
uniq [file] - Explanation: Remove duplicate lines in a file.
- Example:
uniq file.txt
- Syntax:
wc:
- Syntax:
wc [file] - Explanation: Count lines, words, and characters.
- Example:
wc file.txt
- Syntax:
11. Compare Files (diff, cmp)
diff:
- Syntax:
diff [file1] [file2] - Explanation: Compare two files line by line.
- Example:
diff file1.txt file2.txt
- Syntax:
cmp:
- Syntax:
cmp [file1] [file2] - Explanation: Compare two files byte by byte.
- Example:
cmp file1.txt file2.txt
- Syntax:
12. Compress and Un-compress Files/Directories (tar, gzip, gunzip)
tar:
Syntax:
tar -cvf [archive.tar] [file]Explanation: Create a tarball archive.
Example:
tar -cvf archive.tar /home/user/Syntax:
tar -xvf [archive.tar]Explanation: Extract files from a tarball.
Example:
tar -xvf archive.tar
gzip:
- Syntax:
gzip [file] - Explanation: Compress a file with gzip.
- Example:
gzip file.txt
- Syntax:
gunzip:
- Syntax:
gunzip [file.gz] - Explanation: Decompress a gzip file.
- Example:
gunzip file.txt.gz
- Syntax:
13. Truncate File Size (truncate)
- truncate:
- Syntax:
truncate -s [size] [file] - Explanation: Resize a file (extend or truncate).
- Example:
truncate -s 0 file.txt- Sets the size of
file.txtto zero.
- Sets the size of
- Example:
truncate -s +100k file.txt- Increases the size of
file.txtby 100KB.
- Increases the size of
- Syntax:
14. Combining and Splitting Files (cat and split)
cat:
- Syntax:
cat [file1] [file2] > [combinedfile] - Explanation: Concatenate files and combine them into one.
- Example:
cat file1.txt file2.txt > combined.txt
- Syntax:
split:
- Syntax:
split -l [lines] [file] [prefix] - Explanation: Split a file into smaller files.
- Example:
split -l 1000 largefile.txt smallfile_- Splits
largefile.txtinto chunks of 1000 lines.
- Splits
- Syntax:
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
- Linux File Editors (vi text editor)
- “sed” command
- User account management
- Switch users and Sudo access
- Monitor users
- Talking to users (users, wall, write)
- Linux Directory Service - Account Authentication
- System utility commands (date, uptime, hostname, which, cal, bc etc.)
- Processes and schedules (systemctl, ps, top, kill, crontab and at)
- System Monitoring Commands (top, df, dmesg, iostat 1, netstat, free etc.)
- OS Maintenance Commands (shutdown, reboot, halt, init etc.)
- System logs monitor (/var/log)
- Changing System Hostname (hostnamectl)
- Finding System Information (uname, cat /etc/redhat-release, cat /etc/*rel*, dmidecode)
- System Architecture (arch)
- Terminal control keys
- Terminal Commands (clear, exit, script)
- Recover root Password (single user mode)
- SOS Report
- Environment variables
1. Linux File Editors (vi text editor)
- Command:
vi- Syntax:
vi [file] - Explanation: The
vieditor 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— Opensfile.txtin thevieditor. - Basic Usage:
- Press
ito enter insert mode (to start typing). - Press
Escto return to normal mode. - Type
:wqto save and quit, or:q!to quit without saving.
- Press
- Syntax:
2. sed Command
- Command:
sed- Syntax:
sed [options] 'command' [file] - Explanation:
sedis 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.
- Replaces the first occurrence of "old" with "new" in each line of
- Example:
sed -i 's/old/new/g' file.txt- Replaces all occurrences of "old" with "new" (in-place modification).
- Syntax:
3. User Account Management
Command:
useradd- Syntax:
useradd [options] [username] - Explanation: Adds a new user account to the system.
- Example:
useradd john- Creates a user
johnon the system.
- Creates a user
- Example:
useradd -m -s /bin/bash john- Creates the user
johnwith a home directory and default shell/bin/bash.
- Creates the user
- Syntax:
Command:
usermod- Syntax:
usermod [options] [username] - Explanation: Modify user account properties.
- Example:
usermod -aG groupname john- Adds
johnto thegroupnamegroup.
- Adds
- Syntax:
Command:
userdel- Syntax:
userdel [options] [username] - Explanation: Delete a user account.
- Example:
userdel john- Deletes the user
john.
- Deletes the user
- Syntax:
4. Switch Users and Sudo Access
- Command:
su- Syntax:
su [username] - Explanation: Switch to another user account.
- Example:
su - john- Switches to the
johnuser account.
- Switches to the
- Syntax:
- Command:
sudo- Syntax:
sudo [command] - Explanation: Execute a command with superuser privileges.
- Example:
sudo apt-get update- Runs the
apt-get updatecommand with root privileges.
- Runs the
- Syntax:
5. Monitor Users
Command:
who- Syntax:
who - Explanation: Displays a list of logged-in users.
- Example:
who- Shows all logged-in users with their terminal and login time.
- Syntax:
Command:
w- Syntax:
w - 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.
- Syntax:
Command:
last- Syntax:
last - Explanation: Displays the last logins of users.
- Example:
last- Shows a list of recent user logins, including time, IP address, and session length.
- Syntax:
6. Talking to Users (users, wall, write)
Command:
users- Syntax:
users - Explanation: Lists currently logged-in users.
- Example:
users- Displays usernames of users who are currently logged in.
- Syntax:
Command:
wall- Syntax:
wall [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.
- Syntax:
Command:
write- Syntax:
write [username] - Explanation: Send a message to a specific logged-in user.
- Example:
write john- Starts a chat session with the user
john.
- Starts a chat session with the user
- Syntax:
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.confand/etc/ldap.conffiles are used to configure authentication.
- Example:
8. System Utility Commands (date, uptime, hostname, which, cal, bc etc.)
Command:
date- Syntax:
date - Explanation: Displays or sets the system date and time.
- Example:
date- Displays the current date and time.
- Syntax:
Command:
uptime- Syntax:
uptime - 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.
- Syntax:
Command:
hostname- Syntax:
hostname - Explanation: Displays or sets the system’s hostname.
- Example:
hostname- Displays the current hostname.
- Syntax:
Command:
which- Syntax:
which [command] - Explanation: Displays the path of a command.
- Example:
which ls- Shows the path of the
lscommand.
- Shows the path of the
- Syntax:
Command:
cal- Syntax:
cal [month] [year] - Explanation: Displays a calendar.
- Example:
cal 12 2023- Displays the calendar for December 2023.
- Syntax:
Command:
bc- Syntax:
bc - Explanation: An arbitrary-precision calculator language.
- Example:
echo "3 + 5" | bc- Calculates and outputs the result (
8).
- Calculates and outputs the result (
- Syntax:
9. Processes and Schedules (systemctl, ps, top, kill, crontab, at)
Command:
systemctl- Syntax:
systemctl [options] [service] - Explanation: Control system services with
systemd. - Example:
systemctl status apache2- Displays the status of the Apache2 service.
- Syntax:
Command:
ps- Syntax:
ps [options] - Explanation: Display information about running processes.
- Example:
ps aux- Lists all running processes.
- Syntax:
Command:
top- Syntax:
top - Explanation: Display real-time system resource usage and process information.
- Example:
top- Shows CPU and memory usage, and a list of running processes.
- Syntax:
Command:
kill- Syntax:
kill [PID] - Explanation: Terminate a process by its process ID (PID).
- Example:
kill 1234- Kills the process with PID
1234.
- Kills the process with PID
- Syntax:
Command:
crontab- Syntax:
crontab -e - Explanation: Edit the cron jobs for scheduling tasks.
- Example:
crontab -e- Opens the cron file for the current user to add scheduled tasks.
- Syntax:
Command:
at- Syntax:
at [time] - Explanation: Schedule a task to run at a specific time.
- Example:
at 14:00- Schedules a task to run at 2:00 PM.
- Syntax:
10. System Monitoring Commands (top, df, dmesg, iostat, netstat, free)
Command:
df- Syntax:
df -h - Explanation: Displays disk space usage in a human-readable format.
- Example:
df -h- Shows available disk space for all mounted file systems.
- Syntax:
Command:
dmesg- Syntax:
dmesg - Explanation: Displays system boot logs and kernel-related messages.
- Example:
dmesg | grep error- Filters the system messages for errors.
- Syntax:
Command:
iostat- Syntax:
iostat 1 - Explanation: Display CPU and I/O statistics.
- Example:
iostat -x 1- Shows extended stats every second.
- Syntax:
Command:
netstat- Syntax:
netstat -tuln - Explanation: Displays network connections and listening ports.
- Example:
netstat -tuln- Lists all active TCP and UDP ports.
- Syntax:
Command:
free- Syntax:
free -h - Explanation: Displays memory usage.
- Example:
free -h- Shows memory usage in a human-readable format (e.g., GB or MB).
- Syntax:
11. OS Maintenance Commands (shutdown, reboot, halt, init)
Command:
shutdown- Syntax:
shutdown -h now - Explanation: Shut down the system immediately.
- Example:
shutdown -r now- Reboots the system immediately.
- Syntax:
Command:
reboot- Syntax:
reboot - Explanation: Reboots the system.
- Example:
reboot- Restarts the system.
- Syntax:
Command:
halt- Syntax:
halt - Explanation: Immediately stops all system processes.
- Example:
halt- Halts the system.
- Syntax:
Command:
init- Syntax:
init [level] - Explanation: Change the runlevel of the system.
- Example:
init 0- Shuts down the system.
- Syntax:
12. System Logs Monitor (/var/log)
- Explanation: Log files can be found in
/var/logdirectory. 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)
- Command:
hostnamectl- Syntax:
hostnamectl set-hostname [new-hostname] - Explanation: Change the system's hostname.
- Example:
hostnamectl set-hostname newhostname- Sets the system hostname to
newhostname.
- Sets the system hostname to
- Syntax:
14. Finding System Information (uname, cat /etc/rel, dmidecode)
- Command:
uname -a- Syntax:
uname -a - Explanation: Displays system information such as kernel version, machine architecture, etc.
- Syntax:
- Command:
cat /etc/*rel*- Syntax:
cat /etc/*rel* - Explanation: Displays information about the Linux distribution.
- Syntax:
- Command:
dmidecode- Syntax:
dmidecode - Explanation: Provides detailed information about the system's hardware components.
- Example:
dmidecode -t system- Displays information about the system's hardware.
- Syntax:
15. System Architecture (arch)
- Command:
arch- Syntax:
arch - Explanation: Displays the system's architecture (e.g., x86_64).
- Example:
arch- Displays system architecture type.
- Syntax:
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)
Command:
clear- Syntax:
clear - Explanation: Clears the terminal screen.
- Example:
clear- Clears the terminal.
- Syntax:
Command:
exit- Syntax:
exit - Explanation: Close the terminal session.
- Example:
exit- Exits the terminal session.
- Syntax:
Command:
script- Syntax:
script [filename] - Explanation: Starts a script that records all terminal output.
- Example:
script session.log- Starts recording terminal output to
session.log.
- Starts recording terminal output to
- Syntax:
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:
- Reboot the system.
- Press
eto edit the GRUB boot menu. - Add
singleor1at the end of thelinuxline. - Press
Ctrl + Xto boot in single-user mode. - Reset the password with
passwd root. - Reboot the system.
19. SOS Report
- Command:
sosreport- Syntax:
sosreport - Explanation: Generates a detailed system diagnostic report for troubleshooting.
- Example:
sosreport- Collects system information and saves it to a tarball file for debugging.
- Syntax:
20. Environment Variables
Command:
printenv- Syntax:
printenv - Explanation: Displays all environment variables.
- Example:
printenv PATH- Shows the
PATHenvironment variable.
- Shows the
- Syntax:
Command:
export- Syntax:
export [variable]=[value] - Explanation: Set environment variables.
- Example:
export PATH=$PATH:/new/path - Adds
/new/pathto thePATHvariable.
Networking, Servers and System Updates
- Enabling internet in Linux VM
- Network Components
- Network files and commands (ping, ifconfig, netstat, tcpdump, networking config files)
- NIC Information (ethtool)
- NIC or port bonding
- Download files with URLs (wget)
- curl and ping commands
- File transfer commands (ftp, scp etc.)
- System updates and repositories (rpm and yum)
- System Upgrade/Patch Management
- Create Local Repository from CD/DVD
- Advance Package Management
- Rollback Patches and Updates
- SSH and Telnet
- DNS
- Hostname and IP Lookup (nslookup and dig)
- NTP
- chronyd
- Sendmail
- Apache Web Server (http)
- Central Logger (rsyslogd)
- Securing Linux Machine (OS Hardening)
- OpenLDAP Installation
- 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-eth0for static IP or DHCP.
- Example: Using
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:
- Syntax:
ping [hostname or IP address] - Explanation: Sends ICMP echo requests to a host to check if it’s reachable.
- Example:
ping google.com— Pingsgoogle.comto check connectivity.
- Syntax:
ifconfig (deprecated in favor of
ipcommand in newer systems):- Syntax:
ifconfig [interface] - Explanation: Display or configure network interfaces.
- Example:
ifconfig eth0— Displays the configuration of theeth0interface.
- Syntax:
netstat:
- Syntax:
netstat [options] - Explanation: Displays network connections, routing tables, and interface statistics.
- Example:
netstat -tuln— Displays listening ports and active connections.
- Syntax:
tcpdump:
- Syntax:
tcpdump [options] - Explanation: Captures network packets for analysis.
- Example:
tcpdump -i eth0— Captures packets on theeth0interface.
- Syntax:
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)
- Command:
ethtool- Syntax:
ethtool [interface] - Explanation: Displays or modifies NIC (Network Interface Card) settings.
- Example:
ethtool eth0— Displays information about theeth0interface, such as speed and duplex mode.
- Syntax:
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.
- Example:
6. Download Files with URLs (wget)
- Command:
wget- Syntax:
wget [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.
- Syntax:
7. curl and ping Commands
curl:
- Syntax:
curl [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.
- Syntax:
ping:
- Syntax:
ping [hostname or IP address] - Explanation: Sends ICMP echo requests to a host to check if it’s reachable.
- Example:
ping google.com— Pingsgoogle.comto check network connectivity.
- Syntax:
8. File Transfer Commands (ftp, scp, etc.)
ftp:
- Syntax:
ftp [hostname] - Explanation: Transfers files over the FTP protocol.
- Example:
ftp ftp.example.com— Opens an FTP session withftp.example.com.
- Syntax:
scp:
- Syntax:
scp [options] [source] [destination] - Explanation: Securely copies files between local and remote systems over SSH.
- Example:
scp file.txt user@remote:/path/to/destination— Copiesfile.txtto a remote server.
- Syntax:
9. System Updates and Repositories (rpm and yum)
rpm (Red Hat Package Manager):
- Syntax:
rpm [options] [package] - Explanation: Installs, updates, or queries RPM packages.
- Example:
rpm -ivh package.rpm— Installs a package.
- Syntax:
yum:
- Syntax:
yum [options] [command] - Explanation: Package manager for RPM-based distributions (like CentOS, RHEL).
- Example:
yum install httpd— Installs the Apache web server.
- Syntax:
10. System Upgrade/Patch Management
- yum update:
- Syntax:
yum update - Explanation: Updates all installed packages to the latest version.
- Example:
yum update— Updates the system’s installed packages.
- Syntax:
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.repoto point to the mounted media.- Example:
- Mount the CD:
mount /dev/cdrom /mnt - Create repo file:
nano /etc/yum.repos.d/local.repo - Add:
- Mount the CD:
- Example:
12. Advanced Package Management
- yum groupinstall:
- Syntax:
yum groupinstall [group_name] - Explanation: Installs a group of related packages.
- Example:
yum groupinstall "Development Tools"— Installs a set of development tools.
- Syntax:
13. Rollback Patches and Updates
- yum history undo:
- Syntax:
yum history undo [transaction_id] - Explanation: Rolls back a previous transaction.
- Example:
yum history undo 5— Rolls back the 5th transaction.
- Syntax:
14. SSH and Telnet
SSH:
- Syntax:
ssh [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.
- Syntax:
Telnet:
- Syntax:
telnet [hostname] - Explanation: Connects to a remote system over Telnet (not secure).
- Example:
telnet example.com 23— Connects toexample.comon port 23.
- Syntax:
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:
- Example: Add nameservers to
16. Hostname and IP Lookup (nslookup and dig)
nslookup:
- Syntax:
nslookup [domain_name] - Explanation: Queries DNS records for a domain.
- Example:
nslookup example.com— Finds the IP address ofexample.com.
- Syntax:
dig:
- Syntax:
dig [domain_name] - Explanation: Another tool for querying DNS.
- Example:
dig example.com— Performs a DNS lookup forexample.com.
- Syntax:
17. NTP
- Command:
ntpdorchronyd- Explanation: Network Time Protocol (NTP) synchronizes the system clock with a remote server.
- Example:
systemctl start ntpd— Starts the NTP service.
18. chronyd
- Command:
chronyc- Syntax:
chronyc [command] - Explanation: Command-line interface for the Chrony service to manage time synchronization.
- Example:
chronyc tracking— Displays the time synchronization status.
- Syntax:
19. Sendmail
- Command:
sendmail- Syntax:
sendmail [options] - Explanation: Mail transfer agent (MTA) used to send emails.
- Example:
sendmail user@example.com < email.txt— Sends the contents ofemail.txtto the specified email address.
- Syntax:
20. Apache Web Server (http)
- Command:
httpd- Syntax:
systemctl start httpd - Explanation: Starts the Apache web server.
- Example:
systemctl start httpd— Starts the Apache web server service.
- Syntax:
21. Central Logger (rsyslogd)
- Command:
rsyslogd- Syntax:
systemctl start rsyslog - Explanation: Starts the rsyslog service, which is responsible for logging system events.
- Example:
systemctl start rsyslog— Starts the logging service.
- Syntax:
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.,
firewalldoriptables). - Implementing SELinux policies.
23. OpenLDAP Installation
- Command:
yum 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)
- Command:
traceroute - Syntax:
traceroute [hostname or IP address] - Explanation: Traces the path packets take to reach a destination.
- Example:
traceroute google.com— Shows the route taken to reachgoogle.com
Disk Management and Run Levels
- System run levels
- Linux Boot Process
- Message of the Day
- Customize Message of the Day
- Storage
- Disk partition (df, fdisk, etc.)
- Add Disk and Create Standard Partition
- Logical Volume Management (LVM)
- LVM Configuration during Installation
- Add Disk and Create LVM Partition
- Extend disk using LVM
- Adding swap space
- RAID
- File System Check (fsck and xfs_repair)
- System Backup (dd Command)
- 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
Command:
init- Syntax:
init [runlevel] - Explanation: Change the system’s run level.
- Example:
init 3— Switch to multi-user mode without GUI.
- Syntax:
Command:
runlevel- Syntax:
runlevel - Explanation: Displays the current and previous run levels.
- Example:
runlevel— Shows the current runlevel.
- Syntax:
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/motdfile to customize the message. - Example:
nano /etc/motd— Open and edit the MOTD file.
- Explanation: You can edit the
4. Customize Message of the Day
- Explanation: To customize the MOTD, you can add text to
/etc/motdor/etc/issue(for pre-login message).- Example:
nano /etc/motd— Edit the MOTD to display custom messages.
- Example:
5. Storage
Explanation: Storage in Linux can be managed through various devices and partitions. You can use tools like
fdisk,parted,lsblkto manage storage.Command:
lsblk- Syntax:
lsblk - Explanation: Lists all block devices.
- Example:
lsblk— Displays all connected storage devices.
- Syntax:
6. Disk Partition (df, fdisk, etc.)
df:
- Syntax:
df [options] - Explanation: Displays disk space usage for all mounted filesystems.
- Example:
df -h— Displays disk space in human-readable format.
- Syntax:
fdisk:
- Syntax:
fdisk [device] - Explanation: A tool to manipulate disk partitions.
- Example:
fdisk /dev/sda— Open the partitioning tool for thesdadisk.
- Syntax:
7. Add Disk and Create Standard Partition
Command:
fdisk- Syntax:
fdisk /dev/sdX - Explanation: Partition a new disk using
fdisk. - Example:
fdisk /dev/sdb— Select the disk to partition.- Type
nto create a new partition. - Type
wto write changes.
- Syntax:
Command:
mkfs- Syntax:
mkfs -t [filesystem_type] [partition] - Explanation: Formats a partition with the specified filesystem type.
- Example:
mkfs.ext4 /dev/sdb1— Formats/dev/sdb1with the ext4 filesystem.
- Syntax:
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:
- Create a Physical Volume (PV):
pvcreate /dev/sdb - Create a Volume Group (VG):
vgcreate my_vg /dev/sdb - Create a Logical Volume (LV):
lvcreate -L 10G -n my_lv my_vg - Format the Logical Volume:
mkfs.ext4 /dev/my_vg/my_lv
- Create a Physical Volume (PV):
11. Extend Disk using LVM
- Steps:
- Add a new physical volume:
pvcreate /dev/sdc - Extend the volume group:
vgextend my_vg /dev/sdc - Extend the logical volume:
lvextend -l +100%FREE /dev/my_vg/my_lv - Resize the filesystem:
resize2fs /dev/my_vg/my_lv
- Add a new physical volume:
12. Adding Swap Space
Command:
mkswap- Syntax:
mkswap [partition] - Explanation: Initializes a partition as swap space.
- Example:
mkswap /dev/sdb1— Sets/dev/sdb1as swap.
- Syntax:
Command:
swapon- Syntax:
swapon [partition] - Explanation: Activates the swap space.
- Example:
swapon /dev/sdb1— Enables the swap partition.
- Syntax:
File:
/etc/fstab- Explanation: Add the swap entry to
/etc/fstabfor automatic mounting during boot. - Example:
- Explanation: Add the swap entry to
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
mdadmin Linux.Command:
mdadm- Syntax:
mdadm --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/sdband/dev/sdc.
- Syntax:
14. File System Check (fsck and xfs_repair)
fsck:
- Syntax:
fsck [options] [device] - Explanation: Checks and repairs a filesystem.
- Example:
fsck /dev/sda1— Checks and repairs the filesystem on/dev/sda1.
- Syntax:
xfs_repair:
- Syntax:
xfs_repair [device] - Explanation: Repairs an XFS filesystem.
- Example:
xfs_repair /dev/sda1— Repairs the XFS filesystem on/dev/sda1.
- Syntax:
15. System Backup (dd Command)
- Command:
dd- Syntax:
dd 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/sdato/dev/sdbwith block size 64K.
- Syntax:
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:
- Command:
yum install nfs-utils - Explanation: Installs NFS utilities.
- Example:
yum install nfs-utils
- Command:
Export a directory (on NFS server):
- File:
/etc/exports - Example:
- File:
Start NFS server:
- Command:
systemctl start nfs-server - Explanation: Starts the NFS service.
- Command:
Mount NFS share (on NFS client):
- Command:
mount -t nfs [server_ip]:/data /mnt - Explanation: Mounts the NFS share from the server to the local
/mntdirectory
System Administration
Check system uptime and load average:
- Use
uptimeorwto see uptime and load average. - Use
toporcat /proc/loadavgfor more details.
- Use
Analyze high CPU or memory usage:
- Use
top,htop,ps aux --sort=-%cpu, orvmstatto check CPU usage. - Use
free -morcat /proc/meminfofor memory usage. - Use
iotopfor disk I/O analysis.
- Use
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).
Troubleshoot slow-performing Linux system:
- Check CPU:
top,htop. - Check Memory:
free -m,vmstat. - Check Disk I/O:
iotop,iostat. - Check Network:
netstat,ss,iftop. - Check Logs:
journalctl,/var/log/messages.
- Check CPU:
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
Recover a forgotten root password:
- Boot into single-user mode or rescue mode.
- Use
passwd rootto reset the password.
Purpose of
sysctl.confand modifying kernel parameters:- Stores kernel parameters, e.g.,
vm.swappiness,net.ipv4.ip_forward. - Modify at runtime:
sysctl -w net.ipv4.ip_forward=1 - Persistent change: Edit
/etc/sysctl.confand apply withsysctl -p.
- Stores kernel parameters, e.g.,
Remount a filesystem as read-only:
Difference between
crontabandsystemd timers:crontabis simpler but lacks advanced logging.systemd timersare more powerful with dependencies and logs.
User & Permission Management
Lock/unlock a user account:
Difference between
chmod,chown, andchgrp:chmod: Changes file permissions (chmod 755 file).chown: Changes file owner (chown user file).chgrp: Changes group ownership (chgrp group file).
umaskusage:- Controls default file permissions.
- Example:
umask 022results in755for new directories.
Give sudo access to a user without editing
/etc/sudoers:Difference between
/etc/passwdand/etc/shadow:/etc/passwd: Stores user information./etc/shadow: Stores encrypted passwords.
Networking
Check open ports:
Difference between
iptablesandfirewalld:iptables: Legacy firewall, rule-based.firewalld: Dynamic, supports zones.
Troubleshoot DNS resolution issues:
Add a persistent static route:
Difference between
ping,traceroute, andmtr:ping: Checks reachability.traceroute: Shows route taken.mtr: Combines both.
Check which process is using a port:
Process & Performance Monitoring
Difference between
niceandrenice:nice: Sets priority when starting a process.renice: Changes priority of a running process.
Send a process to the background and bring it back:
What is
nohup?- Runs processes immune to hang-ups:
- Runs processes immune to hang-ups:
List and kill all processes of a user:
Monitor real-time performance:
File System & Storage
Check and repair filesystem errors:
LVM extension without unmounting:
Create and mount a new filesystem:
Difference between
ext4,xfs, andbtrfs:ext4: Stable, widely used.xfs: Better for large files.btrfs: Snapshot and RAID support.
List mounted filesystems:
Logs & Debugging
System logs location:
/var/log/syslog,/var/log/messages,/var/log/dmesg.
Track failed login attempts:
Filter logs using
journalctl:Configure log rotation:
/etc/logrotate.confor/etc/logrotate.d/.
Package Management
List installed packages:
Difference between
yumanddnf:dnfis faster and handles dependencies better.
Upgrade Linux kernel safely:
Check files owned by a package:
Security
Check system vulnerabilities:
What is SELinux?
- Mandatory access control system.
- Troubleshoot with
setenforce 0.
Difference between
ssh-keygenandssh-copy-id:ssh-keygen: Creates SSH keys.ssh-copy-id: Copies keys to a server.
Restrict SSH access:
- Edit
/etc/ssh/sshd_config, modifyAllowUsers.
Comments
Post a Comment