Skip to main content
  1. Posts/

A Complete Introduction to Linux: An Actual Helpful Resource For Beginners

10 mins· 0 · 0 · ·
Zaney
Software Tools How To Linux RHEL Intro to Linux Beginner Linux Guide Introduction to Linux
Zaney
Author
Zaney
I am creating content about Linux & FOSS software. You’ll find me rocking NixOS with Hyprland, probably helping somebody with a question. 😎
Table of Contents

Linux is a versatile, open-source operating system used by millions around the world. Its flexibility, security, and cost-effectiveness make it an ideal choice for everything from personal computing to enterprise-grade servers. In this document, we’ll dive into the inner workings of Linux, understand its essential components, and explore its fundamental commands. We’ll primarily focus on Red Hat-based systems, which are widely used in enterprise environments. Even though this will focus on using Red Hat as an example this guide or resource is in no way specific to Red Hat or RHEL.

This page will cover many aspects of Linux and will be a long read. However, if you are new to Linux, want to understand it, and how it works-this will be an incredible resource.

How Linux Works #

The Linux Kernel #

At the heart of Linux is its kernel. The Linux kernel is the core that interacts directly with the hardware. It manages system resources like CPU, memory, and I/O devices. Users and applications interact with the kernel through system calls and libraries.

Key Functions of the Kernel:

  • Process Management: Handles multitasking, process scheduling, and execution.
  • Memory Management: Allocates and deallocates memory for processes.
  • Device Drivers: Facilitates communication between hardware and software.
  • Networking: Manages network protocols and data transmission.

User Space vs. Kernel Space #

Linux separates operations into two domains:

  • Kernel Space: Where the kernel runs and has full access to the hardware.
  • User Space: Where user applications and services operate, interacting with the kernel through APIs and system calls.

Essential Components of a Linux System #

  • Shell: A command-line interface for users to interact with the system.
  • Init System: The first process started by the kernel during boot. It initializes the system and starts services.
  • File System: Organizes and stores data on storage devices.
  • Networking Stack: Manages communication between devices and systems.

Basic Linux Commands #

Linux commands allow users to interact with the system efficiently. Below are 10 fundamental commands, their purposes, and examples of usage.

  1. ls – List Directory Contents

The ls command lists files and directories in the current directory.

  • Syntax: ls [options] [directory]
  • Examples:
    • ls – Lists contents of the current directory.
    • ls -l – Displays detailed information about files.
    • ls -a – Includes hidden files in the listing.
  1. cd – Change Directory

The cd command navigates between directories.

  • Syntax: cd [directory]
  • Examples:
    • cd /var/log – Moves to the /var/log directory.
    • cd .. – Moves up one directory level.

  1. pwd – Print Working Directory

Displays the current directory path.

  • Syntax: pwd
  • Example:
    • pwd – Outputs something like /home/user.
  1. cp – Copy Files and Directories

Copies files and directories from one location to another.

  • Syntax: cp [options] source destination
  • Examples:
    • cp file.txt /tmp/ – Copies file.txt to /tmp/.
    • cp -r folder/ /backup/ – Recursively copies the folder.
  1. mv – Move/Rename Files

Moves or renames files and directories.

  • Syntax: mv [options] source destination
  • Examples:
    • mv file.txt archive/ – Moves file.txt to archive/.
    • mv oldname.txt newname.txt – Renames the file.

  1. rm – Remove Files and Directories

Deletes files or directories.

  • Syntax: rm [options] file
  • Examples:
    • rm file.txt – Deletes file.txt.
    • rm -r folder/ – Recursively deletes folder/.
  1. mkdir – Make Directory

Creates new directories.

  • Syntax: mkdir [options] directory
  • Examples:
    • mkdir projects – Creates a directory named projects.
    • mkdir -p parent/child – Creates nested directories.
  1. rmdir – Remove Empty Directories

Deletes empty directories.

  • Syntax: rmdir directory
  • Example:
    • rmdir old_folder – Deletes old_folder if it’s empty.
  1. touch – Create Empty Files

Creates empty files or updates the timestamp of existing files.

  • Syntax: touch filename
  • Example:
    • touch newfile.txt – Creates an empty file named newfile.txt.
  1. cat – View File Contents

Displays the contents of a file.

  • Syntax: cat file
  • Examples:
    • cat file.txt – Outputs the contents of file.txt.
    • cat file1 file2 – Concatenates and displays contents of both files.

How to actually learn these tools: The best way to learn and become proficient with these programs is to load up a terminal and play around with these commands. Instead of using your graphical file manager for a while try just using your terminal to complete things like moving folders, adding and deleting files and folders, and so on.

Understanding Systemd #

Systemd is the default init system for most modern Linux distributions, including Red Hat. It’s responsible for initializing the system, managing services, and maintaining system states.

Key Features of Systemd:

  • Parallel service startup.
  • Unified logging with journald.
  • A robust dependency management system.

Managing Services with Systemd #

  • Starting a Service: systemctl start service_name
  • Stopping a Service: systemctl stop service_name
  • Enabling a Service to Start at Boot: systemctl enable service_name
  • Checking Service Status: systemctl status service_name

