Basic Linux Commands for Hacking

Master essential Linux commands used in ethical hacking—file navigation, permissions, networking, and process management—with hands-on exercises and real-world scenarios.

Focus: basic linux commands for hacking

Sponsored

You've got your Kali Linux VM booted, a terminal blinking at you, and a target IP address scribbled on a sticky note. But the moment you type your first command, you freeze — ls, cd, chmod — familiar yet foreign. Every ethical hacking tutorial assumes you speak Linux fluently, but most beginners are still translating from Windows or macOS. This lesson bridges that gap. You'll master the core Linux commands that form the backbone of every penetration test — navigation, file manipulation, permissions, networking, and process control — so you can execute tools like Nmap and Metasploit with confidence, not confusion.

The problem this lesson solves

You can't hack what you can't control. Ethical hacking is 90% terminal work — reading output, modifying scripts, transferring files, and pivoting through systems. If you fumble basic commands, you'll:

  • Mistype a flag and corrupt a file instead of reading it
  • Fail to navigate an SSH session when you finally breach a target
  • Run a script without execute permissions and waste minutes debugging
  • Leave a suspicious process running that alerts the blue team

Beginners often skip Linux fundamentals, jumping straight into "hacking tools." Then they hit a wall: they can't run nmap without sudo, can't interpret the output, and don't know how to change a file's permissions to execute an exploit they just downloaded. This lesson removes that wall — fast.

Core concept / mental model

Think of Linux commands as a Swiss Army knife for the system. Each command is a tool with a specific purpose, and flags are the attachments that adapt it. You don't memorize every tool — you learn the core set and how to combine them.

Here's a mental model to anchor everything:

  • Everything is a file — processes, devices, and directories are all files with permissions
  • Commands have three parts — the command, options (flags), and arguments
  • You're always in a directory — every command executes from your current location
  • Permissions gate everything — you can't read, write, or execute without the right bits

Pro tip: If you ever doubt a command, use man <command> or command --help. The manual is built into Linux — no Google needed.

How it works step by step

Let's break down the essential command categories you'll use daily in ethical hacking.

1. Navigation & file system

Your first objective is knowing where you are and what's around you.

  • pwd — print working directory (where am I?)
  • ls — list files; add -la for all details (hidden files, permissions, owners)
  • cd — change directory (cd /var/log, cd .. to go up)
  • find — search for files by name, size, or type
  • locate — faster search using a prebuilt database

2. File manipulation

Reading and modifying files is non-negotiable.

  • cat — dump a file's contents
  • nano / vim — edit text files (nano is friendlier for beginners)
  • cp, mv, rm — copy, move, delete
  • touch — create an empty file or update its timestamp
  • head, tail — view the start or end of a file (great for logs)
  • grep — search inside files for patterns

3. Permissions

Every file has an owner, group, and others, each with read (r), write (w), execute (x) rights.

  • chmod — change permissions (e.g., chmod +x script.sh)
  • chown — change ownership (almost always needs sudo)
  • ls -l — shows permission string like -rwxr-xr--

4. Networking

Hacking relies on understanding network state.

  • ip a — show network interfaces and IPs
  • ifconfig — older but still common
  • ping — check host reachability
  • netstat -tulpn — list listening ports and processes
  • curl — transfer data to/from URLs (e.g., HTTP requests)
  • ssh — remote shell connection

5. Process management

When you run tools, you need to control them.

  • ps — list running processes (ps aux for all)
  • top / htop — real-time process monitoring
  • kill — end a process (use kill -9 as last resort)
  • & — run a command in the background
  • jobs — list background jobs

6. Privilege escalation

Ethical hacking often requires admin rights.

  • sudo — run a command as root
  • su — switch user (e.g., su root)

Pro tip: Always check sudo -l to see which commands you can run as root — this is a classic privilege escalation check.

Hands-on walkthrough

Let's put this into practice with a realistic scenario. You're on Kali Linux, tasked with examining a server for weak points.

Example 1: Reconnaissance with navigation

# Check your identity and location
whoami
pwd

# List all files, including hidden, with permissions
ls -la

# Navigate to the system logs and peek at the last entries
tail -n 50 /var/log/syslog | grep "Failed password"

Expected output snippet:

user@kali:~
-rwxr-xr-- 1 root root 1234 Feb 10 10:00 report.txt
Feb 10 10:01:01 server sshd[1234]: Failed password for root from 192.168.1.101 port 22

Example 2: File manipulation and permissions

# Create a script that pings a host
cat > ping_test.sh <<EOF
#!/bin/bash
ping -c 4 192.168.1.1
EOF

# Make it executable and run it
chmod +x ping_test.sh
./ping_test.sh

Expected output:

PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.043 ms
...

Example 3: Networking and process control

# Find listening ports and the processes behind them
netstat -tulpn | grep LISTEN

