Linux

Objectives: By the end of this topic, you will be able to…

  • Navigate the Linux filesystem with confidence
  • Manipulate files, permissions, and processes from the terminal
  • Install tools needed for other classes
  • Begin writing simple scripts to automate tasks

Why use Linux in cybersecurity

Linux is the most widely used operating system among cybersecurity professionals due to its control, flexibility, and large tool ecosystem. Kali Linux is a specialized Debian-based distribution that includes tools for pentesting, forensics, network analysis, reverse engineering, and more.

Working directly with the terminal (CLI) allows automating tasks, interacting directly with tools, and better understanding how systems work.


Filesystem structure

Linux organizes everything in a single directory hierarchy, where everything is a file, including devices and processes.

DirectoryTypical contents
/System root
/homeUser home directories
/etcSystem configuration files
/binEssential system commands
/usrUser applications
/varVariable data (logs, cache)
/tmpTemporary files
/rootHome directory of the root user
/devDevices (disks, USB, etc.)
/procInformation about processes and the kernel

Essential navigation and manipulation commands

pwd        # Show current directory
ls         # List files
cd         # Change directory

File and directory manipulation

cp file destination        # Copy
mv file destination        # Move or rename
rm file                    # Delete
mkdir directory_name       # Create directory
touch file.txt             # Create empty file
cat file.txt               # View file contents
less file.txt              # View contents with pagination

Useful exploration

tree                     # View directory structure
file file                # Detect file type
find /path -name "*.txt" # Search files by name/extension

File permissions and user management

Understanding permissions

ls -l

Typical output:

-rwxr-xr-- 1 user group 1234 jul 18 file.sh

The first 10 characters indicate type and permissions:

  • r = read, w = write, x = execute
  • Structure: [user][group][others]

Permission and user commands

chmod 755 file.sh           # Change permissions (rwxr-xr-x)
chown user:group file       # Change owner
whoami                      # Show current user
sudo command                # Execute with elevated privileges

Processes and services

Process monitoring

ps aux           # View all processes
top / htop       # Dynamic view (htop must be installed)
kill PID         # Terminate a process

Services (systemd)

systemctl status service_name
systemctl start/stop/restart service_name

Package installation and using man

Package management

sudo apt update            # Update package list
sudo apt install name      # Install a package
sudo apt remove name       # Remove a package

Kali Linux already includes many cybersecurity tools, but you can install others as needed.

Getting help

man command     # Full manual
command --help  # Quick help

Basic Bash scripting concepts

Scripts allow automating tasks using command-line tools.

Minimal structure:

#!/bin/bash
echo "Hello, World"

Useful commands in scripts: if, then, else, for, while, read, $(command)

Simple example:

#!/bin/bash
echo "What is your name?"
read name
echo "Hello, $name"

Allow execution:

chmod +x script.sh
./script.sh

Hands-on lab

Requirements: Kali Linux

Part 1: System exploration

  1. Navigate from / to /etc, /var, and /home. Identify the purpose of each
  2. Read the contents of /etc/passwd and answer:
    • What type of information does it contain?
    • What is the difference between this file and /etc/shadow?
  3. Verify the permissions of /etc/shadow with ls -l and explain why it cannot be read as a normal user
  4. Review logs:
less /var/log/boot.log
less /var/log/dpkg.log

Part 2: Files and permissions

  1. Create a working folder at ~/linux_practice
  2. Create three files with dummy content
  3. Execute and document the effects of:
cp file1.txt copy.txt
mv file2.txt renamed.txt
rm file3.txt
chmod 644 copy.txt
chmod +x renamed.txt
chown root:root copy.txt

Part 3: Processes and services

  1. Run top and observe the most active processes. Filter with ps aux | grep bash
  2. Start a program in the background and terminate it with kill
  3. Check the status of ssh, cron, and apache2:
systemctl status ssh
service cron status

Part 4: Package management

  1. Search for a package such as nmap, htop, or net-tools:
apt search nmap
  1. Install, verify, and uninstall a package

Part 5: Bash automation

  1. Create a script that:
    • Finds all .txt files in the home directory
    • Counts the lines in each file
    • Prints the result sorted by number of lines
  2. Add improvements: save results to a file, accept a directory as an argument

Submission

Compressed file (.zip or .tar.gz) with:

  • Key screenshots
  • The Bash script with comments
  • Document with answers to questions and reflections

Key concepts

TermDefinition
CLICommand Line Interface. Text-based interface for interacting with the operating system
PermissionsFile access control system based on read, write, and execute for user, group, and others
systemdInit system and service manager used in modern Linux distributions
BashBourne Again Shell. Default command interpreter and scripting language on most Linux distributions
aptAdvanced Package Tool. Package manager for Debian and its derivatives like Kali

Test yourself

  1. Permissions: A file has permissions -rw-r-----. Who can read it? Who can write to it? What command would you use to make it executable only for the owner?

  2. Security: Why does /etc/shadow have restrictive permissions while /etc/passwd is readable by everyone? What would happen if both were readable?

  3. Scripting: Write a Bash script that takes an IP address as an argument and runs ping -c 3 against it, saving the result to a file named after the IP.


Navigation:Previous | Home | Next