Creating a Custom Systemd Service #

  1. Create a Service File:
  • Example: /etc/systemd/system/myapp.service
[Unit]
Description=My Custom Application

[Service]
ExecStart=/usr/bin/myapp
Restart=always

[Install]
WantedBy=multi-user.target
  1. Reload Systemd: systemctl daemon-reload
  2. Start the Service: systemctl start myapp
  3. Enable the Service: systemctl enable myapp

Networking in Linux #

Linux has a robust networking stack that supports everything from simple configurations to complex routing setups.

Basic Networking Commands #

  • ip addr – Displays IP addresses.
  • ping – Tests connectivity to another host.
  • curl – Transfers data from or to a server.

Network Configuration Tools #

  • NetworkManager: GUI and CLI tools for managing network connections.
  • nmcli: Command-line interface for NetworkManager.
  • ifconfig/iwconfig: Older tools for network interface configuration.

Configuring Network Interfaces #

Use nmcli for NetworkManager-based setups:

nmcli con show
nmcli con add con-name "my-wifi" type wifi ssid "MySSID" password "mypassword"

Testing Connectivity #

  • Ping:
ping -c 4 example.com
  • Traceroute:
traceroute example.com

Managing Network Services #

  • Restart network services:
sudo systemctl restart network

Secure Network Configuration #

Use tools like iptables or nftables to configure advanced firewalls.

sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
As we continue our exploration into Linux, this guide delves deeper into advanced topics to enhance your Linux proficiency. We are now going to cover building custom scripts, understanding and managing file permissions, and implementing security best practices. These skills are essential for system administrators and anyone looking to maximize their efficiency and control over Linux environments.

Building Custom Scripts in Linux #

What are Shell Scripts? #

Shell scripts are text files containing a sequence of commands that are executed by a shell interpreter. They allow for automation of repetitive tasks, system administration, and workflow simplification. Most of the shell scripts you will find in the Linux ecosystem are Bash scripts. Bash is the default shell on almost all Linux systems. Here we will cover how to write your own:

Creating Your First Script #

  1. Create a File:
nano myscript.sh
  1. Add Script Content:
#!/bin/bash
echo "Hello, World!"
  1. Make the Script Executable:
chmod +x myscript.sh
  1. Run the Script:
./myscript.sh

Variables and Control Structures #

  • Variables:

You can try running this code below in the terminal and you will see the variable name is created with the value of Alice and can be recalled with the echo command.

name="Alice"
echo "Hello, $name!"
  • Conditional Statements:
if [ "$name" == "Alice" ]; then
    echo "Welcome, Alice!"
else
    echo "Access denied."
fi
  • Loops:
for i in {1..5}; do
    echo "Iteration $i"
done

Using Command-Line Tools in Scripts #

  • Integrate commands like grep, awk, sed, and curl to process data within scripts.
  • Example:
curl -s https://api.example.com/data | grep "key" > output.txt

Debugging Scripts #

Use the bash -x command to debug:

bash -x myscript.sh

Mastering File Permissions #

Understanding File Permissions #

Each file and directory in Linux has associated permissions, owner, and group. Use ls -l to view them:

-rw-r--r-- 1 user group 1234 Dec 20 10:00 file.txt
  • Owner Permissions: rw-
  • Group Permissions: r--
  • Other Permissions: r--

Changing Permissions with chmod #

  • Syntax: chmod [permissions] filename
  • Examples:
    • Make a file readable and writable by the owner only: chmod 600 file.txt
    • Make a script executable for everyone: chmod +x script.sh

Changing Ownership with chown #

  • Syntax: chown [owner][:group] filename
  • Example:
chown alice:developers file.txt

Special Permissions: SUID, SGID, and Sticky Bit #

  • Setuid (SUID): Executes files with the privileges of the file owner.
chmod u+s /path/to/file
  • Setgid (SGID): Runs files or directories with group permissions.
chmod g+s /path/to/dir
  • Sticky Bit: Prevents file deletion by users who are not the owner.
chmod +t /path/to/dir

Securing Your Linux System #

User and Group Management #

  • Add a User:
sudo adduser username
  • Delete a User:
sudo userdel username
  • Modify Group Memberships:
sudo usermod -aG groupname username

Configuring a Firewall #

  • Use firewalld (Red Hat-based systems):
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --reload
  • Use ufw (Uncomplicated Firewall):
sudo ufw allow 22/tcp
sudo ufw enable

Keeping the System Updated #

  • Regular updates reduce vulnerabilities:
sudo dnf update -y  # For Red Hat-based systems
sudo apt update && sudo apt upgrade -y  # For Debian-based systems
sudo pacman -Syu # For Arch-based systems

Securing SSH #

  • Disable Root Login: Edit /etc/ssh/sshd_config and set:
PermitRootLogin no
  • Use SSH Keys:
ssh-keygen -t rsa -b 4096
ssh-copy-id user@host

Monitoring and Logs #

  • System Logs: Use journalctl to view logs:
journalctl -u sshd
  • Disk Usage Monitoring:
df -h
du -sh /path/to/directory

