Key Linux Commands for Cybersecurity

Jul 31, 2024

Essential Linux Commands for Cybersecurity

Introduction

  • Focus on essential Linux commands and their flags
  • Importance for ethical hacking and cybersecurity
  • Advanced applications (e.g., Metasploit, nmap, Hydra, etc.) available in other videos

Navigating the Linux File System

Using the Terminal

  • ls: Lists directory contents
    • ls -l: Long listing format
      • Shows links, permissions (owner, group, everyone), owner, group, size, and modification date
    • ls -a: Includes hidden files
    • ls -t: Sort by modification time
    • ls -h: Human-readable sizes
    • Combine flags: ls -lath
  • cd: Change directory
    • cd -: Move to the previous directory
    • cd ..: Move up one directory level
    • cd ~: Go to home directory
    • Use tab for auto-completion
  • pwd: Print working directory

Manipulating Files and Directories

Creating and Managing Files

  • touch: Create empty files
    • Example: touch file1 file2 file3
  • mkdir: Create directories
    • Example: mkdir dir1
    • Recursive creation: mkdir -p parent/child
    • With permissions: mkdir -m 777 dir

Copying and Removing Files

  • cp: Copy files and directories
    • Example: cp file1 file2
    • Recursive copy: cp -r dir1 dir2
  • rm: Remove files and directories
    • Example: rm file1
    • Recursive and forceful: rm -rf dir

Moving and Renaming Files

  • mv: Move or rename files and directories
    • Example: mv oldname newname
  • clear: Clear the terminal screen

Disk Usage and Permissions

Disk Usage

  • du: Disk usage
    • Human-readable: du -h
    • Summary: du -sh

File Permissions

  • chmod: Change file permissions
    • Example: chmod u+x file
    • Numeric mode: chmod 777 file
  • chown: Change file owner
    • Example: chown user:group file

Viewing and Editing Files

Viewing Files

  • cat: Concatenate and display files
    • Combine files: cat file1 file2 > file3
    • Append: cat file >> file
  • tail: View end of files
    • Example: tail file
    • Follow file changes: tail -f file
  • head: View beginning of files
    • Example: head file
  • less: View files one page at a time
    • Example: less file
  • grep: Search text using patterns
    • Example: grep 'pattern' file

Text Editors

  • nano: Simple text editor
  • vi: More complex, feature-rich text editor

Process Management

Monitoring and Controlling Processes

  • ps: Process status
    • Detailed view: ps aux
  • top: Real-time process monitoring
    • Filter by user: top -u user
  • kill: Terminate processes
    • Example: kill pid
    • Forceful kill: kill -9 pid
  • jobs: List background jobs
  • fg: Bring background job to foreground

Networking Commands

  • ifconfig: Network interface configuration
  • ip: Newer network interface configuration
    • Example: ip a
    • Show routes: ip route
  • netstat: Network statistics
    • Listening ports: netstat -l
  • ss: Socket statistics
    • Example: ss -t
  • ssh: Secure shell
    • Example: ssh user@host
  • scp: Secure copy
    • Example: scp file user@host:/path
  • rsync: Remote sync
    • Example: rsync -avz source destination

System Information

  • uname: System information
    • Detailed: uname -a
  • df: Disk free space
    • Human-readable: df -h

Searching and Archiving

Finding Files

  • find: Search for files
    • Example: find /path -name filename
    • By size: find /path -size +1M
    • By modification time: find /path -mtime -30

Archiving and Compressing

  • tar: Archive files
    • Example: tar czf archive.tar.gz files
    • Extract: tar xzf archive.tar.gz
  • gzip: Compress files
    • Example: gzip file
    • Decompress: gunzip file.gz

User and Group Management

  • useradd: Add a new user
    • Example: useradd username
    • With home directory: useradd -m username
  • userdel: Delete a user
    • Example: userdel username
    • With home directory: userdel -r username
  • groupadd: Add a new group
    • Example: groupadd groupname
  • groupdel: Delete a group
    • Example: groupdel groupname

Conclusion

  • Focus on learning these essential commands
  • Further videos available for advanced topics
  • Encouragement to subscribe and follow for more content