Basics of OS and Linux
Operating System
What is an OS?
Operating Systems is a system software that acts as an interface
between the software and different parts of the computer or the computer
hardware.
It is designed in such a way that it can manage the overall resources and
operations of the computer.
It controls and monitors the execution of all other programs that reside in
the computer.
There are several types of operating systems, including single-user, multi-
user, and distributed systems.
Some of the most popular operating systems in use today are Microsoft
Windows, Apple mac OS, and Linux.
It performs all the basic tasks like file management, memory
management, process management, handling input and output, and
controlling peripheral devices such as disk drives and printers.
The primary functions of an operating system include:
Resource management: The operating system manages and
allocates memory, CPU time, and other hardware resources among
the various programs and processes running on the computer.
Process management: The operating system is responsible for
starting, stopping, and managing processes and programs. It also
controls the scheduling of processes and allocates resources to them.
Threads as lightweight processes.
Memory management: The operating system manages the
computer’s primary memory and provides mechanisms for optimising
memory usage.
Security: The operating system provides a secure environment for
the user, applications, and data by implementing security policies and
mechanisms such as access controls and encryption.
Basics of OS and Linux 1
File management: The operating system is responsible for
organising and managing the file system, including the creation,
deletion, and manipulation of files and directories.
Kernel & Kernel Space VS User Space
In computing, a system call is the programmatic way in which a computer
program requests a service from the operating system on which it is
executed.
The kernel performs its tasks, such as running processes, managing
hardware devices such as the hard disk, and handling interrupts, in this
protected kernel space. In contrast, application programs such as
browsers, word processors, or audio or video players use a separate area
of memory, user space.
It is through a system call an application invokes services of a kernel,
which in that case kernel executes the desired sys call with kernel
privileges.
File System
A file system is a method an operating system uses to store, organise,
and manage files and directories on a storage device.
Some common types of file systems include:
Basics of OS and Linux 2
FAT (File Allocation Table): An older file system used by older
versions of Windows and other operating systems.
NTFS (New Technology File System): A modern file system used by
Windows. It supports features such as file and folder permissions,
compression, and encryption.
ext (Extended File System): A file system commonly used on Linux
and Unix-based operating systems.
HFS (Hierarchical File System): A file system used by macOS.
APFS (Apple File System): A new file system introduced by Apple for
their Macs and iOS devices.
Process and Thread
A process is basically a program in execution.
To put it in simple terms, we write our computer programs in a text file and
when we execute this program, it becomes a process which performs all
the tasks mentioned in the program.
Thread is the segment of a process which means a process can have
multiple threads and these multiple threads are contained within a
process.
A thread has three states: Running, Ready, and Blocked.
The thread takes less time to terminate as compared to the process but
unlike the process, threads do not isolate.
Command - ps
Linux
Basics of OS and Linux 3
History
Check Wiki
Distributions of Linux and why?
There are numerous distributions of Linux, but broadly, they can be classified
into two distributions, viz. Debian and Red Hat Linux. Most of them follow
rolling-release model, which allows repeated updates.
All Linux Distributions have the same Linux kernel, however the applications,
services, like desktop environment which comes installed with it differs.
Debian
Ubuntu, Kali Linux
dpkg is the package manager for the applications packaged as .deb
packages.
apt-get is the frontend for installing deb packages from repository
archive.
On Ubuntu and all other Debian based distributions, the apt software
repositories are defined in the /etc/apt/sources.list file or in separate
files under the /etc/apt/sources.list.d/
Red Hat Linux
.rpm is the package format, and rpm is the package manager.
It is paid, for the additional technical support the red-hat team
provides to corps.
The free version of it is, CentOS.
Arch Linux
It has its own independent package distribution, .arch , and aur as
it’s package manager.
GNOME
GNOME (GNU Network Object Model Environment) is a graphical user
interface (GUI) and set of computer desktop applications for users of the
Linux operating system.
Linux VS Windows
Basics of OS and Linux 4
Linux is an open-source operating system, whereas Microsoft is a
commercial operating system.
Linux facilitates the users to have access to the source code of the
operating system and authorises them to make amendments as per their
choices. On the other hand, Windows users don’t have such privileges.
In terms of speed, Linux runs faster than the Windows operating system,
especially on moderately powerful systems, while the Windows operating
system starts becoming slower with time.
Windows collects data regularly to enhance the consumer experience,
while Linux refrains from doing so.
In the reliability ratio, Linux is far ahead of Windows
In the case of gaming, Windows is on the higher side than Linux, as most
developers intended to create games for Windows only.
Linux is considered a highly secure system, and bugs and vulnerabilities
can be fixed easily due to its open-source platform, while it is not the case
in terms of Windows.
Kernel
Commands
strace → to trace all syscalls a program makes
walkthrough through the linux kernel source code.
Instead, the Linux kernel is monolithic, although it is also modular, for it
can insert and remove loadable kernel modules at runtime.
Basics of OS and Linux 5
File System - Linux VS Windows
W: Files are stored in directories/folders on different data drives like C: D: E:.
L: Files are ordered in a tree structure starting with the root directory, further
branched out to various other sub-directories.
L: Everything is treated like a file or a process. Directories are files, files are
files, and externally connected devices (such as Printer, mouse, keyboard)
are also files.
W: Uses FAT and NTFs as file systems,
L: Uses a variety of file systems.
Unlike Windows, Linux is bootable from a network drive.
Linux has two kinds of major partitions called data partitions and swap
partitions. Because of the existence of swap partitions, you never run out
of memory in Linux (like in windows).
In terms of recovery tools, only a limited number of tools can be used on
Windows, while there is a large number of UNIX based recovery tools
available for Linux file systems.
Usage of forward slash instead of backslashes for traversal in Linux.
Linux doesn’t use the file extension to determine file types. It uses a
header bytes of files and matches them with the set of magic numbers to
determine the file type. The file command is used to determine file type
Basics of OS and Linux 6
in Linux. File extensions may be used to filter out files for dome
processing or may be due to cross-platform interoperability.
Users and Groups in Linux
Multi-user OS.
Create new users - sudo useradd testuser
Modify existing users.
Remove users - sudo userdel testuser
To see list of users - cat /etc/passwd ⇒
you will see this the user accounts
as well you will notice the services have their own user accounts.
/etc/passwd stores the information for a user related to login.
/etc/shadow stores the information regarding the password details of the
user
A group is a collection of users. The primary purpose of the groups is to
define a set of privileges like read, write, or execute permission for a
given resource that can be shared among the users within the group.
To view list of all groups - cat /etc/group
Adding a group - sudo groupadd section
Adding a user to a group - sudo usermod -aG section testuser
Deleting a user from a group - sudo gpasswd -d testuser section
Deleting a group - sudo groupdel section
See all members of a group - getent group section
Concept of Root User
Root is the highest level of user in Linux systems, which has access to
the entire file system in user space.
sudo command is used to authenticate yourself as a root user, if you
belong to a group of sudoers .
root user, just like any other user, has elevated privileges but in user
space, that is, it cannot execute privileged commands like kernel which
directly manipulates the hardware.
suis used to switch between users, but this requires root level
permissions.
Basics of OS and Linux 7
Dual Boot vs Virtual Machine vs WSL
With dual booting, you have to make hard drive space when installing the
system and make sure you have backup media to boot from in case
something goes wrong.
WSL actually runs a a Linux kernel & OS inside of Windows and translates
Linux system calls to NT system calls. A surprising amount of features work
well. You can even get a Linux distro with a desktop running.
VM utilizes computer's virtualization, and is handled by a hypervisor.
Shell vs Terminal and CLI
A shell is a user interface for access to an operating system’s services.
A user interacts with the shell using a command-line interface (CLI).
The terminal is a program that opens a graphical window and lets you
interact with the shell.
The shell gives users (or other programs) a way to get "inside" the system to run
programs or manage configurations. The shell defines the boundary between
inside and outside.
A command-line interface (CLI) is a text-based user interface (UI) used to run
programs, manage computer files and interact with the computer.
Using Terminals and Basic Commands
ls (with options, l, a), chmod , chown , find , grep , cp , mv
file , sed '2,5s/amazing/super/g' textfile.txt
ps , kill -9 (signal)
ssh , scp
symlinks
Redirect operators, Piping commands
bashrc
The .bashrc file is a script file that’s executed when a user logs in.
The file itself contains a series of configurations for the terminal session.
Basics of OS and Linux 8
This includes setting up or enabling: colouring, completion, shell history,
command aliases, and more.
Shell customisations
Alias
Aliases are different names for the same command. Consider them as
shortcuts to a longer form command.
Example: alias wmi='whoami'
Bash Scripting
Check attached links
Functions - omniport-frontend
Braces
John Hammond
Vim
Vim is a free and open-source, screen-based text editor program. It is an
improved clone of vi.
It is designed for use both from a command-line interface and as a
standalone application in a graphical user interface.
Features:
Its memory footprint is very low
It is command centric. You can perform complex text related task with
few commands
It is highly configurable and uses simple text file to store its configuration
There are many plug-in available for Vim. Its functionality can be
extended in great manner using these plug-in
Modes: Normal, Insert, Visual
Basic Movement (h j k l 0 $ gg G :line_number)
Page Movement (ctrl + f b d u e y)
Word movement (w e b)
Basics of OS and Linux 9
Insert (i a o I A O)
Visual (v V Ctrl+v)
Search
/?
/\<word\>
:set ic
:set noic
Delete
dw
dd
5dd
d$
d0
:3,5d
Cut, Copy Paste
cut (d)
copy (y yy yw)
paster (p)
Tmux
Basics
Tmux is a terminal multiplexer.
You can start a Tmux session and then open multiple windows inside that
session
Each window occupies the entire screen and can be split into rectangular
panes.
Basics of OS and Linux 10
Tmux sessions are persistent, which means that programs running in
Tmux will continue to run even if you get disconnected.
Commands
ctrl-b is the default prefix to the tell that this command is for tmux
s list sessions (you can navigate too)
$ rename the current session
d detach from the current session
c create a new window
, rename the current window
w list windows
% split horizontally
" split vertically
n change to the next window
p change to the previous window
0 to 9 select windows 0 through
Bibliography
Desktop Environment
Distros
sudo
Ring diagram
Intro to Binary Exploitation
Bash Scripting
Brackets in Bash
Syscall Table
Building a Binary Deb Package
Process and Thread
Users and groups
Basics of OS and Linux 11
Shell and Terminal
Terminal, Shell, Console, Command Line
Bashrc and Aliases
Tmux
Basics of OS and Linux 12