knowledge

Overview

Linux is a lightweight, open-source operating system based on UNIX, first released by Linus Torvalds in 1991. Highly modular, secure, and customizable, it is widely used in servers, desktops, and embedded systems — and is the default environment for most CTF challenges and penetration testing. Linux comes in many distributions (distros) varying in package management, default tools, and user interfaces. It is generally considered more secure than other operating systems due to its permission model, active community, and rapid patch cycles.


Terminology

TermDefinition
Shell / TerminalInterface for entering commands and interacting with the OS
RootSuperuser account with full system privileges; prompt shown as #
Regular UserStandard account with limited privileges; prompt shown as $
Distro (Distribution)A packaged version of Linux with its own tools, UI, and package manager
File System HierarchyStandardized directory structure starting at / (root)
PID (Process ID)Unique number assigned to each running process
PPID (Parent Process ID)PID of the process that spawned a given process
DaemonBackground service process managed by the OS
systemdModern init system used to manage services and boot processes
System UserUID 1–999; created for system services
Local UserUID 1000+; regular human user accounts
Absolute PathFull path from root / to a file
Relative PathPath relative to the current working directory
PATH VariableLists directories the OS searches when looking for commands
InodeData structure storing file metadata (permissions, ownership, size, timestamps)
STDINStandard input — data stream 0
STDOUTStandard output — data stream 1
STDERRStandard error — data stream 2
PagerTool for reading large files one screen at a time (e.g., more, less)
SUIDSet User ID — runs a file with the permissions of its owner
SGIDSet Group ID — runs a file with the permissions of its owning group
Sticky BitPrevents users from deleting files in a directory they don’t own

Core Concepts

File System Structure

Linux uses a hierarchical file system rooted at /.

DirectoryPurpose
/Root of the entire file system
/etcSystem configuration files
/varVariable data — logs, databases, spool files
/rootHome directory for the root user
/tmpTemporary files; cleared on reboot
/homeHome directories for regular users
/binEssential user binaries
/usrUser programs and utilities
/procVirtual filesystem; running processes listed by PID
/etc/passwdContains user and system account info; readable by all users
/etc/shadowStores hashed passwords and expiration info; root access only
/etc/profileStores default settings for user sessions

/etc/passwd fields (colon-separated): Username : Password : UID : GID : User Info : Home Directory : Shell /etc/shadow fields (colon-separated): Username : Hashed Password : Last Change : Min Days : Max Days : Warn : Inactive : Expire


System Information Commands

Essential commands for gathering basic system information.

CommandDescription
whoamiDisplay current username
idReturn current user identity (UID, GID, groups)
hostnamePrint or set the name of the current host
uname -aPrint all OS info: kernel name, hostname, kernel release, version, hardware, OS
pwdPrint the current working directory
ifconfigView or assign network interface addresses (deprecated; replaced by ip)
ip addrShow or manipulate routing, network devices, and interfaces
netstatShow active network connections and ports
ssInvestigate sockets (modern netstat replacement)
psShow running processes
ps -auxShow all processes with detailed output
whoDisplay logged-in users
envPrint all environment variables — useful for enumeration
lsblkList block devices (disks and partitions)
lsusbList USB devices
lsofList all open files and which processes are using them
lspciList PCI devices
ssh user@ipConnect to a remote system via Secure Shell

CommandDescription
lsList files in current directory
ls -lLong listing with permissions, owner, size, date
ls -laLong listing including hidden files (dotfiles)
ls -ltLong listing sorted by modification time
cd <dir>Change directory
cd ..Go up one directory level
pwdPrint working directory
tree .Display directory structure as a graphical tree

Working with Files and Directories

CommandDescription
touch <name>Create an empty file
mkdir <name>Create a directory
mkdir -p /path/to/dirCreate directory and all parent directories
mv <src> <dst>Move or rename a file or directory
cp <file> <dest>Copy a file
rm <file>Remove a file
rm -r <dir>Remove a directory and its contents recursively
cat <file>Display file contents; also used to write or pipe text
file <name>Identify file type

Editors: nano is simpler and more common. vim is more powerful — includes Normal, Insert, Visual, Command, Replace, and Ex modes. Run vimtutor to learn vim interactively.


Finding Files and Directories

CommandDescription
which <tool>Returns the path to a binary or link
locate <name>Fast search using a local database — run sudo updatedb to refresh
find <path> <options>Powerful file search with filters

find option reference:

