Day 1: Introduction to Linux & Getting Started
Introduction:
Welcome to Day 1 of "Learn Linux in 30 Days"! Today, we'll explore what Linux is, why it's important, and how to get it up and running on your computer. No prior Linux experience is required – just a willingness to learn!
Key Concepts:
- What is Linux?
- Linux is an open-source operating system (OS) kernel. An OS is the core software that manages your computer's hardware and allows you to run programs.
- The term "Linux" is often used to describe the entire operating system built around the Linux kernel, which includes various software tools and applications.
- Open Source: This means the source code is freely available for anyone to view, modify, and distribute. It fosters collaboration and community-driven development.
- History: Created by Linus Torvalds in 1991, Linux has grown into a powerful and versatile OS used worldwide.
- Philosophy: Emphasizes freedom, customization, and community involvement.
- Distributions (Distros): These are different "flavors" of Linux, each with its own set of software, desktop environment, and package management system. Examples: Ubuntu, Fedora, Debian, Mint, Arch Linux.
- Why Learn Linux?
- Career Opportunities: High demand for Linux skills in system administration, cloud computing, cybersecurity, and more.
- Control and Customization: Gives you more control over your computer and allows for extensive customization.
- Stability and Security: Known for its stability and robust security features.
- Open Source Advantage: Be part of a global community and contribute to open-source projects.
- Server Dominance: Linux powers a vast majority of web servers and cloud infrastructure.
- Choosing a Distribution:
- For beginners, user-friendly distributions like Ubuntu, Linux Mint, or Fedora are recommended. They have large communities, ample documentation, and easy installation processes.
- Ubuntu: Known for its ease of use and extensive software repository.
- Linux Mint: Based on Ubuntu, offering a more traditional desktop experience.
- Fedora: Focuses on cutting-edge technology and open-source principles.
- Installation:
- Virtual Machine (VM): The easiest and safest way to try Linux without affecting your current operating system. You can use software like VirtualBox (free) or VMware Workstation Player (free for personal use) to create a VM.
- Dual-Boot: Installing Linux alongside your existing operating system (e.g., Windows). Requires more careful partitioning of your hard drive.
- Live USB/DVD: Booting Linux from a USB drive or DVD without installing it. Great for testing but changes won't be saved unless you set up persistence.
- Steps for Installing in a Virtual Machine (using VirtualBox as an example):
- Download VirtualBox: Get it from https://www.virtualbox.org/ and install it.
- Download a Linux ISO: Go to the website of your chosen distribution (e.g., https://ubuntu.com/, https://linuxmint.com/, https://getfedora.org/) and download the ISO file (disk image).
- Create a New VM in VirtualBox:
- Open VirtualBox and click "New."
- Give your VM a name (e.g., "Ubuntu 22.04").
- Select "Linux" as the Type and the correct Version (e.g., "Ubuntu (64-bit)").
- Allocate RAM (at least 2GB recommended).
- Create a virtual hard disk (dynamically allocated, at least 25GB).
- Start the VM and Select the ISO:
- Select your newly created VM and click "Start."
- You'll be prompted to choose a startup disk. Click the folder icon and select the ISO file you downloaded.
- Install Linux: Follow the on-screen instructions to install your chosen distribution. This usually involves selecting your language, keyboard layout, time zone, and creating a user account.
- Introduction to the Command-Line Interface (CLI) vs. Graphical User Interface (GUI):
- GUI: The visual desktop environment you're likely familiar with (icons, windows, mouse).
- CLI: A text-based interface where you type commands to interact with the system. Powerful and efficient for many tasks.
- Terminal: The program that provides the CLI environment.
- pwd (print working directory): Shows your current location in the file system.
- ls (list): Lists the files and directories in the current directory.
- cd (change directory): Used to navigate between directories.
- pwd (Output might be: /home/yourusername)
- ls (Lists files and directories in your current location)
- cd /home (Navigates to the /home directory)
- cd Downloads (Navigates into the Downloads directory, assuming it exists in your current location)
- cd .. (Navigates up one level in the directory tree)
- Install your chosen Linux distribution in a virtual machine (or using another method if you prefer).
- Open the terminal.
- Use pwd to find your current location.
- Use ls to see what files and directories are present.
- Use cd to navigate to a different directory (e.g., the Documents directory if it exists).
Day 2: Understanding the File System
Introduction:
Today, we'll delve into the structure of the Linux file system, which is organized differently than Windows. Understanding this structure is crucial for navigating and managing your system effectively.
Key Concepts:
- Hierarchical Structure: The Linux file system is like an upside-down tree, starting with the root directory (represented by /). All other directories and files branch out from the root.
- Key Directories:
- / (root): The top-level directory.
- /home: Contains the personal directories for each user (e.g., /home/yourusername). This is where you'll store your documents, downloads, etc.
- /etc: Contains system-wide configuration files.
- /var: Contains variable data, such as logs, databases, and spools.
- /bin: Contains essential command-line binaries (executables) needed for basic system operation.
- /sbin: Contains system administration binaries (usually requiring root privileges).
- /usr: Contains a large collection of user programs, libraries, and documentation.
- /tmp: Temporary files that are usually deleted on reboot.
- /boot: Contains files needed to boot the system.
- /dev: Contains device files, representing hardware devices.
- /media: Mount points for removable media (e.g., USB drives).
- /mnt: A temporary mount point for mounting filesystems manually.
- /opt: Optional or add-on software packages.
- /proc: A virtual filesystem providing process and kernel information.
- /root: The home directory for the root user (administrator).
- File Types:
- Regular Files: Ordinary files containing data (text, images, programs, etc.).
- Directories: Special files that can contain other files and directories (like folders in Windows).
- Symbolic Links (Symlinks): Pointers to other files or directories (like shortcuts in Windows).
- cd .. : Move up one level in the directory hierarchy.
- cd - : Go back to the previous directory you were in.
- Absolute vs. Relative Paths:
- Absolute Path: Specifies the full path starting from the root directory (e.g., /home/yourusername/Documents/myfile.txt).
- Relative Path: Specifies the path relative to your current working directory (e.g., Documents/myfile.txt if you're in /home/yourusername).
- cat: Displays the entire content of a file. (Use with caution for large files!)
- less: A pager that allows you to view a file one screen at a time (use the spacebar to scroll down, b to scroll back, and q to quit).
- head: Displays the first few lines of a file (default is 10).
- tail: Displays the last few lines of a file (default is 10).
- cd /etc (Navigate to the /etc directory using an absolute path)
- cd ../../ (Move up two levels from your current directory)
- cat /etc/passwd (Display the content of the /etc/passwd file - be careful as this contains user information)
- less /var/log/syslog (View the system log file using less)
- head -n 5 myfile.txt (Display the first 5 lines of myfile.txt)
- tail -n 20 access.log (Display the last 20 lines of access.log)
- Navigate to the root directory (/).
- Explore some of the key directories mentioned above (e.g., /home, /etc, /var, /bin).
- Use ls to list the contents of these directories.
- Try using cat, less, head, and tail on some small text files you find (avoid modifying system configuration files at this stage!).
- Create a new text file called my_first_file.txt in your home directory using the touch command.
- View the content of my_first_file.txt.
Day 3: Working with Files and Directories
Introduction:
Now that you can navigate the file system, let's learn how to create, manage, and manipulate files and directories.
Key Concepts:
- Creating Files and Directories:
- touch filename: Creates an empty file.
- mkdir directoryname: Creates a new directory.
- Copying, Moving, and Renaming:
- cp source destination: Copies a file or directory.
- cp file1.txt file2.txt (Copies file1.txt to file2.txt)
- cp -r dir1 dir2 (Recursively copies dir1 to dir2, including all its contents)
- mv source destination: Moves or renames a file or directory.
- mv file1.txt newlocation/ (Moves file1.txt to the newlocation directory)
- mv oldname.txt newname.txt (Renames oldname.txt to newname.txt)
- rm file1.txt: Removes a file.
- rm -r dir1: Recursively removes dir1, including all its contents.
- cp source destination: Copies a file or directory.
- Wildcards: Special characters used for pattern matching:
- *: Matches any sequence of characters (or no characters).
- ls *.txt (Lists all files ending with .txt)
- rm * .jpg (Removes all files ending with .jpg--be very careful with rm and wildcards!)
- ?: Matches any single character.
- ls file?.txt (Lists files like file1.txt, fileA.txt, but not file10.txt)
- *: Matches any sequence of characters (or no characters).
- mkdir MyDocuments (Creates a directory named MyDocuments)
- touch newfile.txt (Creates an empty file named newfile.txt)
- cp report.doc backup/ (Copies report.doc to the backup directory)
- mv notes.txt MyDocuments/ (Moves notes.txt into the MyDocuments directory)
- rm oldfile.txt (Deletes oldfile.txt)
- rm -r tempdir/ (Deletes the tempdir directory and its contents - be extremely careful!)
- ls *.pdf (Lists all PDF files in the current directory)
- Create a new directory called Practice.
- Inside Practice, create two empty files: fileA.txt and fileB.txt.
- Create another directory inside Practice called Backup.
- Copy fileA.txt to the Backup directory.
- Rename fileB.txt to renamed_file.txt.
- Move renamed_file.txt to the Backup directory.
- Use a wildcard to list all files in the Backup directory.
Day 4: File Permissions
Introduction:
File permissions are a crucial aspect of Linux security, controlling who can access and modify files and directories. Today, we'll learn how to understand and manage them.
Key Concepts:
- Users, Groups, and Others:
- User (Owner): The user who created the file or directory.
- Group: A collection of users.
- Others: Everyone else who is not the owner or a member of the group.
- Permission Types:
- Read (r): Allows viewing the contents of a file or listing the contents of a directory.
- Write (w): Allows modifying a file or creating/deleting files within a directory.
- Execute (x): Allows running a file as a program or accessing a directory (necessary to cd into it).
- Viewing Permissions:
- ls -l (long listing): Displays detailed information about files and directories, including permissions.
-rw-r--r-- 1 user group 1234 Jan 1 10:00 myfile.txt drwxr-xr-x 2 user group 4096 Jan 1 12:30 mydir- First character:
- -: Regular file
- d: Directory
- l: Symbolic link
- Next 9 characters: Permissions for user, group, and others (in that order).
- rwx: Read, write, and execute permissions.
- -: Permission is denied.
- Number of hard links: Usually not critical for beginners.
- Owner: The user who owns the file/directory.
- Group: The group associated with the file/directory.
- File size: In bytes.
- Last modification time: When the file/directory was last modified.
- File/directory name: The name of the file or directory.
- Changing Permissions:
- chmod (change mode): Used to modify permissions.
- Numeric Method:
- Each permission type is assigned a number:
- r = 4
- w = 2
- x = 1
- You add up the numbers for each category (user, group, other) to get a three-digit code.
- Example: chmod 755 myfile.txt
- 7 (user): rwx (4 + 2 + 1)
- 5 (group): r-x (4 + 0 + 1)
- 5 (others): r-x (4 + 0 + 1)
- Each permission type is assigned a number:
- Symbolic Method:
- Uses letters to represent categories:
- u: User
- g: Group
- o: Others
- a: All (user, group, and others)
- Uses operators:
- +: Add permission
- -: Remove permission
- =: Set permission exactly
- Example: chmod u+x myscript.sh (Adds execute permission for the user)
- Example: chmod go-r report.txt (Removes read permission for group and others)
- Example: chmod a=rw myfile.txt (Sets read and write permission for everyone, removing execute)
- Uses letters to represent categories:
- ls -l myfile.txt (View permissions of myfile.txt)
- chmod 644 document.txt (Gives the user read/write, group and others read-only)
- chmod 700 my_script.sh (Gives the user full permissions, no permissions for group and others)
- chmod u+x,g+w my_script.sh (Adds execute permission for user and write for group on my_script.sh)
- chmod a-x private_file (Removes execute permission for everyone on private_file)
Introduction:
Today, we'll learn how to use Nano, a beginner-friendly command-line text editor. While more powerful editors like Vim and Emacs exist, Nano is easier to start with and is perfect for simple editing tasks.
Key Concepts:
- What is a Text Editor? A program designed for editing plain text files. Unlike word processors (like Microsoft Word), text editors don't add formatting information, making them ideal for editing configuration files, scripts, and code.
- Why Nano?
- Easy to Learn: Nano has a simple interface and on-screen help, making it less intimidating for beginners compared to Vim or Emacs.
- Widely Available: Nano is usually included in most Linux distributions.
- Launching Nano:
- nano filename (Opens the specified file in Nano. If the file doesn't exist, it will be created.)
- nano (Opens Nano with a new, unnamed file.)
- Nano Interface:
- Top Line: Shows the Nano version, filename, and whether the file has been modified.
- Main Area: The text editing area where you can type and edit.
- Bottom Two Lines: Show available commands (shortcuts). The ^ symbol represents the Ctrl key. For example, ^X means Ctrl + X.
- Navigation:
- Arrow Keys: Move the cursor character by character or line by line.
- Ctrl + F: Move forward one character (same as right arrow).
- Ctrl + B: Move backward one character (same as left arrow).
- Ctrl + P: Move to the previous line (same as up arrow).
- Ctrl + N: Move to the next line (same as down arrow).
- Ctrl + A: Move to the beginning of the line.
- Ctrl + E: Move to the end of the line.
- Ctrl + V: Move forward one page.
- Ctrl + Y: Move backward one page.1
- Editing:
- Typing: Just start typing to insert text at the cursor position.
- Backspace: Delete the character before the cursor.
- Delete: Delete the character at the cursor.
- Ctrl + K: Cut (delete) the current line and store it in the cutbuffer.
- Ctrl + U: Uncut (paste) the contents of the cutbuffer at the cursor position.
- Ctrl + ]: Indent marked text (you can mark text by holding Shift and using the arrow keys, similar to a GUI).
- Ctrl + Shift + ]: Unindent marked text.
- Saving and Exiting:
- Ctrl + O: Write Out (save) the file. Nano will prompt you for a filename if it's a new file. Press Enter to confirm or modify the name.
- Ctrl + X: Exit Nano. If you have unsaved changes, Nano will ask if you want to save them. Press Y for yes, N for no, or Ctrl + C to cancel.
- Searching:
- Ctrl + W: Where Is (search). Type the text you want to find and press Enter.
- Alt + W: Repeat the last search (use Alt instead of Ctrl on some systems).
- Other Useful Commands:
- Ctrl + C: (When not exiting) Show the current cursor position.
- Ctrl + T: Invoke the spell checker (if installed).
- Ctrl + _: Go to a specific line and column number.
- Ctrl + G: Get Help (displays a list of all Nano commands).
- nano my_new_file.txt (Opens a new file named my_new_file.txt in Nano)
- Type some text into the file.
- Ctrl + O (Save the file. Press Enter to confirm the filename.)
- Ctrl + X (Exit Nano)
- nano my_new_file.txt (Reopen the file)
- Use the arrow keys to move around.
- Practice cutting and pasting lines with Ctrl + K and Ctrl + U.
- Ctrl + W (Search for a word in the file)
- Ctrl + X (Exit Nano)
- Create a new text file called my_notes.txt using Nano.
- Type a few lines of text into the file (e.g., a short to-do list or some notes).
- Practice navigating and editing the text using the commands you learned.
- Save the file and exit Nano.
- Reopen the file in Nano and make some more changes.
- Save the changes and exit.
- Verify that your changes were saved by using cat or less to view the file from the command line.
Day 6: Introduction to User and Group Management
Introduction:
Today, we'll cover the basics of user and group management on Linux. Understanding these concepts is essential for system security and controlling access to resources.
Key Concepts:
- Users: Each person (or service) that interacts with a Linux system has a user account.
- Username: A unique name identifying the user (e.g., john, sarah, webserver).
- User ID (UID): A unique numerical ID associated with each user.
- Home Directory: Each user typically has a home directory where their personal files are stored (usually /home/username).
- Root User: The administrator account with complete control over the system (UID 0). Use with extreme caution!
- Groups: Users can be organized into groups, making it easier to manage permissions for multiple users at once.
- Group Name: A unique name for the group (e.g., developers, admins, students).
- Group ID (GID): A unique numerical ID for each group.
- Primary Group: Each user has a primary group, usually created automatically when the user account is created.
- Supplementary Groups: Users can belong to multiple supplementary groups.
- /etc/passwd File: Stores user account information.
- Each line represents a user.
- Fields are separated by colons (.
- Example: john:x:1001:1001:John Doe:/home/john:/bin/bash
- john: Username
- x: Placeholder for the encrypted password (stored in /etc/shadow)
- 1001: UID
- 1001: GID (primary group)
- John Doe: Full name (or a comment field)
- /home/john: Home directory
- /bin/bash: Login shell
- /etc/shadow File: Stores secure user account information, including encrypted passwords.
- Only accessible by the root user.
- /etc/group File: Stores group information.
- Each line represents a group.
- Fields are separated by colons (.
- Example: developers:x:2001:john,sarah
- developers: Group name
- x: Placeholder for the group password (rarely used)
- 2001: GID
- john,sarah: List of users in the group
- id: Displays the current user's UID, GID, and groups.
- id (Shows information for the current user)
- id username (Shows information for the specified user)
- whoami: Displays the current user's username.
- groups: Displays the groups the current user belongs to.
- groups (Shows groups for the current user)
- groups username (Shows groups for the specified user)
- su (switch user): Allows you to temporarily become another user.
- su - username (Switch to the specified user and load their environment variables, including changing to their home directory)
- su (by itself, it usually defaults to switching to the root user, requiring the root password)
- sudo (superuser do): Allows you to run commands with the privileges of another user (usually the root user).
- sudo command (Runs command as root, prompting you for your own password)
- Configuration: The /etc/sudoers file controls who can use sudo and what commands they can run. Use extreme caution when editing this file; use sudo visudo which provides a safer way to edit it.
- useradd: Creates a new user account.
- sudo useradd -m username (Creates a user with a home directory. The -m option creates the home directory.)
- sudo useradd -s /bin/bash username (Creates a user with a specific shell.)
- usermod: Modifies an existing user account.
- sudo usermod -a -G groupname username (Adds a user to a supplementary group. The -a option is for appending to the group list, -G is for specifying supplementary groups).
- userdel: Deletes a user account.
- sudo userdel username (Deletes the user)
- sudo userdel -r username (Deletes the user and their home directory)
- groupadd: Creates a new group.
- sudo groupadd groupname
- groupmod: Modifies an existing group.
- sudo groupmod -n newgroupname oldgroupname (Renames a group)
- groupdel: Deletes a group.
- sudo groupdel groupname
- passwd: Changes a user's password.
- passwd (Changes your own password)
- sudo passwd username (Changes the password for the specified user - requires root privileges)
- id (Displays your UID, GID, and groups)
- whoami (Displays your username)
- groups sarah (Displays the groups that the user sarah belongs to)
- su - john (Switches to user john and loads their environment)
- sudo apt update (Runs the apt update command with root privileges)
- sudo useradd -m jdoe (Creates a new user named jdoe with a home directory)
- sudo usermod -a -G developers jdoe (Adds user jdoe to the developers group)
- sudo passwd jdoe (Sets a password for user jdoe)
- Use id and groups to find out information about your current user.
- Try whoami to see your username.
- If you have root privileges (or use sudo), create a new user account using useradd.
- Set a password for the new user using passwd.
- Experiment with su to switch to the new user (and then use exit to return to your original user).
- (Caution): Avoid modifying or deleting existing users or groups unless you are sure you understand the consequences.
Day 7: Essential Utilities and Help System
Introduction:
Today, we'll explore some essential command-line utilities and learn how to use the Linux help system to find information about commands.
Key Concepts:
- man (manual pages): The primary way to get help on commands.
- man command (Displays the manual page for the specified command)
- Navigation:
- Spacebar: Move down one page.
- b: Move up one page.
- q: Quit.
- /searchterm (forward slash): Search for searchterm within the man page.
- n: Go to the next search result.
- N: Go to the previous search result.
- Sections: Man pages are divided into sections (e.g., 1 for user commands, 8 for system administration commands). You can sometimes specify the section number: man 1 printf
- grep (global regular expression print): Searches for patterns in files.
- grep pattern file (Searches for pattern in file)
- grep -i pattern file (Case-insensitive search)
- grep -r pattern directory (Recursive search through a directory)
- grep -v pattern file (Inverted search - displays lines that don't match the pattern)
- grep -n pattern file (Displays line numbers with matching lines)
- grep -c pattern file (Counts the number of matching lines)
- find: Locates files based on various criteria.
- find directory -name filename (Finds files named filename within directory)
- find directory -type f (Finds only regular files within directory)
- find directory -type d (Finds only directories within directory)
- find directory -mtime -7 (Finds files modified within the last 7 days)
- find . -name "*.txt" (Finds all files ending with .txt in the current directory and its subdirectories)
- date: Displays or sets the system date and time.
- date (Displays the current date and time)
- date +%Y-%m-%d (Displays the date in a specific format)
- sudo date -s "2024-01-15 10:30:00" (Sets the system date and time - requires root privileges)
- cal (calendar): Displays a calendar.
- cal (Displays the calendar for the current month)
- cal 12 2024 (Displays the calendar for December 2024)
- man ls (Displays the manual page for the ls command)
- man 5 passwd (Displays the manual page for the format of the /etc/passwd file, which is in section 5 of the manual)
- grep error /var/log/syslog (Searches for lines containing "error" in the /var/log/syslog file)
- grep -i warning /var/log/messages (Performs a case-insensitive search for "warning" in /var/log/messages)
- find /home -name "*.jpg" (Finds all files ending with .jpg in the /home directory)
- find . -type f -mtime +30 (Finds regular files in the current directory modified more than 30 days ago)
- date (Displays the current date and time)
- cal -y (Displays a calendar for the entire current year)
- Use man to read the manual page for the grep command.
- Use man to find out what the -i option does for the ls command.
- Use grep to search for a specific word (e.g., your username) in a file like /etc/passwd (be cautious about modifying system files!).
- Use find to locate all files with a specific extension (e.g., .txt) in your home directory.
- Experiment with the date and cal commands.
- --help: Many commands also have a --help option that provides a brief summary of usage and options (e.g., ls --help).
- apropos or man -k: If you don't know the exact command name, you can use apropos keyword or man -k keyword to search for commands related to a keyword (e.g., apropos copy or man -k copy).
- Online Resources: There are many online resources, tutorials, and forums where you can find help with Linux commands.
Alright, let's move on to Days 8-15 of our "Learn Linux in 30 Days" series! This week we'll dive into system configuration, covering networking, package management, and more.
Days 8-15: System Configuration
Day 8: Networking Basics
Introduction:
Today, we'll explore fundamental networking concepts and commands in Linux. Understanding networking is crucial for connecting your system to the internet or a local network.
Key Concepts:
- IP Addresses: Unique numerical addresses assigned to devices on a network.
- IPv4: The most common type, consisting of four sets of numbers separated by periods (e.g., 192.168.1.100).
- IPv6: The newer version, using a longer format (e.g., 2001:0db8:85a3:0000:0000:8a2e:0370:7334).
- Network Interfaces: Hardware or software components that connect your computer to a network (e.g., eth0 for a wired Ethernet connection, wlan0 for a wireless connection).
- Subnet Mask: Defines which part of an IP address identifies the network and which part identifies the host within that network.
- Gateway: The device (usually a router) that forwards traffic from your local network to other networks (like the internet).
- DNS (Domain Name System): Translates human-readable domain names (e.g., www.google.com) into IP addresses.
- DHCP (Dynamic Host Configuration Protocol): Automatically assigns IP addresses and other network settings to devices on a network.
- ip addr (or ip a): Displays network interface information, including IP addresses.
- ip addr show eth0 (Shows information for the eth0 interface)
- ip link: Displays the status of network interfaces (up or down).
- ip link show (Lists all interfaces and their status)
- sudo ip link set eth0 up (Brings the eth0 interface up)
- sudo ip link set eth0 down (Brings the eth0 interface down)
- ip route (or ip r): Displays the routing table (which determines where network traffic is sent).
- ip route show (Shows the routing table)
- ping: Sends ICMP Echo Request packets to a host to test connectivity.
- ping google.com (Sends ping requests to google.com)
- ping 192.168.1.1 (Sends ping requests to the IP address 192.168.1.1)
- ping -c 4 google.com (Sends only 4 ping requests)
- traceroute: Shows the path that packets take to reach a destination.
- traceroute google.com
- nslookup: Queries DNS servers to find the IP address associated with a domain name.
- nslookup google.com
- dig: A more advanced tool for querying DNS servers.
- dig google.com
- hostname: Displays or sets the system's hostname.
- hostname (Displays the hostname)
- sudo hostname newhostname (Sets the hostname - requires root privileges)
- ip addr (Displays IP addresses and other information for all network interfaces)
- ip route show (Displays the routing table, showing the default gateway)
- ping -c 4 8.8.8.8 (Sends 4 ping requests to Google's public DNS server)
- traceroute facebook.com (Traces the route to facebook.com)
- nslookup example.com (Finds the IP address for example.com)
- Use ip addr to find the IP address of your computer.
- Use ip route to identify your default gateway.
- Use ping to test your internet connectivity.
- Use nslookup or dig to find the IP address of a website.
- If you're comfortable, use ip link to experiment with bringing a network interface up or down (be cautious, as this could affect your network connectivity).
Day 9: Introduction to Package Management (APT)
Introduction:
Today, we'll learn about package management on Debian-based systems (like Ubuntu and Linux Mint) using the APT (Advanced Package Tool) system. Package managers simplify software installation, updates, and removal.
Key Concepts:
- Package: A compressed archive containing all the files needed for a software application, along with information about the software (dependencies, version, etc.).
- Repository: A server or a collection of servers that store packages.
- Package Manager: A tool that handles the installation, removal, updating, and management of packages.
- APT (Advanced Package Tool): The package management system used by Debian and its derivatives.
- apt vs. apt-get: apt is a newer, more user-friendly command-line interface that combines the functionality of apt-get, apt-cache, and other related tools. While apt-get is still widely used, apt is generally recommended for interactive use.
- sudo apt update: Downloads the latest package lists from the repositories. Always run this before upgrading or installing new packages.
- sudo apt upgrade: Upgrades all installed packages to their latest versions.
- sudo apt install package_name: Installs a package.
- sudo apt install vlc (Installs the VLC media player)
- sudo apt remove package_name: Removes a package.
- sudo apt remove vlc
- sudo apt purge package_name: Removes a package and its configuration files.
- sudo apt purge vlc
- sudo apt autoremove: Removes packages that were automatically installed as dependencies but are no longer needed.
- apt search package_name: Searches for packages.
- apt search video editor
- apt show package_name: Shows detailed information about a package.
- apt show vlc
- apt list --installed: Lists all installed packages.
- apt list --upgradable: Lists packages that have upgrades available.
- sudo apt update (Updates the package lists)
- sudo apt upgrade (Upgrades all installed packages)
- sudo apt install gimp (Installs the GIMP image editor)
- sudo apt remove firefox (Removes the Firefox web browser)
- apt search music player (Searches for music player packages)
- Update your package lists using sudo apt update.
- Upgrade any outdated packages using sudo apt upgrade.
- Search for a package you're interested in (e.g., a game, a text editor) using apt search.
- Install the package using sudo apt install.
- If you want to remove the package later, use sudo apt remove.
Day 10: Introduction to Package Management (DNF/YUM)
Introduction:
Today, we'll explore package management on Red Hat-based systems (like Fedora, CentOS, and Red Hat Enterprise Linux) using DNF and YUM. These tools are similar to APT but have some differences in commands and usage.
Key Concepts:
- RPM (Red Hat Package Manager): The underlying packaging format used by these distributions.
- YUM (Yellowdog Updater, Modified): The older package manager, still used in CentOS 7 and earlier.
- DNF (Dandified YUM): The newer package manager, used in Fedora and CentOS 8 and later. It's designed to be faster and more efficient than YUM.
- Repository: A server or a collection of servers that store RPM packages.
- sudo dnf update: Updates the package lists and upgrades all installed packages. (You can also use sudo dnf upgrade for the same result.)
- sudo dnf install package_name: Installs a package.
- sudo dnf install vlc
- sudo dnf remove package_name: Removes a package.
- sudo dnf remove vlc
- sudo dnf autoremove: Removes packages that are no longer needed.
- dnf search package_name: Searches for packages.
- dnf search video editor
- dnf info package_name: Shows detailed information about a package.
- dnf info vlc
- dnf list installed: Lists all installed packages.
- dnf list available: Lists all available packages.
- dnf repoquery -l package_name: Lists the files that would be installed by a package.
- sudo dnf provides "*/command_name": Find out what package provides a specific command.
- sudo dnf distro-sync: Synchronizes installed packages to the latest versions available in enabled repositories. (Can be used for major upgrades)
- sudo yum update: Updates the package lists and upgrades all installed packages.
- sudo yum install package_name: Installs a package.
- sudo yum install vlc
- sudo yum remove package_name: Removes a package.
- sudo yum remove vlc
- sudo yum autoremove: Removes packages that are no longer needed.
- yum search package_name: Searches for packages.
- yum search video editor
- yum info package_name: Shows detailed information about a package.
- yum info vlc
- yum list installed: Lists all installed packages.
- yum list available: Lists all available packages.
- sudo dnf update (Updates the package lists and upgrades packages on Fedora/CentOS 8+)
- sudo yum update (Updates the package lists and upgrades packages on CentOS 7 or earlier)
- sudo dnf install gimp (Installs the GIMP image editor on Fedora/CentOS 8+)
- sudo yum install gimp (Installs the GIMP image editor on CentOS 7 or earlier)
- sudo dnf remove firefox (Removes Firefox on Fedora/CentOS 8+)
- Update your package lists and upgrade any outdated packages.
- Search for a package you're interested in.
- Install the package.
- If you want to remove the package later, use the appropriate remove command.
Day 11: Managing Services
Introduction:
Today, we'll learn about managing services (also called daemons) in Linux using systemctl, the command-line interface for the systemd system and service manager.
Key Concepts:
- Service/Daemon: A program that runs in the background, performing tasks or providing functionality to other programs. Examples include web servers (Apache, Nginx), database servers (MySQL, PostgreSQL), and SSH.
- systemd: The most widely used init system and service manager in modern Linux distributions. It's responsible for starting, stopping, and managing services.
- systemctl: The command-line tool used to interact with systemd.
- Unit: A resource that systemd can manage. Services are one type of unit. Other unit types include sockets, mount points, and timers.
- systemctl status service_name: Checks the status of a service.
- systemctl status sshd (Checks the status of the SSH service)
- systemctl status (Checks the status of all services)
- sudo systemctl start service_name: Starts a service.
- sudo systemctl start apache2 (Starts the Apache web server - the service name might vary slightly depending on your distribution)
- sudo systemctl stop service_name: Stops a service.
- sudo systemctl stop mysql
- sudo systemctl restart service_name: Restarts a service.
- sudo systemctl restart nginx
- sudo systemctl reload service_name: Reloads the configuration of a service without stopping it.
- sudo systemctl reload postfix
- sudo systemctl enable service_name: Enables a service to start automatically at boot time.
- sudo systemctl enable docker
- sudo systemctl disable service_name: Disables a service from starting automatically at boot time.
- sudo systemctl disable cups (Disables the printing service)
- systemctl list-units --type=service: Lists all service units.
- systemctl list-unit-files --type=service: Lists all service unit files and their status (enabled, disabled, static, etc.)
- systemctl is-active service_name: Checks if a service is currently active (running).
- systemctl is-enabled service_name: Checks if a service is enabled to start at boot.
- systemctl is-failed service_name: Checks if a service is in a failed state.
- systemctl status bluetooth (Checks the status of the Bluetooth service)
- sudo systemctl start postgresql (Starts the PostgreSQL database server)
- sudo systemctl stop firewalld (Stops the firewall service)
- sudo systemctl restart vsftpd (Restarts the FTP server)
- sudo systemctl enable httpd (Enables the Apache web server to start at boot)
- systemctl list-units --type=service --all (Lists all service units, including inactive ones)
- Use systemctl status to check the status of some common services on your system (e.g., sshd, bluetooth, cron).
- If you have a service you want to experiment with (and you understand the risks), try stopping and starting it using systemctl stop and systemctl start.
- Use systemctl enable or systemctl disable to configure whether a service should start automatically at boot.
- Use systemctl list-units to explore the services running on your system.
Day 12: Working with Processes
Introduction:
Today, we'll learn how to view and manage running processes in Linux. Understanding processes is essential for troubleshooting and monitoring your system.
Key Concepts:
- Process: An instance of a running program. Each process has a unique process ID (PID) and various attributes (memory usage, CPU time, etc.).
- Parent Process: A process that creates another process (the child process).
- Foreground Process: A process that is currently connected to your terminal. You interact with it directly.
- Background Process: A process that runs independently of your terminal. You can start a background process by appending & to the command.
- Job Control: Managing foreground and background processes (e.g., suspending, resuming, terminating).
- ps (process status): Displays information about running processes.
- ps aux (Displays all processes for all users in a detailed format)
- USER: The user who owns the process.
- PID: The process ID.
- %CPU: Percentage of CPU usage.
- %MEM: Percentage of memory usage.
- VSZ: Virtual memory size (in KB).
- RSS: Resident set size (physical memory used, in KB).
- TTY: The terminal associated with the process.
- STAT: Process state (e.g., S for sleeping, R for running, Z for zombie).
- START: Start time of the process.
- TIME: Total CPU time used by the process.
- COMMAND: The command that started the process.
- ps -ef (Another common way to view all processes with a slightly different output format)
- ps aux (Displays all processes for all users in a detailed format)
- top: Displays a dynamic, real-time view of processes, sorted by CPU usage by default.
- Navigation:
- q: Quit.
- k: Kill a process (you'll be prompted for the PID).
- r: Renice a process (change its priority).
- Shift + P: Sort by CPU usage.
- Shift + M: Sort by memory usage.
- Fields: Similar to ps, but updated in real time.
- Navigation:
- htop: An interactive process viewer, similar to top but with a more user-friendly interface (often needs to be installed separately: sudo apt install htop or sudo dnf install htop).
- Features:
- Color-coded output.
- Mouse support.
- Tree view of processes.
- Features:
Day 13: Disk Usage and Partitions
Introduction:
Today, we'll explore how to check disk usage, understand partitions, and manage disk space on your Linux system.
Key Concepts:
- Disk Partition: A logical division of a physical hard drive. Each partition can be formatted with a different file system and used independently.
- File System: A method of organizing and storing files on a storage device (e.g., ext4, XFS, Btrfs, NTFS, FAT32).
- Mount Point: A directory in the file system where a partition is mounted (made accessible). For example, the root partition is usually mounted at /, and a separate home partition might be mounted at /home.
- Inode: A data structure that stores information about a file or directory (metadata), such as permissions, timestamps, and location on the disk. Each file and directory has an inode.
- df (disk free): Displays disk space usage for mounted file systems.
- df -h (Human-readable output, showing sizes in GB, MB, etc.)
- df -i (Displays inode usage instead of disk space usage)
- df -T (Shows the file system type)
- du (disk usage): Displays disk space used by files and directories.
- du -sh directory (Summarizes the total disk usage of a directory in human-readable format)
- du -ah (Shows disk usage for all files and directories recursively, in human-readable format)
- du -sh * | sort -rh (Lists directories in the current location sorted by size, largest first)
- lsblk (list block devices): Displays information about block devices (hard drives, partitions, etc.).
- lsblk (Shows a tree-like view of devices and partitions)
- lsblk -f (Also shows file system type and mount point)
- fdisk: A powerful command-line utility for managing partitions (requires root privileges). Use with extreme caution, as incorrect usage can lead to data loss.
- sudo fdisk -l (Lists partition tables for all disks)
- sudo fdisk /dev/sda (Starts fdisk to manage partitions on the disk /dev/sda - replace with the actual device name)
- parted: Another utility for managing partitions, often considered more user-friendly than fdisk for some tasks.
- sudo parted -l (Lists partition tables)
- mkfs: Creates a file system on a partition (formats the partition). Use with extreme caution, as this will erase existing data on the partition.
- sudo mkfs.ext4 /dev/sda1 (Formats /dev/sda1 with the ext4 file system - replace with the correct partition)
- mount: Mounts a file system.
- sudo mount /dev/sda1 /mnt (Mounts /dev/sda1 at the /mnt directory - replace with the correct partition and mount point)
- umount: Unmounts a file system.
- sudo umount /mnt (Unmounts whatever is mounted at /mnt)
- df -h (Displays disk space usage in a human-readable format)
- du -sh /home/user/Documents (Shows the total size of the Documents directory)
- lsblk (Lists block devices and their partitions)
- sudo fdisk -l (Lists partition tables - be careful not to modify anything unless you're sure)
- sudo mount /dev/sdb1 /media/usb (Mounts an external USB drive - assuming it's /dev/sdb1)
- Use df -h to check your system's disk space usage.
- Use du -sh to find out which directories are taking up the most space in your home directory.
- Use lsblk to examine your system's partitions.
- (Optional, if you have a spare USB drive or are working in a safe environment): Experiment with mounting and unmounting a USB drive using mount and umount. Be very careful not to modify your system's primary partitions unless you're absolutely sure what you're doing.
Day 14: Archiving and Compression
Introduction:
Today, we'll learn how to create archives (combine multiple files and directories into one file) and how to compress files to save disk space.
Key Concepts:
- Archive: A file that contains a collection of other files and directories, along with metadata (file permissions, timestamps, etc.).
- Compression: Reducing the size of a file by using algorithms to eliminate redundancy.
- tar (tape archive): A versatile command-line utility for creating and extracting archives. Despite its name, it's commonly used for creating archives on disk, not just tape.
- Compression Utilities:
- gzip: A common compression utility that produces files with the .gz extension.
- bzip2: Another compression utility, often achieving higher compression ratios than gzip but slower. Produces files with the .bz2 extension.
- xz: A newer compression utility that generally offers the best compression ratios. Produces files with the .xz extension.
- zip: a widely used archive format that also supports compression.
- tar:
- Creating Archives:
- tar -cvf archive_name.tar file1 file2 dir1 (Creates an uncompressed archive named archive_name.tar containing file1, file2, and dir1)
- -c: Create a new archive.
- -v: Verbose mode (list the files being processed).
- -f: Specifies the archive filename.
- tar -czvf archive_name.tar.gz file1 file2 dir1 (Creates a gzip-compressed archive)
- -z: Use gzip compression.
- tar -cjvf archive_name.tar.bz2 file1 file2 dir1 (Creates a bzip2-compressed archive)
- -j: Use bzip2 compression.
- tar -cJvf archive_name.tar.xz file1 file2 dir1 (Creates an xz-compressed archive)
- -J: Use xz compression.
- tar -cvf archive_name.tar file1 file2 dir1 (Creates an uncompressed archive named archive_name.tar containing file1, file2, and dir1)
- Extracting Archives:
- tar -xvf archive_name.tar (Extracts an uncompressed archive)
- -x: Extract files from an archive.
- tar -xzvf archive_name.tar.gz (Extracts a gzip-compressed archive)
- tar -xjvf archive_name.tar.bz2 (Extracts a bzip2-compressed archive)
- tar -xJvf archive_name.tar.xz (Extracts an xz-compressed archive)
- tar -xvf archive_name.tar (Extracts an uncompressed archive)
- Listing Archive Contents:
- tar -tvf archive_name.tar (Lists the contents of an archive without extracting)
- -t: List the contents of an archive.
- tar -tvf archive_name.tar (Lists the contents of an archive without extracting)
- Creating Archives:
- gzip:
- gzip file.txt (Compresses file.txt into file.txt.gz, deleting the original file.txt)
- gzip -d file.txt.gz (Decompresses file.txt.gz back to file.txt)
- gunzip file.txt.gz (Same as gzip -d)
- bzip2:
- bzip2 file.txt (Compresses file.txt into file.txt.bz2)
- bzip2 -d file.txt.bz2 (Decompresses file.txt.bz2)
- bunzip2 file.txt.bz2 (Same as bzip2 -d)
- xz:
- xz file.txt (Compresses file.txt into file.txt.xz)
- xz -d file.txt.xz (Decompresses file.txt.xz)
- unxz file.txt.xz (Same as xz -d)
- zip and unzip:
- zip archive_name.zip file1 file2 dir1 (Creates a zip archive)
- zip -r archive_name.zip my_directory (Creates a zip archive including a directory and subdirectories)
- unzip archive_name.zip (Extracts a zip archive)
- tar -czvf my_backup.tar.gz /home/user/Documents (Creates a gzip-compressed archive of the Documents directory)
- tar -xjvf my_archive.tar.bz2 (Extracts a bzip2-compressed archive)
- gzip my_large_file.log (Compresses my_large_file.log into my_large_file.log.gz)
- gunzip my_report.txt.gz (Decompresses my_report.txt.gz)
- zip my_project.zip main.c data.txt (Creates a zip archive containing main.c and data.txt)
- unzip my_backup.zip (Extracts the contents of my_backup.zip)
- Create a directory with a few files inside it.
- Use tar to create an uncompressed archive of the directory.
- Create a compressed archive of the same directory using tar with gzip, bzip2, and xz compression.
- Compare the sizes of the resulting archives.
- Extract one of the compressed archives to a different location.
- Experiment with compressing and decompressing individual files using gzip, bzip2, and xz.
- Experiment with creating and extracting a zip archive using zip and unzip
Day 15: Introduction to SSH (Secure Shell)
Introduction:
Today, we'll introduce SSH, a secure protocol for remote login and command execution. SSH is essential for managing servers and accessing remote systems securely.
Key Concepts:
- SSH (Secure Shell): A cryptographic network protocol that provides a secure channel over an unsecured network. It encrypts all traffic between the client and the server, protecting data from eavesdropping and tampering.
- SSH Client: The program you use to connect to a remote server (e.g., the ssh command on Linux, PuTTY on Windows).
- SSH Server: The program running on the remote server that listens for incoming SSH connections (usually sshd).
- Authentication: SSH uses various methods to verify the identity of the user connecting to the server:
- Password Authentication: The most common method, where you enter your username and password.
- Public Key Authentication: A more secure method that uses a pair of cryptographic keys (a public key and a private key). The public key is placed on the server, and the private key is kept on the client.
- Port 22: The default port used for SSH connections.
- ssh: The SSH client command.
- ssh username@remote_host (Connects to remote_host as username)
- Example: ssh john@192.168.1.100 (Connects to the server with IP address 192.168.1.100 as user john)
- ssh -p port_number username@remote_host (Connects to a non-standard port)
- Example: ssh -p 2222 john@example.com
- ssh user@remote_host command (Runs a command on the remote host and then exits)
- Example: ssh ubuntu@my_server "df -h" (Runs df -h on the server my_server as user ubuntu)
- ssh username@remote_host (Connects to remote_host as username)
- Connecting to a Remote Server:
- Open your terminal and use the ssh command:
- ssh username@remote_host
- If it's your first time connecting to the server, you'll be asked to verify the server's fingerprint. This is a security measure to ensure you're connecting to the right server. Type yes to continue.
- Enter your password when prompted.
- Open your terminal and use the ssh command:
- Running Commands on the Remote Server:
- Once connected, you'll be in the remote server's shell. You can now run commands as if you were sitting in front of that machine.
- Example: ls, pwd, whoami, top, etc.
- Exiting the Remote Session:
- Type exit or press Ctrl + D to close the SSH connection.
- Generate a Key Pair (on your local machine):
- ssh-keygen -t rsa (Creates an RSA key pair. You can use other key types like -t ed25519)
- You'll be asked where to save the keys (press Enter to accept the default location, usually ~/.ssh/id_rsa for the private key and ~/.ssh/id_rsa.pub for the public key).
- You can optionally set a passphrase for added security.
- Copy the Public Key to the Remote Server:
- Use the ssh-copy-id command:
- ssh-copy-id username@remote_host (This automatically copies your public key to the correct location on the server)
- Manual Method (if ssh-copy-id is not available):
- cat ~/.ssh/id_rsa.pub | ssh username@remote_host "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
- This command copies the contents of your public key file (id_rsa.pub) to the authorized_keys file on the remote server, creating the ~/.ssh directory if it doesn't exist.
- cat ~/.ssh/id_rsa.pub | ssh username@remote_host "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
- Use the ssh-copy-id command:
- Connect Using Your Key:
- Now you should be able to connect without a password:
- ssh username@remote_host
- Now you should be able to connect without a password:
- ssh student@10.0.0.168 (Connects to the server at 10.0.0.168 as the user student)
- ssh -p 2200 admin@webserver.example.com (Connects to webserver.example.com on port 2200 as admin)
- ssh-keygen -t rsa (Generates an RSA key pair)
- ssh-copy-id user@remote_machine (Copies your public key to remote_machine)
- If you have access to a remote server (or a virtual machine with SSH enabled), try connecting to it using ssh with password authentication.
- Practice running a few basic commands on the remote server.
- Set up public key authentication for a more secure and convenient login.
- (Optional): If you have two Linux virtual machines, you can practice SSHing between them.
- Strong Passwords: If you're using password authentication, make sure to use very strong, unique passwords.
- Key Management: Protect your private key file. Don't share it with anyone. If it's compromised, anyone with the key can access your server.
- Firewall: Make sure your server has a firewall configured to only allow SSH connections from trusted sources if possible.
- Disable Root Login: For increased security, it's often recommended to disable direct root login over SSH and instead use a regular user account with sudo privileges.
- Keep Software Updated: Regularly update your SSH client and server software to patch any security vulnerabilities.