#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 Distributions
- Filesystem Hierarchy
- User Management
- File Permissions
- Package Management
- Service Management
#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
| Distribution | Package Manager | Use Case |
|---|---|---|
| Ubuntu | apt | General purpose, cloud |
| Debian | apt | Stability-focused |
| Linux Mint | apt | Desktop users |
#Red Hat Family
| Distribution | Package Manager | Use Case |
|---|---|---|
| RHEL | dnf/yum | Enterprise |
| CentOS Stream | dnf | RHEL testing ground |
| Fedora | dnf | Cutting-edge |
| Rocky Linux | dnf | RHEL compatible |
| AlmaLinux | dnf | RHEL compatible |
#Other
| Distribution | Package Manager | Use Case |
|---|---|---|
| Alpine | apk | Minimal containers |
| Arch Linux | pacman | Rolling release |
| SUSE/openSUSE | zypper | Enterprise |
#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
| Directory | Purpose |
|---|---|
/etc | Configuration files |
/var/log | System and application logs |
/home | User data and scripts |
/opt | Third-party applications |
/tmp | Temporary 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
| Permission | Symbol | Number |
|---|---|---|
| Read | r | 4 |
| Write | w | 2 |
| Execute | x | 1 |
| None | - | 0 |
#Common Permission Patterns
| Numeric | Symbolic | Meaning |
|---|---|---|
| 755 | rwxr-xr-x | Owner full, others read/execute |
| 644 | rw-r--r-- | Owner read/write, others read |
| 700 | rwx------ | Owner only |
| 600 | rw------- | Owner read/write only |
| 777 | rwxrwxrwx | Everyone 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.targetbash
1# Reload daemon after creating/editing unit file
2sudo systemctl daemon-reload
3
4# Enable and start
5sudo systemctl enable --now myapp#Summary
| Topic | Key Commands |
|---|---|
| Users | useradd, passwd, usermod |
| Permissions | chmod, chown, ls -l |
| Packages | apt/dnf install, remove, update |
| Services | systemctl start, stop, enable |
| Logs | journalctl -u service |
[!TIP] Pro Tip: Practice these commands daily in a VM or container. Muscle memory is key!