Complete Ubuntu OS Tutorial with Usage Examples
1. Introduction to Ubuntu
Ubuntu is a free, open-source Linux distribution based on Debian. Developed by Canonical Ltd., it's known for its user-friendliness, extensive software availability, strong community support, and regular release cycles. Ubuntu is designed to be a versatile operating system, suitable for desktops, servers, cloud computing, and IoT devices.
Why Choose Ubuntu?
- User-Friendly: Often considered one of the easiest Linux distributions for new users, especially those coming from Windows or macOS.
- Wide Adoption: Very popular on desktops, and a dominant force in server and cloud environments.
- Rich Software Ecosystem: Access to millions of open-source applications through its package manager (APT).
- Strong Community Support: Vast online documentation, forums, and a global community to assist users.
- Regular Updates & LTS: New versions every six months, with Long Term Support (LTS) releases every two years for stability.
2. Ubuntu Versions & Flavors
A. Release Cycles:
- Regular Releases: Released every six months (e.g., 24.04, 24.10, 25.04...). Supported for 9 months.
- LTS (Long Term Support) Releases: Released every two years (e.g., 20.04 LTS, 22.04 LTS, 24.04 LTS). Supported for 5 years for desktop and server, extendable to 10 years with Ubuntu Pro. LTS releases are recommended for stability, especially for servers and production environments.
B. Ubuntu Flavors (Different Desktop Environments):
While Ubuntu's default desktop environment is GNOME, several official "flavors" offer alternative desktop experiences:
- Ubuntu (Default): Uses the GNOME desktop environment, known for its modern and clean interface.
- Kubuntu: Ubuntu with the KDE Plasma desktop, highly customizable and feature-rich.
- Xubuntu: Ubuntu with the XFCE desktop, lightweight and fast, ideal for older hardware.
- Lubuntu: Ubuntu with the LXQt desktop, extremely lightweight, for minimal resource usage.
- Ubuntu MATE: Ubuntu with the MATE desktop, a traditional desktop experience.
- Ubuntu Budgie: Ubuntu with the Budgie desktop, modern and elegant.
3. Installation Methods
Ubuntu can be installed in various environments:
Basic GUI Installation Steps (Virtual Machine Example):
- Boot your VM/computer from the Ubuntu Desktop ISO.
- Choose "Try Ubuntu" (to test without installing) or "Install Ubuntu".
- Select Language and Keyboard layout.
- Updates and other software:
- Choose "Normal installation" or "Minimal installation".
- Check "Download updates while installing" and "Install third-party software for graphics and Wi-Fi hardware and additional media formats".
- Installation type:
- "Erase disk and install Ubuntu" (safest for VMs or dedicated systems).
- "Something else" (for custom partitioning, e.g., dual-boot).
- Choose Location: Set your timezone.
- Who are you?: Create your user account (full name, username, password). Check "Require my password to log in" and "Encrypt my home folder" (optional, for security).
- Click **Install Now**.
- After installation, **Restart Now**. Remove the ISO from the drive if prompted.
- Log in with your created user account.
4. Getting Started with the GUI (GNOME Desktop)
Ubuntu's default desktop environment is GNOME, designed for a modern and user-friendly experience.
- Desktop: Your main workspace. Right-click for context menu (Change Background, Display Settings, Open in Terminal).
- Top Bar:
- Activities: Top-left corner. Click or press the Super (Windows) key to open the Activities Overview.
- Application Menu: Next to "Activities," shows the active application's name.
- Clock & Calendar: Center.
- Status Icons: Top-right. Quick access to Network, Volume, Battery, User Menu (Shutdown, Restart, Lock Screen).
- Dock (Launcher): Vertical bar on the left side (default position).
- Contains frequently used applications, running applications, and the Applications (grid) button at the bottom.
- Click to launch/switch apps. Right-click for contextual menus.
- Activities Overview: (Press Super key or click "Activities").
- Shows all open windows and multiple virtual "Workspaces" (desktops) for organizing tasks.
- Search bar at the top for apps, files, settings, and web search.
- Files (Nautilus): Ubuntu's default file manager, similar to Windows File Explorer or macOS Finder.
- Access from the Dock.
- Provides views (Icons, List), sidebar for quick access to Home, Documents, Downloads, Trash, Network, Drives.
- Software Center (Ubuntu Software): Your graphical gateway to install and manage applications from Ubuntu's repositories and Snap Store.
- Access from the Dock. Browse categories, search for apps, install/uninstall with a few clicks.
- Settings: Central hub for configuring your Ubuntu system.
- Access from the Status Icons (top-right) > Gear icon, or search in Activities.
- Sections include Network, Bluetooth, Background, Appearance, Notifications, Privacy, Users, Displays, Sound, etc.
# Example: Customizing desktop via GUI
# 1. Click on "Activities" (top-left) or press the Super key.
# 2. Type "Settings" and open the Settings application.
# 3. In the sidebar, click on "Appearance".
# 4. Change "Style" (Light/Dark), "Accent color", "Dock position", "Icon size", etc.
# 5. Observe changes on your desktop.
5. Basic Terminal Commands (CLI)
The command-line interface (CLI) is fundamental for advanced tasks. Open the "Terminal" application (e.g., Ctrl + Alt + t).
- `pwd` (Print Working Directory): Shows your current directory.
pwd
# Output: /home/yourusername
- `ls` (List): Lists files and directories.
ls -l # Long format (details: permissions, owner, size, date)
ls -a # List all files, including hidden ones (starting with .)
ls -lh # Long format, human-readable sizes (KB, MB, GB)
ls /var/log # List contents of a specific directory
- `cd` (Change Directory): Navigates between directories.
cd Documents # Move into 'Documents'
cd .. # Move up one directory
cd ~ # Move to your home directory
cd / # Move to the root directory
cd - # Move to the previous directory
- `mkdir` (Make Directory): Creates new directories.
mkdir my_new_folder
mkdir -p projects/my_app # Creates parent directories if they don't exist
- `rmdir` (Remove Directory): Deletes empty directories.
rmdir my_empty_folder
- `touch`: Creates empty files or updates a file's timestamp.
touch new_document.txt
touch script.sh
- `cp` (Copy): Copies files or directories.
cp file1.txt file2.txt # Copy file1.txt to file2.txt in same directory
cp image.jpg /home/user/Pictures/ # Copy to another directory
cp -r my_folder /backup/ # Copy a directory recursively
- `mv` (Move): Moves or renames files/directories.
mv old_name.txt new_name.txt # Rename a file
mv document.pdf /archive/ # Move file to /archive/
- `rm` (Remove): Deletes files or directories.
rm unwanted_file.txt
rm -i important_file.txt # Prompt before deleting
rm -r my_folder # Remove a directory and its contents recursively (USE WITH CAUTION!)
rm -f stubborn_file.txt # Force remove (no prompt)
rm -rf very_critical_folder # Force remove recursively (EXTREME CAUTION: Irreversible!)
- `cat` (Concatenate): Displays the content of files.
cat my_document.txt
cat /etc/os-release # Show OS information
- `less` / `more`: View file content page by page.
less /var/log/syslog # Press Space to scroll, 'q' to quit
- `head` / `tail`: Display beginning/end of a file.
head -n 5 file.txt # Show first 5 lines
tail -n 10 file.txt # Show last 10 lines
tail -f /var/log/auth.log # Follow a log file in real-time (Ctrl+C to exit)
- `echo`: Prints text to the terminal.
echo "Hello, Ubuntu!"
- `man` (Manual): Displays the manual page (documentation) for a command.
man ls # Press 'q' to quit
- `sudo` (SuperUser Do): Executes a command with superuser (root) privileges. Required for many system administration tasks.
sudo apt update # Update package lists (requires password)
6. Linux File System Hierarchy (FHS)
Ubuntu, like other Linux distributions, adheres to the Filesystem Hierarchy Standard (FHS), which defines a standardized directory structure.
- `/` (Root): The top-level directory. All other directories and files are located under it.
- `/bin`: (Binaries) Essential command binaries for all users.
- `/sbin`: (System Binaries) Essential system binaries for system administration.
- `/etc`: (Etcetera) Host-specific system-wide configuration files.
- `/home`: Home directories for regular users (e.g., `/home/yourusername`).
- `/root`: The home directory for the `root` (superuser) account.
- `/opt`: (Optional) Optional application software packages.
- `/usr`: (Unix System Resources) Read-only user utilities and applications.
- `/usr/bin`: Most user commands.
- `/usr/local`: Locally installed software.
- `/var`: (Variable) Variable data files, such as log files (`/var/log`), mail queues, and temporary files.
- `/tmp`: (Temporary) Temporary files, usually deleted on system reboot.
- `/dev`: (Devices) Special device files representing hardware devices.
- `/proc`: (Processes) A virtual filesystem providing information about running processes and kernel state.
- `/sys`: (System) A virtual filesystem providing access to kernel information and device drivers.
- `/boot`: Contains files needed to boot the operating system.
- `/media`: Mount points for removable media.
- `/mnt`: (Mount) Temporarily mounted filesystems.
- `/snap`: Where Snap packages are typically mounted.
7. File Permissions and Ownership
Linux security relies on file permissions and ownership to control access to files and directories.
Permissions (Read, Write, Execute):
- `r` (Read): Can view content (file) or list contents (directory).
- `w` (Write): Can modify/delete content (file) or create/delete/rename files within (directory).
- `x` (Execute): Can run (file) or enter/traverse (directory).
Permission Categories:
Permissions are assigned to three categories:
- `u` (User/Owner): The user who owns the file or directory.
- `g` (Group): The group that owns the file or directory.
- `o` (Others): All other users on the system.
Viewing Permissions (`ls -l`):
ls -l my_script.sh
# Example Output: -rwxr-xr-- 1 yourusername yourusername 1234 Jul 19 10:00 my_script.sh
Breakdown of `-rwxr-xr--`:
- First character (`-`): File type (`-` for regular file, `d` for directory, `l` for symbolic link).
- Next 3 (`rwx`): Owner's permissions.
- Next 3 (`r-x`): Group's permissions.
- Last 3 (`r--`): Others' permissions.
Changing Permissions (`chmod`):
Can use symbolic mode (r, w, x, u, g, o, a) or octal (numeric) mode.
- Octal (Numeric) Mode: Each permission has a numeric value: `r=4`, `w=2`, `x=1`. Sum the values for each category.
chmod 755 my_script.sh # Owner: rwx (7), Group: r-x (5), Others: r-x (5)
# Visual: -rwxr-xr-x
chmod 644 my_document.txt # Owner: rw- (6), Group: r-- (4), Others: r-- (4)
# Visual: -rw-r--r--
chmod +x my_script.sh # Add execute permission for all (commonly used for scripts)
Changing Ownership (`chown`, `chgrp`):
Requires `sudo` (superuser privileges).
8. User and Group Management
Ubuntu provides commands for managing user accounts and groups.
User Accounts:
- `root`: The superuser, has full administrative privileges.
- System users: Accounts created by services/applications (UIDs 1-999).
- Normal users: Regular user accounts (UIDs usually 1000+).
Common Commands (requires `sudo` for management):
- `whoami`: Display the current username.
- `id`: Display user and group IDs for the current or specified user.
id yourusername
# Output example: uid=1000(yourusername) gid=1000(yourusername) groups=1000(yourusername),4(adm),24(cdrom),27(sudo)...
- `adduser`: Create a new user account. This command is a higher-level script that sets up the home directory, default group, and prompts for password/details.
sudo adduser newuser
# Follow prompts for password and user information.
- `useradd`: A lower-level command for creating users. Doesn't create home directory or set password by default.
sudo useradd -m -s /bin/bash newuser2 # -m: create home dir, -s: set shell
- `passwd`: Set or change a user's password.
passwd # Change your own password
sudo passwd newuser # Set password for newuser
- `usermod`: Modify user account properties.
sudo usermod -aG sudo newuser # Add newuser to 'sudo' group (grant sudo privileges)
sudo usermod -l new_name old_name # Change username (careful with this!)
sudo usermod -d /home/customhome newuser # Change home directory
- `deluser` / `userdel`: Delete a user account.
sudo deluser olduser # Delete user, but leave home directory
sudo deluser --remove-home olduser2 # Delete user and home directory
Groups:
Groups are collections of users, simplifying permission management for multiple users.
- `addgroup`: Create a new group.
sudo addgroup mydevgroup
- `delgroup`: Delete a group.
sudo delgroup myoldgroup
- `gpasswd`: Manage group members.
sudo gpasswd -a newuser mydevgroup # Add newuser to mydevgroup
sudo gpasswd -d olduser mydevgroup # Remove olduser from mydevgroup
- `groups`: List groups a user belongs to.
groups # List groups for current user
groups newuser # List groups for newuser
Configuration Files:
- `/etc/passwd`: Stores user account information (username, UID, GID, home directory, shell).
- `/etc/shadow`: Stores encrypted user passwords and password aging. (Root-readable only).
- `/etc/group`: Stores information about groups.
- `/etc/sudoers`: Defines which users/groups can run `sudo` commands (edited with `visudo`).
9. Package Management (APT)
Ubuntu uses the Advanced Package Tool (APT) for managing software packages. It's a powerful and easy-to-use system.
10. Process Management
Managing running programs and background tasks.
- `ps` (Process Status): Displays information about running processes.
ps aux # Show all running processes (user, CPU, memory usage)
ps -ef # Show all processes in full format (more details)
ps -p <PID> # Show info for a specific Process ID
- `top`: Provides a real-time, dynamic view of running processes, CPU usage, memory usage, and other system information. Press q to quit.
top
- `htop`: An interactive process viewer, similar to `top` but with a more user-friendly interface. (Installable: `sudo apt install htop`).
htop
- `kill`: Sends a signal to a process, typically to terminate it. Requires the Process ID (PID).
kill <PID> # Sends SIGTERM (graceful termination request)
kill -9 <PID> # Sends SIGKILL (forceful termination, cannot be ignored)
- `pkill` / `killall`: Kill processes by name.
pkill firefox # Kills all processes named firefox
killall nginx # Kills all processes named nginx
- `jobs`: Lists background jobs in the current shell session.
- `fg` (Foreground): Brings a background job to the foreground.
- `bg` (Background): Sends a suspended job to the background. (Use Ctrl + z to suspend a foreground job first).
- `nohup command &`: Run a command in the background, immune to terminal closure.
11. Service Management (systemd)
Ubuntu, like most modern Linux distributions, uses `systemd` as its init system and service manager. It controls system services (daemons).
- `systemctl status <service_name>`: Check the status of a service.
systemctl status nginx.service
# Output will show if it's active (running), inactive (dead), enabled (starts on boot), etc.
- `systemctl start <service_name>`: Start a service.
sudo systemctl start nginx.service
- `systemctl stop <service_name>`: Stop a service.
sudo systemctl stop nginx.service
- `systemctl restart <service_name>`: Restart a service.
sudo systemctl restart nginx.service
- `systemctl enable <service_name>`: Enable a service to start automatically on boot.
sudo systemctl enable nginx.service
- `systemctl disable <service_name>`: Disable a service from starting automatically on boot.
sudo systemctl disable nginx.service
- `systemctl reload <service_name>`: Reload a service's configuration without restarting (if supported by the service).
sudo systemctl reload nginx.service
- `systemctl list-units --type=service`: List all active services.
- `systemctl is-active <service_name>`: Check if a service is running.
12. Networking (Netplan, UFW)
Ubuntu uses Netplan for network configuration and UFW for firewall management.
- `ip a` (IP Address): Displays network interface information. (Recommended over `ifconfig`).
ip a # Shows interfaces like lo, eth0, enpXsY, wlan0 etc.
- `ip route`: Displays the routing table.
ip route show
- `ping`: Tests network connectivity to a host.
ping google.com
- `ss` (Socket Statistics): Displays network socket information. (Modern replacement for `netstat`).
ss -tuln # Show TCP/UDP listening ports
ss -tunap # Show all TCP/UDP connections with process info
- `netstat` (Legacy, use `ss`): Displays network connections, routing tables, interface statistics.
- `curl` / `wget`: Command-line tools for making web requests and downloading files.
curl https://example.com
wget https://example.com/software.deb
- `nslookup` / `dig`: DNS lookup utilities.
- `netplan`: Ubuntu's modern network configuration utility. Configuration files are YAML files in `/etc/netplan/`.
# Example Netplan config (50-cloud-init.yaml for DHCP):
# Use 'sudo nano /etc/netplan/50-cloud-init.yaml'
# network:
# ethernets:
# enp0s3: # Your ethernet interface name
# dhcp4: true
# version: 2
# After editing a Netplan file:
sudo netplan generate # Generate configuration files
sudo netplan apply # Apply changes
- UFW (Uncomplicated Firewall): Ubuntu's default firewall management tool, simplifying `iptables` commands.
sudo ufw enable # Enable firewall
sudo ufw allow ssh # Allow SSH (port 22)
sudo ufw allow http # Allow HTTP (port 80)
sudo ufw status verbose # Check status
13. Storage Management
Managing disk space, partitions, and file systems.
- `df` (Disk Free): Reports file system disk space usage.
df -h # Human-readable output (GB, MB)
- `du` (Disk Usage): Estimates file space usage of files and directories.
du -sh /home/yourusername # Summarize home directory size (human-readable)
du -h /var/log # Show sizes of subdirectories in /var/log
- `lsblk` (List Block Devices): Lists information about all available or specified block devices (hard drives, partitions).
lsblk
- `fdisk` (Partition Disk): Command-line utility for disk partitioning. (Use with extreme caution).
sudo fdisk /dev/sda # Opens interactive partitioning tool for sda
- `mkfs` (Make Filesystem): Builds a Linux file system on a device.
sudo mkfs.ext4 /dev/sdb1 # Format partition sdb1 with ext4 filesystem
- `mount` / `umount`: Mounts a file system onto a directory, making it accessible. `umount` unmounts it.
sudo mount /dev/sdb1 /mnt/data # Mount sdb1 to /mnt/data
sudo umount /mnt/data # Unmount /mnt/data
- `/etc/fstab`: A configuration file that defines static file systems to be mounted automatically at boot time.
- LVM (Logical Volume Manager): Provides a more flexible way to manage disk space. (More advanced topic).
14. Shell Scripting Basics
Shell scripting allows you to automate tasks by writing a series of commands in a file that the shell can execute. Ubuntu typically uses Bash as its default shell.
A. Creating a Script:
# Create a file named 'hello_ubuntu.sh'
nano hello_ubuntu.sh
# Add the following content:
#!/bin/bash
# This is my first Ubuntu script.
echo "Hello from Ubuntu!"
echo "User: $(whoami)"
echo "Uptime: $(uptime -p)" # Human-readable uptime
B. Making Executable and Running:
chmod +x hello_ubuntu.sh
./hello_ubuntu.sh
C. Basic Scripting Concepts:
- Variables: `NAME="Ubuntu"`, `echo "Welcome to $NAME"`.
- Input/Output: `echo` for output, `read` for user input.
- Conditionals (`if`, `elif`, `else`): `if [[ $NUM -gt 10 ]]; then ... fi`.
- String: `==`, `!=`. Numeric: `-eq`, `-gt`, `-lt`. File: `-f`, `-d`.
- Loops (`for`, `while`): `for i in {1..3}; do ... done`. `while [[ $COUNT -lt 5 ]]; do ... done`.
- Functions: `my_func() { echo "Inside function"; }`.
- Command-line Arguments: `$0`, `$1`, `$#`, `$@`.
- Error Handling: `set -e` (exit on error), `set -x` (debug mode).
- Input/Output Redirection: `>`, `>>`, `2>`.
- Pipes (`|`): Chain commands together.
15. Text Editors (GUI & CLI)
Ubuntu provides both graphical and command-line text editors.
16. Security Best Practices
Implementing security best practices is crucial for any Ubuntu system.
- Keep System Updated: Regularly update your OS and software to apply security patches.
sudo apt update && sudo apt upgrade -y
- Use Strong Passwords & SSH Keys: For all user accounts, especially those with `sudo` privileges. Prefer SSH key-based authentication for remote access.
- Configure Firewall (UFW): Restrict network access to only necessary ports.
sudo ufw enable
sudo ufw allow 22/tcp # Allow SSH
sudo ufw allow 80/tcp # Allow HTTP
sudo ufw status verbose # Check firewall status
- Principle of Least Privilege: Grant users and services only the minimum permissions necessary. Avoid using `root` for daily operations.
- Disable Unnecessary Services: Stop and disable services you don't need to reduce the attack surface.
sudo systemctl disable <service_name>
- Monitor Logs: Regularly review system logs (`/var/log/syslog`, `/var/log/auth.log`) for suspicious activity. Use `journalctl` for `systemd` logs.
sudo journalctl -f # Follow live logs
sudo journalctl -u sshd # View SSH daemon logs
- Regular Backups: Implement a robust backup strategy for critical data.
- Secure SSH: Disable password authentication (use keys), change default SSH port, and restrict root login directly.
- Fail2ban: Install Fail2ban to protect against brute-force attacks by blocking IPs that show malicious signs.
sudo apt install fail2ban
sudo systemctl enable fail2ban
sudo systemctl start fail2ban
Your Ubuntu Journey Begins!
Ubuntu provides an excellent entry point into the world of Linux. Its user-friendly GUI, robust command-line tools, and extensive software ecosystem make it a powerful choice for both personal computing and server administration. Consistent practice, experimentation, and leveraging its vast community resources will empower you to master this versatile operating system.