#Linux Fundamentals

Linux powers the vast majority of servers, containers, and cloud infrastructure. Understanding Linux is essential for any DevOps professional.

#šŸ“‹ Table of Contents


#What is Linux?

Linux is an open-source operating system kernel created by Linus Torvalds in 1991. A Linux distribution combines the kernel with software packages to create a complete OS.

#Why Linux for DevOps?

Loading diagram...

#Linux Distributions

#Debian Family

DistributionPackage ManagerUse Case
UbuntuaptGeneral purpose, cloud
DebianaptStability-focused
Linux MintaptDesktop users

#Red Hat Family

DistributionPackage ManagerUse Case
RHELdnf/yumEnterprise
CentOS StreamdnfRHEL testing ground
FedoradnfCutting-edge
Rocky LinuxdnfRHEL compatible
AlmaLinuxdnfRHEL compatible

#Other

DistributionPackage ManagerUse Case
AlpineapkMinimal containers
Arch LinuxpacmanRolling release
SUSE/openSUSEzypperEnterprise

#Filesystem Hierarchy

diagram
/
ā”œā”€ā”€ bin/          # Essential user binaries (ls, cp, etc.)
ā”œā”€ā”€ boot/         # Boot loader files
ā”œā”€ā”€ dev/          # Device files
ā”œā”€ā”€ etc/          # System configuration files
ā”œā”€ā”€ home/         # User home directories
│   └── username/
ā”œā”€ā”€ lib/          # System libraries
ā”œā”€ā”€ media/        # Mount points for removable media
ā”œā”€ā”€ mnt/          # Temporary mount points
ā”œā”€ā”€ opt/          # Optional/third-party software
ā”œā”€ā”€ proc/         # Process and kernel information
ā”œā”€ā”€ root/         # Root user home directory
ā”œā”€ā”€ sbin/         # System binaries
ā”œā”€ā”€ srv/          # Service data
ā”œā”€ā”€ sys/          # Kernel and system information
ā”œā”€ā”€ tmp/          # Temporary files
ā”œā”€ā”€ usr/          # User programs and data
│   ā”œā”€ā”€ bin/      # User binaries
│   ā”œā”€ā”€ lib/      # Libraries
│   ā”œā”€ā”€ local/    # Locally installed software
│   └── share/    # Shared data
└── var/          # Variable data
    ā”œā”€ā”€ log/      # Log files
    ā”œā”€ā”€ cache/    # Application cache
    └── www/      # Web server files

#Important Directories for DevOps

DirectoryPurpose
/etcConfiguration files
/var/logSystem and application logs
/homeUser data and scripts
/optThird-party applications
/tmpTemporary working space

#User Management

#Users and Groups

bash
1# View current user
2whoami
3
4# View user details
5id
6
7# View all users
8cat /etc/passwd
9
10# View all groups
11cat /etc/group

#Managing Users

bash
1# Create user
2sudo useradd -m -s /bin/bash username
3
4# Create user with home directory and groups
5sudo useradd -m -s /bin/bash -G sudo,docker devops
6
7# Set password
8sudo passwd username
9
10# Delete user
11sudo userdel -r username
12
13# Modify user
14sudo usermod -aG docker username  # Add to group

#Managing Groups

bash
1# Create group
2sudo groupadd developers
3
4# Add user to group
5sudo usermod -aG developers username
6
7# Remove user from group
8sudo gpasswd -d username developers
9
10# View group members
11getent group developers

#Sudo Access

bash
1# Edit sudoers file (safe way)
2sudo visudo
3
4# Add user to sudoers
5username ALL=(ALL:ALL) ALL
6
7# Allow passwordless sudo
8username ALL=(ALL) NOPASSWD:ALL
9
10# Add to sudo group (Debian/Ubuntu)
11sudo usermod -aG sudo username
12
13# Add to wheel group (RHEL/CentOS)
14sudo usermod -aG wheel username

#File Permissions

#Understanding Permissions

