Linux Fundamentals Part 1

beginner30 minWriteup

Basic Linux commands and navigation

Learning Objectives

  • Navigate Linux filesystem
  • Use basic commands
  • Understand file permissions
  • Use man pages

Linux is the operating system that powers the majority of servers, security tools, and hacking environments. If you want to work in cybersecurity, you MUST be comfortable with Linux. This room teaches the absolute basics - navigating the filesystem, running commands, and understanding how Linux works.

Think of the command line as texting your computer instead of clicking buttons. It's faster, more powerful, and essential for security work. Once you get comfortable, you'll never want to go back to clicking through menus.

Why Linux for Hacking?

Most security tools are built for Linux. Kali Linux comes with hundreds of pre-installed tools. Target servers are often Linux. Learning Linux is non-negotiable for security professionals.

Basic Commands

bash
1606070;"># Essential Linux Commands
2 
3606070;"># Print working directory (where am I?)
4pwd
5606070;"># Output: /home/user
6 
7606070;"># List files and folders
8ls
9ls -la 606070;"># Detailed view with hidden files
10 
11606070;"># Change directory
12cd /home 606070;"># Go to specific path
13cd .. 606070;"># Go up one level
14cd ~ 606070;"># Go to home directory
15cd - 606070;"># Go to previous directory
16 
17606070;"># Print text
18echo 606070;">#a5d6ff;">"Hello World"
19echo $PATH 606070;"># Print environment variable
20 
21606070;"># Display file contents
22cat file.txt
23 
24606070;"># Display first/last lines
25head file.txt 606070;"># First 10 lines
26tail file.txt 606070;"># Last 10 lines
27tail -f /var/log/syslog 606070;"># Follow live updates
28 
29606070;"># Manual pages (help)
30man ls 606070;"># Full documentation for 'ls'
31ls --help 606070;"># Quick help
32 
33606070;"># Clear terminal
34clear 606070;"># Or press Ctrl+L
bash
1606070;"># File Operations
2 
3606070;"># Create files
4touch newfile.txt 606070;"># Empty file
5echo 606070;">#a5d6ff;">"content" > file.txt # With content
6 
7606070;"># Create directories
8mkdir newfolder
9mkdir -p path/to/deep/folder 606070;"># Create nested folders
10 
11606070;"># Copy files
12cp file.txt backup.txt 606070;"># Copy file
13cp -r folder/ backup_folder/ 606070;"># Copy directory
14 
15606070;"># Move/rename files
16mv file.txt newname.txt 606070;"># Rename
17mv file.txt /path/to/dest/ 606070;"># Move
18 
19606070;"># Delete files
20rm file.txt 606070;"># Delete file
21rm -r folder/ 606070;"># Delete directory
22rm -rf folder/ 606070;"># Force delete (careful!)
23 
24606070;"># Find files
25find / -name 606070;">#a5d6ff;">"filename" # Search entire system
26find . -name 606070;">#a5d6ff;">"*.txt" # Find .txt files in current dir
27locate filename 606070;"># Fast search (uses database)
28 
29606070;"># Search in files
30grep 606070;">#a5d6ff;">"pattern" file.txt # Find text in file
31grep -r 606070;">#a5d6ff;">"pattern" /path/ # Search recursively

rm -rf is Dangerous

The command "rm -rf" deletes files and folders without confirmation or recovery. Never run "rm -rf /" - it will destroy your entire system. Always double-check paths before using rm.

Linux Filesystem

1Linux Filesystem Structure:
2 
3/
4├── bin/ 606070;"># Essential command binaries
5├── boot/ 606070;"># Boot loader files
6├── dev/ 606070;"># Device files
7├── etc/ 606070;"># System configuration files
8├── home/ 606070;"># User home directories
9│ └── user/ 606070;"># Your files go here
10├── lib/ 606070;"># Shared libraries
11├── media/ 606070;"># Mount point for removable media
12├── mnt/ 606070;"># Mount point for temporary mounts
13├── opt/ 606070;"># Optional application packages
14├── proc/ 606070;"># Process information (virtual)
15├── root/ 606070;"># Root user's home directory
16├── sbin/ 606070;"># System binaries
17├── tmp/ 606070;"># Temporary files (cleared on reboot)
18├── usr/ 606070;"># User utilities and applications
19│ ├── bin/ 606070;"># User commands
20│ ├── lib/ 606070;"># Libraries
21│ └── share/ 606070;"># Shared data
22└── var/ 606070;"># Variable files (logs, databases)
23 └── log/ 606070;"># System logs
24 
25Key Directories for Security:
26─────────────────────────────────────────────────────────────────────
27/etc/passwd │ User accounts
28/etc/shadow │ Password hashes (root only)
29/etc/hosts │ Local DNS
30/var/log/ │ System logs
31/tmp/ │ Temporary files (world-writable)
32/home/ │ User data and configs

