Linux Fundamentals Part 2
Overview — The second Linux Fundamentals room moves from the in-browser terminal to a real remote login. You connect to the room's Ubuntu machine over SSH, learn to read manual pages and use command flags, manage files withtouch,mkdir,cp,mv,rmandfile, get a first look at file ownership andsu, and tour the standard top-level directories. Two small flags are collected along the way.
| Platform | TryHackMe |
| Category | Fundamentals |
| Difficulty | Easy |
| Room | Linux Fundamentals Part 2 |
| Target IP | MACHINE_IP |
Task 1 — Introduction
A short orientation: this part adds remote access over SSH and a wider set of everyday commands. Nothing to answer.
Task 2 — Accessing Your Linux Machine Using SSH
SSH (Secure Shell) gives you an encrypted terminal on a remote machine and is how Linux servers are administered in the real world. Deploy the machine, then connect from your own terminal (the AttackBox or your VPN-connected host) with the credentials given by the room, tryhackme / tryhackme:
ssh tryhackme@MACHINE_IP
On the first connection SSH shows the server's host key fingerprint and asks you to confirm it. Answering yes stores the key in ~/.ssh/known_hosts, so that later connections can detect a server being impersonated. In a real engagement you would compare the fingerprint through a trusted channel instead of accepting blindly. After entering the password you land on an Ubuntu 20.04 shell with the prompt tryhackme@linux2:~$, and the task is complete.
Q: I've logged into the Linux Fundamentals Part 2 machine using SSH.
A: no answer needed (submit to complete the task)
Task 3 — Introduction to Flags and Switches
Most commands accept options, called flags or switches, that change their behaviour: short ones such as -l and long ones such as --all. The authoritative reference for them is the manual page, opened with man:
man ls
Inside the pager, the arrow keys (or j/k) scroll, /word searches, n jumps to the next match and q quits. The page lists, among many others:
-a, --all do not ignore entries starting with .
-h, --human-readable with -l and -s, print sizes like 1K 234M 2G etc.
Combining them, ls -lah shows a long listing including hidden files with readable sizes. Hidden files on Linux are simply those whose names start with a dot, which is why -a is a staple when hunting for configuration files.
Q: What directional arrow key would we use to navigate down the manual page?
A: down
Q: What flag would we use to display the output in a "human-readable" way?
A: -h
Task 4 — Filesystem Interaction Continued
| Command | Purpose |
|---|---|
touch | Create an empty file (or update the timestamp of an existing one). |
mkdir | Create a directory. |
cp | Copy a file; the original stays. |
mv | Move a file, or rename it if the destination is a new name in the same place. |
rm | Delete a file (add -r for directories). There is no recycle bin, so use with care. |
file | Identify a file's type from its content, not its extension. Useful when a file has no extension or a misleading one. |
touch newnote
file unknown1
mv myfile myfolder/
cat myfolder/myfile
unknown1: ASCII text
Q: How would you create the file named "newnote"?
A: touch newnote
Q: What is the file type of "unknown1" in tryhackme's home directory?
A: ASCII text
Q: How would we move the file "myfile" to the directory "myfolder"?
A: mv myfile myfolder
Q: What are the contents of this file?
A: FLAG
Task 5 — Permissions 101
Every file has an owner, a group and a set of read/write/execute permissions. ls -l shows them:
ls -l important
-rw-r--r-- 1 user2 user2 14 May 5 2021 important
Reading left to right: the first character is the type (- regular file), then owner, group and others permissions (rw-, r--, r--), then link count, owner (user2), group (user2), size, date and name. Here everyone can read the file, but the room is also showing the usual way to act as another user: su (switch user), which asks for that user's password. The room says it is user2.
su user2
cat important
Note thatsu user2without a dash keeps the current environment and working directory, whereassu - user2starts a full login shell as that user. Either is enough for this room.
Q: Who is the owner of "important"?
A: user2
Q: What would the command be to switch to the user "user2"?
A: su user2
Q: Output the contents of "important". What is the flag?
A: FLAG
Task 6 — Common Directories
Linux has a standard layout under /. The ones the room highlights, and that you will visit constantly during CTFs and incident response, are:
| Directory | Contents | Why it matters |
|---|---|---|
/etc | System-wide configuration files | Service configs, passwd, shadow, sudoers; frequent source of misconfigurations and credentials. |
/var | Variable data written by services | Includes /var/log (logs) and web roots, spools and databases. |
/root | Home directory of the root user | Not under /home; only root can normally read it. |
/tmp | Temporary files, writable by everyone | Cleared on reboot or periodically; attackers like it for dropping tools because any user can write there. |
The room compares /tmp to RAM only in the sense that its contents do not persist after a restart (on some systems it really is a memory-backed filesystem).
Q: What directory path would we expect logs to be stored in?
A: /var/log
Q: What root directory is similar to how RAM on a computer works?
A: /tmp
Q: Name the home directory of the root user.
A: /root
Key takeaways
- SSH is the standard remote shell; it verifies the server via a host key and encrypts the session.
- When unsure about an option, read
man <command>rather than guessing.-aand-hmakelsfar more informative. touch,mkdir,cp,mv,rmcover basic file management;filetells you what something really is.ls -lreveals owner, group and permissions, andsuswitches identity when you have the credentials.- Know the key directories: configuration in
/etc, logs in/var/log, root's home in/root, scratch space in/tmp.