diagram
-rw-r--r--  1  owner  group  4096  Jan 1 12:00  file.txt
ā”‚ā”œā”€ā”¤ā”œā”€ā”¤ā”œā”€ā”¤
│ │  │  │
│ │  │  └── Others permissions (r--)
│ │  └───── Group permissions (r--)
│ └──────── Owner permissions (rw-)
└────────── File type (- = file, d = directory)

#Permission Values

PermissionSymbolNumber
Readr4
Writew2
Executex1
None-0

#Common Permission Patterns

NumericSymbolicMeaning
755rwxr-xr-xOwner full, others read/execute
644rw-r--r--Owner read/write, others read
700rwx------Owner only
600rw-------Owner read/write only
777rwxrwxrwxEveryone full (avoid!)

#Changing Permissions

bash
1# Using numeric mode
2chmod 755 script.sh
3chmod 644 config.yaml
4
5# Using symbolic mode
6chmod u+x script.sh        # Add execute for owner
7chmod g+w file.txt         # Add write for group
8chmod o-r secret.txt       # Remove read for others
9chmod a+r public.txt       # Add read for all
10
11# Recursive
12chmod -R 755 directory/

#Changing Ownership

bash
1# Change owner
2sudo chown username file.txt
3
4# Change owner and group
5sudo chown username:groupname file.txt
6
7# Recursive
8sudo chown -R username:groupname directory/

#Package Management

#APT (Debian/Ubuntu)

bash
1# Update package list
2sudo apt update
3
4# Upgrade packages
5sudo apt upgrade
6
7# Install package
8sudo apt install nginx
9
10# Remove package
11sudo apt remove nginx
12
13# Remove with config files
14sudo apt purge nginx
15
16# Search for packages
17apt search nginx
18
19# Show package info
20apt show nginx
21
22# Clean up
23sudo apt autoremove
24sudo apt clean

#DNF/YUM (RHEL/CentOS/Fedora)

bash
1# Update packages
2sudo dnf update
3
4# Install package
5sudo dnf install nginx
6
7# Remove package
8sudo dnf remove nginx
9
10# Search for packages
11dnf search nginx
12
13# List installed packages
14dnf list installed
15
16# Show package info
17dnf info nginx
18
19# Clean cache
20sudo dnf clean all

#APK (Alpine)

bash
1# Update package list
2apk update
3
4# Install package
5apk add nginx
6
7# Remove package
8apk del nginx
9
10# Search packages
11apk search nginx
12
13# Upgrade all packages
14apk upgrade

#Service Management

#Systemd (Modern Linux)

bash
1# Start service
2sudo systemctl start nginx
3
4# Stop service
5sudo systemctl stop nginx
6
7# Restart service
8sudo systemctl restart nginx
9
10# Reload configuration
11sudo systemctl reload nginx
12
13# Check status
14sudo systemctl status nginx
15
16# Enable at boot
17sudo systemctl enable nginx
18
19# Disable at boot
20sudo systemctl disable nginx
21
22# List all services
23systemctl list-units --type=service
24
25# View logs
26journalctl -u nginx
27journalctl -u nginx -f  # Follow logs
28journalctl -u nginx --since "1 hour ago"

#Service Unit File Example

ini
1# /etc/systemd/system/myapp.service
2[Unit]
3Description=My Application
4After=network.target
5
6[Service]
7Type=simple
8User=appuser
9WorkingDirectory=/opt/myapp
10ExecStart=/opt/myapp/bin/myapp
11Restart=always
12RestartSec=5
13
14[Install]
15WantedBy=multi-user.target
bash
1# Reload daemon after creating/editing unit file
2sudo systemctl daemon-reload
3
4# Enable and start
5sudo systemctl enable --now myapp

#Summary

TopicKey Commands
Usersuseradd, passwd, usermod
Permissionschmod, chown, ls -l
Packagesapt/dnf install, remove, update
Servicessystemctl start, stop, enable
Logsjournalctl -u service

[!TIP] Pro Tip: Practice these commands daily in a VM or container. Muscle memory is key!