File Permissions

bash
1606070;"># Understanding Permissions
2 
3606070;"># View permissions with ls -l
4ls -l
5606070;"># -rw-r--r-- 1 user group 1234 Jan 1 12:00 file.txt
6606070;"># ╰─────╯
7606070;"># Permissions
8 
9606070;"># Permission breakdown:
10606070;"># -rw-r--r--
11606070;"># │╰─╯╰─╯╰─╯
12606070;"># │ │ │ └── Others (everyone else)
13606070;"># │ │ └───── Group
14606070;"># │ └──────── Owner/User
15606070;"># └────────── File type (- = file, d = directory)
16 
17606070;"># Permission letters:
18606070;"># r = read (4)
19606070;"># w = write (2)
20606070;"># x = execute (1)
21606070;"># - = no permission (0)
22 
23606070;"># Change permissions with chmod
24chmod 755 file.txt 606070;"># rwxr-xr-x (owner full, others read+execute)
25chmod 644 file.txt 606070;"># rw-r--r-- (owner read+write, others read)
26chmod +x script.sh 606070;"># Add execute permission
27chmod -w file.txt 606070;"># Remove write permission
28 
29606070;"># Change ownership
30chown user:group file.txt
31chown user file.txt 606070;"># Change owner only
32chown -R user:group dir/ 606070;"># Recursive
1Permission Numbers Explained:
2 
3Number │ Binary │ Permission
4────────┼─────────┼───────────
5 0000 │ ---
6 1001 │ --x
7 2010 │ -w-
8 3011 │ -wx
9 4100 │ r--
10 5101 │ r-x
11 6110 │ rw-
12 7111 │ rwx
13 
14Common Permission Sets:
15────────────────────────
16755 = rwxr-xr-x │ Executable, public readable
17644 = rw-r--r-- │ Regular file, public readable
18600 = rw------- │ Private file
19700 = rwx------ │ Private executable/directory
20777 = rwxrwxrwx │ Everyone full access (dangerous!)

Security Note: World-Writable

Files with permission 777 or directories like /tmp that are world-writable (everyone can write) are often targets for privilege escalation. Always check file permissions during pentests!

Room Walkthrough

Linux Fundamentals Part 1 Tasks

1
IntroductionRead about what Linux is and why it's important. Answer basic questions from the reading.
2
Basic CommandsPractice echo, whoami, pwd, ls, cd. The room provides an in-browser terminal.
3
File OperationsCreate, copy, move, and delete files. Use touch, cp, mv, rm, mkdir.
4
Reading FilesUse cat, head, tail to view file contents. Find specific content using grep.
5
PermissionsUnderstand ls -l output. Identify who can read/write/execute files.
bash
1606070;"># Room Answer Examples (actual answers may vary)
2 
3606070;"># Task: What is the output of whoami?
4whoami
5606070;"># Answer: Usually your username (tryhackme, ubuntu, etc.)
6 
7606070;"># Task: How do you list files with details?
8ls -la
9606070;"># Answer: ls -la (or ls -l)
10 
11606070;"># Task: What directory are you in?
12pwd
13606070;"># Answer: Shows current path
14 
15606070;"># Task: Output contents of file.txt
16cat file.txt
17606070;"># Answer: Contents of the file
18 
19606070;"># Task: Find specific text in a file
20grep 606070;">#a5d6ff;">"searchterm" file.txt
21606070;"># Answer: Lines containing the search term
22 
23606070;"># Remember: Answers in TryHackMe are case-sensitive!

Knowledge Check

Quick Quiz
Question 1 of 3

Which command shows your current directory?

Challenges

Navigate and Read Files

Challenge
🌱 beginner

In a Linux terminal: 1) Find what directory you're in, 2) Navigate to /etc, 3) Read the first 5 lines of the passwd file, 4) Navigate back to your home directory.

Need a hint? (4 available)

Key Takeaways

  • pwd shows current directory, ls lists files, cd navigates
  • cat reads files, grep searches within files
  • File permissions control read (r), write (w), execute (x) access
  • Permission numbers: 4=read, 2=write, 1=execute, combine for total
  • Important paths: /etc (configs), /home (users), /var/log (logs)
  • man command gives detailed help for any command