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
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>orcommand --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-lafor all details (hidden files, permissions, owners)cd— change directory (cd /var/log,cd ..to go up)find— search for files by name, size, or typelocate— faster search using a prebuilt database
2. File manipulation
Reading and modifying files is non-negotiable.
cat— dump a file's contentsnano/vim— edit text files (nano is friendlier for beginners)cp,mv,rm— copy, move, deletetouch— create an empty file or update its timestamphead,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 needssudo)ls -l— shows permission string like-rwxr-xr--
4. Networking
Hacking relies on understanding network state.
ip a— show network interfaces and IPsifconfig— older but still commonping— check host reachabilitynetstat -tulpn— list listening ports and processescurl— 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 auxfor all)top/htop— real-time process monitoringkill— end a process (usekill -9as last resort)&— run a command in the backgroundjobs— list background jobs
6. Privilege escalation
Ethical hacking often requires admin rights.
sudo— run a command as rootsu— switch user (e.g.,su root)
Pro tip: Always check
sudo -lto 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
sudoor change permissions withchmod +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
sudoto kill - Fix: Try
killwith a normal signal first, then escalate tosudo kill -9
Edge case: Hidden files
- Issue:
lsdoesn't show config files like.bashrc - Fix: Always use
ls -lato 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 withgrepto 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
netstatandip - 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
rmwithout checking the path — deleting critical system files instead of a target file - Forgetting
sudowhen 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 fileinstead ofcat file | grep pattern, which is unnecessary but not harmful
Variations
- Use
busyboxon limited devices to get a stripped-down set of Unix commands - Consider
zshwith auto-suggestions and plugins as a more user-friendly shell than defaultbash - Try
tmuxfor managing multiple terminal sessions during a penetration test
Real-world use cases
- Incident response: inspecting
/var/log/auth.logwithtailandgrepto trace unauthorized SSH login attempts - Penetration testing: using
netstat -tulpnto discover open ports and running services as part of initial enumeration - CTF competition: quickly modifying file permissions with
chmodto execute a payload script and capture a flag
Key takeaways
- The Linux philosophy 'everything is a file' underpins commands like
ls,chmod, andnetstat - 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
Keep learning
Related tutorials, quizzes, and articles for this topic.
Discussion
Questions, corrections, and tips help everyone reading this page.
0 comments
Add a comment
No comments yet — start the thread.