🔐

Key Linux Commands for Cybersecurity

Jul 31, 2024

Essential Linux Commands for Cybersecurity

Introduction

  • Focus on essential Linux commands for ethical hacking and cybersecurity
  • Importance of mastering these basics before moving on to advanced tools (e.g., Metasploit, nmap)
  • Use Terminal for navigating Linux filesystem

Navigating the Linux Filesystem

ls Command

  • Basic listing of directory contents
  • ls -l: Long listing format, shows more details (e.g., file permissions, owner, size)
  • ls -a: Shows hidden files
  • ls -t: Sorts by modification time
  • ls -h: Human-readable file sizes
  • Combine options: ls -lath

cd Command

  • cd: Change directory
  • cd -: Return to the previous directory
  • cd ..: Move up one directory level
  • cd ~: Go to the home directory
  • Tab completion for directories

pwd Command

  • pwd: Print working directory

Manipulating Files and Directories

touch Command

  • touch filename: Create empty text files

mkdir Command

  • mkdir directory_name: Create a new directory
  • mkdir -p path/to/directory: Create nested directories
  • mkdir -m 777 directory_name: Create a directory with specific permissions

cp Command

  • cp source destination: Copy files
  • cp -r source destination: Copy directories recursively

rm Command

  • rm filename: Remove files
  • rm -r directory: Remove directories recursively
  • rm *pattern*: Remove files matching a pattern

mv Command

  • mv source destination: Move or rename files

clear Command

  • clear: Clear the terminal screen

File Viewing and Editing

cat Command

  • cat filename: View file contents
  • cat file1 file2 > newfile: Concatenate files
  • cat file >> existingfile: Append to a file

tail Command

  • tail filename: View the last 10 lines of a file
  • tail -n N filename: View the last N lines
  • tail -f filename: Continuously monitor a file

head Command

  • head filename: View the first 10 lines of a file
  • head -n N filename: View the first N lines

less and more Commands

  • less filename: View file one page at a time, supports search
  • more filename: Simpler than less, also views file one page at a time

Text Editors

  • vi filename: Open file in vi editor (more complex, powerful)
  • nano filename: Open file in nano editor (user-friendly)

Process Management

ps Command

  • ps: Show processes for current user
  • ps aux: Detailed process listing

top Command

  • top: Real-time process monitoring
  • top -u username: Show processes for a specific user
  • top -p PID: Monitor a specific process

kill Command

  • kill PID: Terminate a process
  • kill -9 PID: Forcefully terminate a process

Job Control

  • command &: Run command in background
  • jobs: List background jobs
  • fg: Bring background job to foreground

Networking

ifconfig Command (Deprecated)

  • ifconfig: Show network interfaces

ip Command

  • ip a: Show IP addresses
  • ip route show: Show routing table
  • ip addr add IP/Mask dev interface: Add an IP address

netstat and ss Commands

  • netstat: Show network connections
  • ss: Socket statistics, newer than netstat
  • ss -t: Show TCP connections
  • ss -u: Show UDP connections

SSH and SCP

  • ssh user@host: Connect to a remote system
  • scp source user@host:destination: Secure copy files between hosts

Checking System Info

uname Command

  • uname -a: Show system information

df Command

  • df: Show disk space usage
  • df -h: Human-readable format

Finding Files

find Command

  • find /path -name filename: Find files by name
  • find /path -size +1M: Find files larger than 1MB
  • find /path -mtime -30: Find files modified in the last 30 days

grep Command

  • grep pattern file: Search for a pattern in a file
  • grep pattern /path/*: Search for a pattern in multiple files*

Archiving and Compression

tar Command

  • tar czf archive.tar.gz files: Create a compressed archive
  • tar xzf archive.tar.gz: Extract a compressed archive
  • tar rf archive.tar file: Add files to an archive

gzip Command

  • gzip file: Compress a file
  • gunzip file.gz: Decompress a file
  • gzip -l file.gz: List contents of a gzip file

User Management

Adding and Deleting Users

  • useradd username: Add a new user
  • userdel username: Delete a user
  • useradd -m username: Add a user with a home directory
  • useradd -G group username: Add a user to a specific group

Adding and Deleting Groups

  • groupadd groupname: Add a new group
  • groupdel groupname: Delete a group

Conclusion

  • Mastering these basic Linux commands is essential for anyone in cybersecurity
  • Subscribe to the channel for more advanced tutorials