Kernel Tuning #

Kernel tuning involves configuring the Linux kernel’s parameters to optimize system performance, stability, and resource utilization. These parameters govern everything from memory management to network throughput.

Tools for Kernel Tuning #

  1. sysctl: A command-line tool to modify kernel parameters.
  • View all current settings:
sysctl -a
  • Modify a parameter temporarily:
sysctl -w net.ipv4.ip_forward=1
  • Persist changes by editing /etc/sysctl.conf:
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl -p
  1. tuned: A service for dynamically optimizing system settings based on profiles.
  • Install:
sudo dnf install tuned
sudo systemctl enable --now tuned
  • List available profiles:
tuned-adm list
  • Apply a profile:
tuned-adm profile throughput-performance

Commonly Tuned Parameters #

  • Memory Management:
sysctl -w vm.swappiness=10  # Reduce swap usage
  • Networking:
sysctl -w net.core.rmem_max=16777216  # Increase receive buffer size
  • File Systems:
sysctl -w fs.file-max=2097152  # Increase max open files

Virtualization #

Virtualization allows running multiple operating systems on a single physical machine by abstracting hardware resources. It is a cornerstone of modern IT infrastructure, supporting cloud computing, development environments, and testing scenarios.

Types of Virtualization #

  • Full Virtualization: Provides complete abstraction of the hardware, allowing unmodified guest OS.
  • Para-virtualization: Requires modifications to the guest OS for optimal performance.
  • Containerization: Virtualizes at the application level using containers (e.g., Docker).

Tools for Virtualization #

KVM (Kernel-based Virtual Machine) #

KVM is a full virtualization solution integrated into the Linux kernel.

  • Installation:
sudo dnf install qemu-kvm libvirt virt-install
sudo systemctl enable --now libvirtd
  • Creating a Virtual Machine:
virt-install \
  --name=myvm \
  --ram=2048 \
  --disk path=/var/lib/libvirt/images/myvm.img,size=20 \
  --vcpus=2 \
  --os-variant=centos7 \
  --network network=default \
  --graphics none \
  --console pty,target_type=serial \
  --location='http://mirror.centos.org/centos/7/os/x86_64/' \
  --extra-args='console=ttyS0'

Docker #

Docker is a containerization platform that simplifies deploying and managing applications.

  • Installation:
sudo dnf install docker-ce
sudo systemctl enable --now docker
  • Running a Container:
docker run -d -p 8080:80 nginx
  • Useful Self-hosted Docker Apps:
    • Nextcloud: Private file sharing and collaboration.
docker run -d -p 443:443 nextcloud
  • Home Assistant: Smart home automation.
docker run -d --name homeassistant -p 8123:8123 homeassistant/home-assistant
  • Portainer: Docker management GUI.
docker run -d -p 9000:9000 portainer/portainer-ce

Kubernetes #

Kubernetes orchestrates containerized applications across a cluster of machines.

  • Installation on Red Hat-based Systems:
sudo dnf install kubectl
sudo dnf install kubeadm kubelet kubernetes-cni
  • Setting Up a Cluster:
sudo kubeadm init
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

Benefits of Virtualization #

  • Resource optimization.
  • Isolation for development/testing environments.
  • Enhanced scalability and disaster recovery.

Conclusion: Mastering Linux Beyond the Basics #

Through the exploration of scripting, permissions, system security, and virtualization, we’ve journeyed into the heart of what makes Linux an unparalleled choice for developers, administrators, and tech enthusiasts alike.

We’ve covered Linux scripting which provides unmatched flexibility, allowing users to automate repetitive tasks, streamline workflows, and handle complex processes with precision. Combining this with robust file permissions and enhanced security practices ensures a stable and protected environment, essential for both personal and enterprise-level use.

A Gateway to Infinite Possibilities #

Linux is not just an operating system—it’s a philosophy of control, adaptability, and community-driven innovation. Each step in mastering these advanced topics equips you with the tools to create efficient, secure, and scalable solutions. Whether you are developing scripts, managing virtualized clusters, or fine-tuning a kernel for peak performance, the possibilities are as limitless as your ambitions.

As we move forward, remember that Linux is a journey of continuous learning. With these foundational and advanced skills in your arsenal, you’re well-prepared to face the challenges of modern computing while embracing the boundless opportunities Linux provides.

Related

How to Create a Bootable USB in the Linux Terminal
5 mins· 0 · 0
Zaney
Software Tools How To Linux Terminal
How to Find Your Ubuntu Version
2 mins· 0 · 0
Zaney
Software Tools How To Linux Ubuntu
Understanding the Linux Operating System: An In-Depth Guide
5 mins· 0 · 0
Zaney
Software Tools Linux Linux Operating System
How to Make a Signature in Outlook
5 mins· 0 · 0
Zaney
Software Tools How To Outlook
Comprehensive Guide to Using Waybar
5 mins· 0 · 0
Zaney
Software Tools How To Waybar How To Use Waybar
Reasons Not to Choose Manjaro Linux: Exploring the Downsides
5 mins· 0 · 0
Zaney
Software Tools Linux Manjaro