# Run a Nmap scan in the background, then check it
nmap -sV 192.168.1.1 &
ps aux | grep nmap

# If it hangs, kill it
sudo kill -9 <PID>

Expected output (abridged):

tcp  0  0 0.0.0.0:22  0.0.0.0:*  LISTEN  1234/sshd
user   5678  0.0 0.1 23456  1234 ?  S  10:00  0:00 nmap -sV 192.168.1.1

Summary of what these exercises taught you:

  • You can locate yourself, inspect files, and filter output
  • You can create and execute simple scripts — essential for custom exploits
  • You can map network services and manage long-running scans

Compare options / when to choose what

Different situations call for different commands. Here's a quick comparison table for frequent choices:

Task Primary Command Alternative When to use which
List files ls -la tree ls is universal; tree gives a hierarchy view
Search files find locate find scans live; locate is faster but needs updatedb
Edit a file nano vim nano is beginner-friendly; vim is powerful once mastered
Network info ip a ifconfig ip is modern; ifconfig still works on older systems
Process list ps aux top/htop ps is static; top/htop are live and interactive
Kill a process kill pkill kill needs a PID; pkill matches a name

Rule of thumb: Start with the simplest command that works. If you need more power, escalate to the alternative.

Troubleshooting & edge cases

Error 1: "Permission denied"

  • Cause: You lack execute or read rights
  • Fix: Use sudo or change permissions with chmod +x file

Error 2: "Command not found"

  • Cause: Tool not installed or not in PATH
  • Fix: Install with sudo apt install <tool>, or use full path like /usr/bin/tool

Error 3: Process won't stop

  • Cause: Process is stuck or needs sudo to kill
  • Fix: Try kill with a normal signal first, then escalate to sudo kill -9

Edge case: Hidden files

  • Issue: ls doesn't show config files like .bashrc
  • Fix: Always use ls -la to reveal them — they often hold credentials or settings

Edge case: Output too long

  • Issue: Scrolling forever in terminal
  • Fix: Pipe to less — e.g., ls -la | less; also combine with grep to filter

Pro tip: When you're chaining commands, use command1 | command2 (pipe) to pass output. It's the backbone of Linux efficiency.

What you learned & what's next

You now have a solid Linux foundation for ethical hacking. Let's recap what you can do:

  • Navigate the filesystem and find critical files (like logs)
  • Manipulate and execute scripts — a prerequisite for running exploits
  • Understand file permissions — crucial for privilege escalation
  • Map network services with netstat and ip
  • Manage processes — essential for controlling scans and avoiding detection

You are ready for the next lesson: Basic Networking Tools for Hacking. There, you'll dive into Nmap, Netcat, and Wireshark to actively scan and interact with target systems. Your new command-line fluency will make those tools feel like second nature.

Your challenge: Before next lesson, run the exercises above on your own VM. Try to investigate a local service with netstat and nmap, and practice killing a background process. Then you can move forward with confidence.

Practice recap

Boot your Kali Linux VM (or any Linux box) and run these exercises: 1) ls -la /etc/passwd and read the file with cat; 2) create a script that pings your router, make it executable, and run it; 3) check listening ports with netstat -tulpn and identify at least one service. If you get stuck, revisit this lesson's troubleshooting section.

Common mistakes

  • Running rm without checking the path — deleting critical system files instead of a target file
  • Forgetting sudo when reading restricted logs or killing root-owned processes
  • Executing a downloaded script without chmod +x, causing a permission denied error
  • Piping grep wrong — using grep pattern file instead of cat file | grep pattern, which is unnecessary but not harmful

Variations

  1. Use busybox on limited devices to get a stripped-down set of Unix commands
  2. Consider zsh with auto-suggestions and plugins as a more user-friendly shell than default bash
  3. Try tmux for managing multiple terminal sessions during a penetration test

Real-world use cases

  • Incident response: inspecting /var/log/auth.log with tail and grep to trace unauthorized SSH login attempts
  • Penetration testing: using netstat -tulpn to discover open ports and running services as part of initial enumeration
  • CTF competition: quickly modifying file permissions with chmod to execute a payload script and capture a flag

Key takeaways

  • The Linux philosophy 'everything is a file' underpins commands like ls, chmod, and netstat
  • Navigation (cd, ls -la) and file manipulation (cat, chmod) are foundational before using any hacking tool
  • Networking commands (ip a, netstat, ping) form the core of reconnaissance and discovery
  • Process management (ps, kill) is critical for controlling scans and cleanup during engagements
  • Troubleshooting common errors relies on understanding permissions, PATH, and piping output

Sponsored

Sponsored

Discussion

Questions, corrections, and tips help everyone reading this page.

0 comments

Add a comment

Shown publicly with your comment.

Be constructive · max 4,000 characters

No comments yet — start the thread.

Related tutorials, quizzes, and articles for this topic.