Introduction to Linux

"Linux is an open source Unix-Like operating system based on the linux kernal..." yeah this blog isn't about a lecture on linux but how to use the system and utilise it for cyber security. What you need to know is that:

  • Linux is an operating system

  • It has things called "Distributions" which are: Ubuntu, Debian, Arch, Fedora, etc.

  • You have a lot of control over everything and linux won't warn you - wanna delete your root directory? Go for it!

This amount of customisation and control over your system makes linux an ideal system to master.

Using Linux

We will go into:

  • Linux File Systems

  • Linux Commands

  • Exercises

File Systems

Files in linux operate on a hierarchy type model for its files and directories:

The top part of the 'tree' is called the root - it houses all of your directories, while everything else is called a 'node'. Each 'parent' node can have a 'child' node, which is to say, a folder inside of another folder.

Content Types

There are 4 major types of content stored in a file system:

  1. Persistent: Contents that will be persistent after a system reboot. (Systems and Application configuration settings)

  2. Runtime: Content generated by a running process (Usually deleted by a reboot)

  3. Variable/Dynamic: The content of these can be appended or modified by processes running on the system

  4. Static Content: Content that remains unchanged unless edited or configured

System DirectoriesPurpose

/etc

Contains configuration files used by system services

/root

This is a home directory for the Linux superuser account, root

/boot

Contains all the files needed to start the boot process.

/home

This is where standard users store their personal configurations and data such as Documents, Videos, Music etc

/var

Has variable data that is required to persist between boots – databases, log files, mails, cache directories, Web data etc

/tmp

Stores temporary files. All Linux users can write to this directory. Files older than 10 days are deleted automatically.

/usr

This directory contains shared libraries, installed software, and read-only program data. Some of the important subdirectories include: /usr/bin: Mostly user commands are located here. /usr/sbin: Hosts System administrative commands that required privilege escalation to run. /usr/local: For locally customized software.

/dev

This contains special device files used by the system to access hardware.

/run

The processes started since the last boot stores their runtime data here, e.g. process ID files and lock files. These contents are recreated on reboot.

Source

Shortcuts

Some helpful shortcuts:

root - '/'
home - '~' OR 'cd [ENTER]'
previous - '-'

The terminal is the most essential part of your linux system (other than the root, boot, uhh everything else) learning how to use it will make you much faster in navigating, programming, and hacking. Skipping this step will only bring you pain trust me.

Basic Commands

# Help
man - Manual - man [command] - man ls

# Utility
echo - Echoes user input (Functions as print) - echo "Hello"
cat  - Concatinate, append or replace text / display file contents - cat "Hello" > file.txt, cat file.txt

# Navigation
cd - Change Directory - cd [directory] - cd /
ls - List Directory Contents - ls [OPTIONS] - ls OR ls /[folder]

# Creating Files & Folders
mkdir - Make Directory - mkdir [NAME] - mkdir testfolder
touch - Create File - touch [NAME][.EXT] - touch script.sh
cp    - Copy File - cp [ORIG] [COPY] - cp original.txt new.txt
mv    - Move / Rename - mv [file/folder] [location] OR mv [filename1] [filename2]

# Deleting Files & Folders
rm - Remove - rm [FILE] - rm script.sh
rmdir - Remove Directory - rmdir [FOLDER] - rmdir testfolder (Empty folders)

# Network Commands
ifconfig - Interface Configuration - shows your IP addresses, and other network info - ifconfig [INTERFACE] - ifconfig eth0
ip	 - Same as ifconfig - ip a 
netstat  - Network Statistics - netstat [FLAGS]
ping 	 - Sends packets to check destination response - ping [URL] OR ping [IP]

There are many more commands that we will come across but we will get to them later. For now, let's look at flags and wildcards.

Flags

# Flags [Find list of a commands' flag using man]

## Navigation

ls -l > Long list
ls -a > Display All (Hidden included)
ls -R > List recursively (Current directory + any directory that is inside it)
# You can chain flags together too (Usually)

ls -la > List everything + long listed
ls -laR > Everything + Recursive + Long

## Nested folders
mkdir -p > create folders + parent folders if they are not present - mkdir -p folder1/folder2/folder3

## Remove
rm -r > remove recursively
rm -f > force remove
rm -rf > recursive force (! Careful with this, you can delete your entire file system as well)

Wildcards

Wildcards are special characters that do specific things or target specific items based on the users' input

* - Matches any number of chars or a set of chars. Example:

file1.txt
file2.txt

To select file2.txt using *: *2.txt
it will target a pattern that matches with whatever ends in 2.txt

? - Matches a set number of chars depends on how many ? you use. Example:

Seer
Seen
Soon

To select everything that starts with S, has 2 chars in the middle, and ends with n - S??n


[] # - Matches a range of characters between the brackets. Example:

 S[on]n # will match Son and Snn (Range from on)
# If we do S[a-d]n, we will match San, Sbn, Scn, Sdn (Range from a to d)

Exercises

Solve these exercises to get you comfortable with using Linux. You can always refer to the man page or back here for references.

[+] OverTheWire Bandit

[+] Linux Full Course Video

Last updated