Understanding Linux: A Comprehensive Guide for Beginners

Linux is an open-source operating system that is widely known for its flexibility, security, and diverse distributions (often called "flavors"). This guide will walk you through the fundamentals of Linux, covering essential concepts, commands, permissions, user management, and more.

What is Linux?

Linux is an open-source operating system kernel that serves as the foundation for various operating systems known as Linux distributions (distros). It provides a robust and secure environment for servers, desktops, and embedded systems.

Levels of Access in Linux

  1. User Level: Regular users with limited permissions.

  2. Root Level: The superuser with complete control over the system.

  3. Service Accounts: Specialized accounts for running services and daemons.

Security in Linux

Linux is known for its security features, which include:

  • User Permissions: Users are restricted by file permissions (read, write, execute).

  • Firewall Rules: Control incoming and outgoing network traffic using inbound and outbound rules.

  • Public and Private Keys: Asymmetric encryption for secure communication.

Linux offers various distributions (distros) catering to different needs:

  • Ubuntu: User-friendly and widely used for desktops.

  • CentOS: Ideal for servers with long-term support.

  • Debian: Known for stability and robustness.

  • RHEL (Red Hat Enterprise Linux): Enterprise-grade distro with professional support.

  • Arch Linux: A lightweight and flexible option for advanced users.

Linux Architecture

Here's a breakdown of Linux system architecture:

  1. Hardware (H/W): The physical components like CPU, RAM, and storage.

  2. Kernel: The core of the OS, responsible for process management, device management, memory management, etc.

  3. System Libraries: Libraries that support system utilities and applications.

  4. System Utilities: Essential tools for system administration.

  5. User Applications: Software like browsers, editors, etc.

Private Key vs. Public Key

  • Public Key: Shared with anyone for encryption.

  • Private Key: Kept secret for decryption. Example: SSH uses these keys for secure communication.

Ports: The Entry and Exit Points

Think of ports as doors and windows for your system:

  • Inbound Rules: Control incoming connections (like opening a door).

  • Outbound Rules: Control outgoing connections (like opening a window).


Basic Linux Commands

File and Directory Commands

  1. ls: List directory contents.

     $ ls
     Documents Downloads Pictures
    
  2. pwd: Print current working directory.

     $ pwd
     /home/ubuntu
    
  3. mkdir: Create a new directory.

     $ mkdir new_folder
    
  4. touch: Create an empty file.

     $ touch newfile.txt
    
  5. cat: Display contents of a file.

     $ cat filename.txt
     Hello, World!
    
  6. mv: Move or rename a file.

     $ mv oldname.txt newname.txt
    

Updating System Packages

  • Ubuntu:

      $ sudo apt update
    
  • CentOS:

      $ sudo yum update
    
  • Using Snap (Ubuntu):

      $ sudo snap install <package>
    

User Management in Linux

Creating Users and Managing Groups

  1. Creating a new user:

     $ sudo useradd newuser
    
    • useradd uses the /bin/sh shell by default.
  2. Switching to Root User:

     $ sudo su
    
  3. Checking User Information:

     $ cat /etc/passwd
     ubuntu:x:1000:1000:Ubuntu:/home/ubuntu:/bin/bash
    
    • userid and groupid are listed here.
  4. Adding a user to a group:

     $ sudo usermod -aG docker $USER
    
    • After adding, refresh the group membership:

        $ newgrp docker
      
  5. addgroup vs groupadd: Both are used to create groups but addgroup is a Debian-specific variant with more user-friendly prompts.

Understanding File Permissions

  • Permission Levels:

    • r (read) = 4

    • w (write) = 2

    • x (execute) = 1

  • Example of File Permissions:

      $ ls -l
      -rw-rw-r-- 1 ubuntu ubuntu 4096 Nov 10 10:00 file.txt
    
    • rw- for Owner (User)

    • rw- for Group

    • r-- for Others

๐Ÿ” Essential Linux Commands

1. Viewing and Manipulating Files

$ cat file.txt      # Display file contents
$ mv oldname.txt newname.txt  # Rename or move a file
$ rm filename.txt   # Delete a file
$ cp source.txt destination.txt  # Copy a file

2. System Monitoring

$ ps -aux          # Display all running processes
$ top              # Monitor system resources in real-time
$ sleep 100        # Pause terminal for 100 seconds

3. Using vi Text Editor

$ vi myfile.txt
# Press 'i' to enter insert mode
# Type your content
# Press 'ESC', then type ':wq' to save and exit

4. Viewing System Information

$ uname -a         # Display system information
$ df -h            # Show disk usage
$ free -m          # Display memory usage

๐Ÿ—‚๏ธ Important Directories in Linux

DirectoryDescription
/etcConfiguration files
/homeUser home directories
/varVariable data (e.g., logs)
/optOptional software packages
0
Subscribe to my newsletter

Read articles from Krishnat Ramchandra Hogale directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Krishnat Ramchandra Hogale
Krishnat Ramchandra Hogale

Hi! Iโ€™m Krishnat, a Senior IT Associate specializing in Performance Engineering at NTT DATA SERVICES. With experience in cloud technologies, DevOps, and automation testing, I focus on optimizing CI/CD pipelines and enhancing infrastructure management. Currently, I'm expanding my expertise in DevOps and AWS Solutions Architecture, aiming to implement robust, scalable solutions that streamline deployment and operational workflows.