OptionDescription
-type fMatch files only
-type dMatch directories only
-name "*.conf"Match by filename pattern
-user rootMatch files owned by a specific user
-size +20kMatch files larger than 20KB
-newermt 2020-03-03Match files newer than the specified date
-exec ls -al {} \;Execute a command on each result
2>/dev/nullSuppress permission denied errors (redirect STDERR to null)

Example: find / -type f -name *.conf -user root -size +20k -newermt 2020-03-03 -exec ls -al {} \; 2>/dev/null


File Descriptors and Redirections

Every process has three default data streams:

StreamNumberDescription
STDIN0Standard input
STDOUT1Standard output
STDERR2Standard error
OperatorDescriptionExample
> or 1>Redirect STDOUT to a file (overwrites)ls > out.txt
>>Append STDOUT to a filels >> out.txt
<Use a file as STDINcat < file.txt
<<Heredoc — feed multi-line input until a delimitercat << EOF > file.txt
2>/dev/nullRedirect STDERR to null (suppress errors)find / -name x 2>/dev/null
|Pipe STDOUT of one command as STDIN to the next`find /etc

EOF is a Linux function that marks the end of input in a heredoc — type content, then type EOF on its own line to finish.


Filter Contents

Tools for reading, searching, and processing output.

CommandDescription
more <file>Read file one page at a time (forward only)
less <file>Read file with forward and backward navigation
head <file>Print first 10 lines of a file
tail <file>Print last 10 lines of a file
sort <file>Sort lines alphabetically by default
grep "pattern" <file>Search for lines matching a pattern
grep -v "pattern"Exclude lines matching a pattern (inverse grep)
cut -d":" -f1Split on delimiter : and return the first field
tr ":" " "Replace all : characters with spaces
column -tDisplay piped input in aligned tabular form
awk '{print $1, $NF}'Print first and last fields of each line
sed 's/old/new/g'Replace all occurrences of old with new in a stream
wc -lCount lines in input

Example pipeline: find /etc/ -name *.conf 2>/dev/null | grep system — find .conf files, suppress errors, filter for “system” apt list --installed | grep -o installed | wc -l — count installed packages


Regular Expressions

Regular expressions (regex) allow precise searching, filtering, and text manipulation. Available in grep, sed, awk, and many other tools.

OperatorDescription
()Group parts of a regex
[]Character class — e.g., [a-z], [0-9]
{}Quantifier — specifies how many times the previous pattern repeats
.Match any single character
*Match zero or more of the preceding element
^Match start of line
$Match end of line

Users and Permissions

User Types

User TypeUID RangeDescription
Root0Full system access
System Users1–999Created for system services and daemons
Local Users1000+Regular human user accounts

Permissions are assigned to three entities: Owner | Group | Others

Permission Breakdown

- rwx rw- r--   1 root root 1641 May 4 23:42 /etc/passwd
  |   |   |     |  |    |
  |   |   |     |  |    └── Group
  |   |   |     |  └─────── User (Owner)
  |   |   └───────────────── Others permissions
  |   └───────────────────── Group permissions
  └───────────────────────── Owner permissions
File type: - = file, d = directory, l = symlink
PermissionOctalFile EffectDirectory Effect
Read (r)4View file contentsList directory contents
Write (w)2Modify fileCreate, delete, rename files inside
Execute (x)1Run as programNavigate into directory

Octal Notation

BinaryOctalSymbolic
1117rwx
1015r-x
1004r—
1106rw-
0000---

Permission Commands

CommandDescription
chmod 755 <file>Set permissions using octal notation
chmod u+x <file>Add execute for owner using symbolic notation
chmod a-w <file>Remove write for all (a=all, o=others, g=group, u=user)
chown user:group <file>Change ownership of a file or directory
ls -lView permissions on files

Special Permissions

PermissionSymbolDescription
SUIDs in owner execute fieldProgram runs with owner’s privileges — risk if executable launches a shell
SGIDs in group execute fieldProgram runs with group’s privileges
Sticky Bit (T)T in others execute fieldOthers have NO execute; cannot see or run files in directory
Sticky Bit (t)t in others execute fieldOthers have execute; only owner/root can delete files they don’t own

SUID/SGID binaries can be a privilege escalation vector — check GTFOBins (https://gtfobins.github.io/) if a flagged binary can launch a shell.


Operators

OperatorDescription
&Run command in background immediately
&&Chain commands; second runs only if first succeeds
;Run commands sequentially regardless of success
|Pipe STDOUT of one command as STDIN to next
>Redirect output to file (overwrites)
>>Append output to file
[CTRL+Z]Suspend current process (send SIGTSTP)
bgResume suspended process in background
fg <job#>Bring background job to foreground
jobsList stopped/background jobs


References / Images