🐧

Fundamental Linux Commands for Cyber Security

Jul 31, 2024

Essential Linux Commands for Cyber Security

Introduction

  • Focus: Essential Linux commands with special flags.
  • Importance: Basis for advanced tools like Metasploit, Nmap, Hydra.
  • Approach: Use terminal over GUI for navigation.

Navigation Commands

ls

  • Basic Command: Lists directory contents.
  • Flags:
    • -l: Long listing format (detailed info).
    • -a: Shows hidden files.
    • -t: Sort by modification time.
    • -h: Human-readable file sizes.
    • -r: Recursively list directory contents.

cd

  • Basic Command: Change directory.
  • Tips:
    • cd -: Go to the previous directory.
    • cd ..: Move up one directory level.
    • cd ~: Go to the home directory.
    • Tab completion: Use Tab to auto-complete directory names.

pwd

  • Command: Print working directory.
  • Usage: Shows the full path of the current directory.

File and Directory Management

touch

  • Command: Create empty files.
  • Example: touch test1.txt test2.txt

mkdir

  • Command: Create directories.
  • Flags:
    • -p: Create parent directories as needed.
    • -m: Set file permissions.

cp

  • Command: Copy files and directories.
  • Flags:
    • -r: Recursively copy directories.
    • -f: Force overwrite existing files.

rm

  • Command: Remove files and directories.
  • Flags:
    • -r: Recursively delete directories.
    • -f: Force deletion.
  • Usage: Be cautious with rm -rf / as it can delete the entire system.

mv

  • Command: Move or rename files and directories.
  • Usage: mv oldname newname or mv file /newpath/

Permissions and Ownership

chmod

  • Command: Change file permissions.
  • Usage: chmod u+x file (give execute permission to the user).
  • Flags:
    • u: User
    • g: Group
    • o: Others
    • +: Add permission
    • -: Remove permission

chown

  • Command: Change file owner and group.
  • Usage: chown user:group file

Viewing File Contents

cat

  • Command: Display file contents.
  • Usage: cat file
  • Additional Features: Concatenate files and redirect output.

tail

  • Command: Display the last part of a file.
  • Flags:
    • -n: Number of lines to display.
    • -f: Follow file updates in real-time.

head

  • Command: Display the first part of a file.
  • Flags:
    • -n: Number of lines to display.

less and more

  • Commands: Page through text one screen at a time.
  • Usage: less file, more file
  • Note: less is more functional.

Disk Usage

du

  • Command: Disk usage of files and directories.
  • Flags:
    • -h: Human-readable sizes.
    • -s: Summary of a directory.

df

  • Command: Report file system disk space usage.
  • Flags:
    • -h: Human-readable sizes.
    • -T: Include file system type.

Networking

ifconfig and ip

  • Commands: Display or configure network interfaces.
  • Usage: ip addr show (preferred over ifconfig)

ping

  • Command: Check network connectivity.
  • Usage: ping hostname

netstat and ss

  • Commands: Network statistics and socket statistics.
  • Usage: netstat -l, ss -t

ssh and scp

  • Commands: Secure shell and secure copy.
  • Usage: ssh user@host, scp file user@host:/path

Process Management

ps

  • Command: Display information about active processes.
  • Flags:
    • aux: Detailed information about all processes.

top

  • Command: Display tasks and system resource usage in real-time.
  • Usage: top, top -u username

kill

  • Command: Terminate a process.
  • Flags:
    • -9: Forcefully kill a process.
  • Usage: kill pid, kill -9 pid

jobs and bg/fg

  • Commands: Manage background jobs.
  • Usage: jobs, bg jobnum, fg jobnum

Archiving and Compression

tar

  • Command: Archive files.
  • Flags:
    • -c: Create an archive.
    • -x: Extract an archive.
    • -f: Specify filename.
    • -z: Compress the archive with gzip.

gzip and gunzip

  • Commands: Compress and decompress files.
  • Usage: gzip file, gunzip file

Finding Files

find

  • Command: Search for files in a directory hierarchy.
  • Usage: find /dir -name filename
  • Flags:
    • -size: Search by size.
    • -mtime: Search by modification time.

grep

  • Command: Search text using patterns.
  • Usage: grep pattern file

User Management

useradd and userdel

  • Commands: Add and delete users.
  • Flags:
    • -m: Create home directory.
    • -e: Set account expiration date.
  • Usage: useradd username, userdel username

groupadd and groupdel

  • Commands: Add and delete groups.
  • Usage: groupadd groupname, groupdel groupname

Conclusion

  • Goal: Become proficient in these essential commands before advancing to more complex tools.
  • Additional Resources: Check out more advanced videos and tutorials on specific tools and commands.