Essential Linux Commands for Cybersecurity

Jul 31, 2024

Essential Linux Commands for Ethical Hacking and Cybersecurity

Introduction

  • Focus on essential Linux commands and special flags
  • Importance of commands for ethical hacking and cybersecurity
  • Advanced applications: Metasploit, nmap, Hydra

Navigating the Linux File System

Using the Terminal

  • Preferred method over file explorer
  • Basic command: ls
    • Lists directory contents
  • Flags for ls:
    • ls -l: Long listing format
    • ls -a: Shows hidden files
    • ls -t: Sorts by modification time
    • ls -h: Human-readable file sizes
    • Combine flags: ls -lath
  • Recursive listing: ls -R

Changing Directories

  • cd: Change directory
  • Navigation shortcuts:
    • cd ..: Go up one level
    • cd -: Go back to the previous directory
    • cd ~: Go to home directory
  • Using tab for autocomplete

Clear Command

  • clear: Clears the terminal screen

Manipulating Files and Directories

Creating Files and Directories

  • touch filename: Creates an empty text file
  • mkdir dirname: Creates a directory
  • Create multiple layers: mkdir -p dir1/dir2/dir3
  • Set directory permissions: mkdir -m 777 dirname

Copying Files and Directories

  • cp source destination: Copies a file
  • Copy directories: cp -r sourcedir destdir

Removing Files and Directories

  • rm filename: Removes a file
  • Remove directories: rm -r dirname
  • Use wildcard for batch removal: rm pattern*
  • Be cautious with rm -rf, especially at root level

Moving and Renaming Files

  • mv source destination: Moves or renames a file

Disk Usage

  • du: Disk usage of files and directories
  • Human-readable format: du -h
  • Summary: du -sh

File Permissions and Ownership

Changing Permissions

  • chmod: Change permissions
  • Format: chmod [user/group/others][+/-][rwx] filename
  • Numeric format: chmod 777 filename

Changing Ownership

  • chown: Change file owner
  • Format: chown user:group filename

Viewing and Editing Files

Viewing Files

  • cat filename: Display file contents
  • Combine files: cat file1 file2 > file3
  • Append to a file: cat file1 >> file2
  • tail filename: Show end of file
    • tail -n 15 filename: Shows last 15 lines
    • tail -f filename: Real-time file update
  • head filename: Show beginning of file
  • less filename: View file one page at a time
  • more filename: Similar to less

Text Editors

  • vi filename: Opens file in VI editor
  • nano filename: Opens file in Nano editor

Process Management

Viewing Processes

  • ps: Displays current user's processes
  • ps aux: Detailed process list

Using Top

  • top: Real-time process viewer
  • Sort by user or process ID

Killing Processes

  • kill PID: Terminates a process
  • Force kill: kill -9 PID

Background Processes

  • command &: Runs command in the background
  • jobs: Lists background jobs
  • fg: Brings background job to foreground

Networking Commands

Viewing IP Configuration

  • ifconfig: Display IP configuration (deprecated)
  • ip a: Display IP configuration (current)
  • ip route: Show routing table

Managing Network Routes

  • ip route add: Add a network route
  • ip addr add: Assign an IP address to an interface
  • ip addr del: Remove an IP address from an interface

Network Statistics

  • netstat -l: Show listening sockets
  • ss: Similar to netstat, but more detailed
  • ss -t: Show TCP sockets
  • ss -u: Show UDP sockets
  • ss -p: Show processes using sockets

Secure Connections

  • ssh user@hostname: Connect to remote machine via SSH
  • scp: Secure copy between machines
  • rsync: Remote file synchronization

System Information

  • uname -a: Detailed system information
  • df: Disk space usage
    • Human-readable: df -h
    • Detailed: df -Th

Searching Files and Directories

  • find /path -name filename: Search for files
  • find /path -size +1M: Search for files larger than 1MB
  • find /path -mtime -30: Search for files modified in last 30 days
  • grep pattern filename: Search within files

Archiving and Compression

  • tar -czf archive.tar.gz files: Create gzip archive
  • Extract archive: tar -xzf archive.tar.gz
  • gzip filename: Compress a file
  • gunzip filename.gz: Decompress a file

User Management

  • useradd username: Add a new user
  • userdel username: Delete a user
  • groupadd groupname: Add a new group
  • groupdel groupname: Delete a group

Conclusion

  • Importance of mastering these basic commands for cybersecurity and ethical hacking
  • Encouragement to check out advanced topics and videos on the channel

These notes cover the essential Linux commands discussed in the video, along with their flags and use cases. They are organized by categories for easy reference and study.