🐧
LINUX
Linux Fundamentals
Linux Structure
History
Many events led up to creating the first Linux kernel and, ultimately, the Linux
operating system (OS), starting with the Unix operating system's release by Ken
Thompson and Dennis Ritchie (whom both worked for AT&T at the time) in 1970.
The Berkeley Software Distribution (BSD) was released in 1977, but since it
contained the Unix code owned by AT&T, a resulting lawsuit limited the
development of BSD. Richard Stallman started the GNU project in 1983. His goal
was to create a free Unix-like operating system, and part of his work resulted in
the GNU General Public License (GPL) being created. Projects by others over the
years failed to result in a working, free kernel that would become widely adopted
until the creation of the Linux kernel.
At first, Linux was a personal project started in 1991 by a Finnish student named
Linus Torvalds. His goal was to create a new, free operating system kernel. Over
the years, the Linux kernel has gone from a small number of files written in C
LINUX 1
under licensing that prohibited commercial distribution to the latest version with
over 23 million source code lines (comments excluded), licensed under the GNU
General Public License v2.
Linux is available in over 600 distributions (or an operating system based on the
Linux kernel and supporting software and libraries). Some of the most popular and
well-known being Ubuntu, Debian, Fedora, OpenSUSE, elementary, Manjaro,
Gentoo Linux, RedHat, and Linux Mint.
Linux is generally considered more secure than other operating systems, and
while it has had many kernel vulnerabilities in the past, it is becoming less and less
frequent. It is less susceptible to malware than Windows operating systems and is
very frequently updated. Linux is also very stable and generally affords very high
performance to the end-user. However, it can be more difficult for beginners and
does not have as many hardware drivers as Windows.
Since Linux is free and open-source, the source code can be modified and
distributed commercially or non-commercially by anyone. Linux-based operating
systems run on servers, mainframes, desktops, embedded systems such as
routers, televisions, video game consoles, and more. The overall Android
operating system that runs on smartphones and tablets is based on the Linux
kernel, and because of this, Linux is the most widely installed operating system.
Linux is an operating system like Windows, iOS, Android, or macOS. An OS is
software that manages all of the hardware resources associated with our
computer. That means that an OS manages the whole communication between
software and hardware. Also, there exist many different distributions (distro). It is
like a version of Windows operating systems.
With the interactive instances, we get access to the Pwnbox, a customized version
of Parrot OS. This will be the primary OS we will work with through the modules.
Parrot OS is a Debian-based Linux distribution that focuses on security, privacy,
and development.
Philosophy
Linux follows five core principles:
Principle Description
LINUX 2
All configuration files for the various services running on
Everything is a file the Linux operating system are stored in one or more text
files.
Small, single-purpose Linux offers many different tools that we will work with,
programs which can be combined to work together.
Ability to chain programs The integration and combination of different tools enable us
together to perform complex to carry out many large and complex tasks, such as
tasks
processing or filtering specific data results.
Linux is designed to work mainly with the shell (or
Avoid captive user
interfaces terminal), which gives the user greater control over the
operating system.
Configuration data stored An example of such a file is the /etc/passwd file, which
in a text file stores all users registered on the system.
Components
Component Description
A piece of code that runs to guide the booting process to start the
Bootloader
operating system. Parrot Linux uses the GRUB Bootloader.
The kernel is the main component of an operating system. It manages
OS Kernel
the resources for system's I/O devices at the hardware level.
Background services are called "daemons" in Linux. Their purpose is to
ensure that key functions such as scheduling, printing, and multimedia
Daemons
are working correctly. These small programs load after we booted or log
into the computer.
The operating system shell or the command language interpreter (also
known as the command line) is the interface between the OS and the
OS Shell
user. This interface allows the user to tell the OS what to do. The most
commonly used shells are Bash, Tcsh/Csh, Ksh, Zsh, and Fish.
This provides a graphical sub-system (server) called "X" or "X-server"
Graphics
server that allows graphical programs to run locally or remotely on the X-
windowing system.
Window Also known as a graphical user interface (GUI). There are many options,
Manager
including GNOME, KDE, MATE, Unity, and Cinnamon. A desktop
environment usually has several applications, including file and web
LINUX 3
browsers. These allow the user to access and manage the essential and
frequently accessed features and services of an operating system.
Applications or utilities are programs that perform particular functions for
Utilities
the user or another program.
Linux Architecture
The Linux operating system can be broken down into layers:
Layer Description
Peripheral devices such as the system's RAM, hard drive, CPU, and
Hardware
others.
The core of the Linux operating system whose function is to virtualize
and control common computer hardware resources like CPU, allocated
Kernel memory, accessed data, and others. The kernel gives each process its
own virtual resources and prevents/mitigates conflicts between different
processes.
A command-line interface (CLI), also known as a shell that a user can
Shell
enter commands into to execute the kernel's functions.
System
Utility Makes available to the user all of the operating system's functionality.
File System Hierarchy
The Linux operating system is structured in a tree-like hierarchy and is
documented in the Filesystem Hierarchy Standard (FHS). Linux is structured with
the following standard top-level directories:
LINUX 4
Path Description
The top-level directory is the root filesystem and contains all of the files
required to boot the operating system before other filesystems are
/ mounted, as well as the files required to boot the other filesystems. After
boot, all of the other filesystems are mounted at standard mount points as
subdirectories of the root.
/bin Contains essential command binaries.
/boot
Consists of the static bootloader, kernel executable, and files required to
boot the Linux OS.
/dev
Contains device files to facilitate access to every hardware device
attached to the system.
/etc
Local system configuration files. Configuration files for installed
applications may be saved here as well.
/home Each user on the system has a subdirectory here for storage.
/lib Shared library files that are required for system boot.
/media External removable media devices such as USB drives are mounted here.
/mnt Temporary mount point for regular filesystems.
LINUX 5
/opt Optional files such as third-party tools can be saved here.
/root The home directory for the root user.
This directory contains executables used for system administration
/sbin
(binary system files).
The operating system and many programs use this directory to store
/tmp temporary files. This directory is generally cleared upon system boot and
may be deleted at other times without any warning.
/usr Contains executables, libraries, man files, etc.
This directory contains variable data files such as log files, email in-
/var
boxes, web application related files, cron files, and more.
+10 Streak pts Mark Complete & NextNext
Cheat Sheet
Table of Contents
Introduction
Linux StructureLinux DistributionsIntroduction to Shell
The Shell
Prompt DescriptionGetting Help System Information
Workflow
Navigation Working with Files and Directories Editing Files Find Files and
Directories File Descriptors and Redirections Filter Contents Regular
Expressions Permission Management
System Management
User Management Package Management Service and Process
Management Task Scheduling Network Services Working with Web
Services Backup and Restore File System Management Containerization
Linux Networking
Network ConfigurationRemote Desktop Protocols in Linux
Linux Hardening
Linux Security Firewall Setup System Logs and Monitoring
Linux Distributions vs Solaris
Solaris
Tips & Tricks
Shortcuts
LINUX 6
https://academy.hackthebox.com/module/18/section/94
LINUX 7
🔐 Terminal Notes (windows, linux)
terminal notes (CMD):
popular helpful commands: (directory means path that contain files with
different type(parent file))
'!' means that the commands work in Linux also
1-! Pwd (print working directory) ---> Show you the directory which
you are in (current working directory)
2-! ls (list) ---> show you all files in that directory (el files ely mawgoda
fel directory dh eh bzbt)
3-! cd(change directory) directory(file) name ---> will go to another
directory (NOTE: make sure you maintain capital letters same as the
directory written because capital letters matter to let terminal be able to
change the directory!!!)
4-! cd.. ---> going back to the previous directory*****(NOTE: in linux
the command is cd .. its required to apply space after cd in windows you
can write cd and after that .. without space but in linux it hits diffrent)
5-! clear or cls or (ctrl + l)---> remove everything to get a clear page
6- mkdir FILENAME ---> create a new file in the directory you are in
7- dir ----> show you the directories and files in the location you are in
and you can differentiate between directories and files by checking if
there is 'dir' beside the name then this name is directory if not then its a
normal file
NOTE: to delete a directory you have to be outside it to be able to delete
it
8- Remove-Item -Path "C:\Users\YourUsername\Documents\TestFolder"
-Recurse -Force ---> to remove directory
//DO NOT FORGET the photo taken for these commands if you want to
look at it you will find it in SCREENSHOT//
** you can use the terminal from VScode and by the commands nothing
change**
9- IN LINUX '$' indicates that the prompt is user prompt, while '#'
indicates that its a route user administrator (route user prompt)
10- IN LINUX if keep coming back you will reach a point you have a '/'
only without any directory which is the root of the file system which is
LINUX 8
the end and you can't come back further
11- LINUX COMMAND: whoami ---> will tell you your username (make
sure when you write the command that there is no space between them
to work)
// EVERYTHING IN LINUX treated as a file the ip-address is a file even
the commands we write are files so every single property or anything is
file in Linux literarily EVERYTHING//
12- LINUX COMMAND: cat (concatenate) ---> show the command
binary which tell the computer what to do (its normal to not understand
any thing from it because its mainly for computers to understand not
people)
13- LINUX COMMAND:(sudo)cp (copy) [how to write it] cp 'the file you
want to copy' 'the file you want to paste in it'(this file can be a new one
not a must to paste in an existing file just write the name of the new file
and will paste in it normally)---> it copies the binary (the function) of
the command or whatever it is it copies its binary and paste it to another
file to do its same functionality
IMPORTANT NOTE: some commands need to have a permission to be
applied it can't be applied directly TO HAVE THIS PERMISSION: sudo cp
'the file you want to copy' 'the file you want to paste in it' what is
different is to write 'sudo' before the command pretending to be the
admin user for this command to give permission for the command to
work
14- LINUX COMMAND:(sudo) rm(remove) ---> it removes files which
can remove anything because everything in Linux is file, BUT you have
to use 'sudo' command before 'rm' to give permission for remove
command to work because delete command need permission to work
also
15 - IN LINUX: we have a 'bin' directory which contain all binary files for
commands and anything have a binary file will be found in the binary
directory
16 - IN LINUX: we have 'sbin'(super bin) directory which has a special
commands that only administrator would use to administrate the system
17- IN LINUX COMMAND:(sudo) adduser ---> add user to the system
and since this is a special command for administrators only we have to
LINUX 9
use 'sudo' to get the permission to use 'adduser' command
18- IN LINUX: to go to user directory you will write cd usr NOT cd user to
be able to understand and change the directory
19- we have 'bin' and 'sbin' for a user and a root and both exists and
work properly without any conflict but actually user has more commands
in 'bin' and 'sbin' that the root. TO BE ABLE TO KNOW WHICH 'bin' and
'sbin' we use for user or root we will use NEW COMMAND: which --->
tell you which path or direction you use if it the root or the user and to
use it write which whatever file you want to know its path EX: which ls --
-> /usr/bin/ls ---> so it uses the 'bin' of the user directory
20- IN LINUX: local directory store binary commands that you might
create
21- IN LINUX: lib directory store binary commands that you might share
(sharing commands)
22- IN LINUX: boot directory files your system need to boot
23- IN LINUX: var directory contain log files and also web application
related files, further details later
24- IN LINUX: tmp directory temporarily files (files go away when
system reboot)
25- IN LINUX: lib directory more shared library files, especially things
your system needs to boot
26- IN LINUX: home directory place where all users of your system live
27- IN LINUX: dev(devices) directory where files of devices found as
printer or drivers because everything in Linux is file
28- IN LINUX: in the dev directory you will find types as vda and vda1
these are the hard disks or more precisely virtual disks you can find
them as sda and sda1 and these also represent the hard drive same as
vda and vda1
29- IN LINUX: etc(etcetera) directory where network files and
configurations found in
30- IN LINUX: media and mnt directory both do the same thing they
mount drives as if insert a usb flash drive it will be mounted to media
directly as file(stored in media directory), mnt directory work the same
way but you might mount files manually. SO THE MAIN DIFFRENCE
BETWEEN media AND mnt is files mounted automatically in media but in
LINUX 10
mnt you mount files manually using commands to manual a file to mnt
//NOTTTTTTEEEE: if you stuck to a long binary file that doesn't come to
an end or an infinite looping or anything doesn't stop and continue to
work and you don't know when it will stop use: (ctrl + c) to stop it
LINUX 11