đź”— Link to the Room
🏷️ Table of Contents
- Introduction
1.1 What is SSH? - Introduction to Flags and Switches
2.1 The Manual Page - Filesystem Interaction Continued
3.1 Creating Files and Folders
3.2 Removing Files and Folders
3.3 Copying and Moving Files and Folders
3.4 Determining File Type - Permissions 101
5.1 Briefly: The Differences Between Users and Groups
5.2 Switching Between Users
5.3 Understanding File Permissions in Numeric Format
5.4 Converting Symbolic Permissions to Numbers
5.5 More Common Examples
5.6 Why This Matters - Common Directories
6.1 etc
6.2 var
6.3 root
6.4 tmp
Introduction
In this task, instead of using the in-browser terminal, we’re connecting to a remote Linux machine using SSH (Secure Shell).
What is SSH?
SSH is a way to remotely connect to another computer securely. It encrypts everything you type, so data traveling over the internet cannot be easily read by anyone else. Once the data reaches the remote machine, it is decrypted so the commands can run.
SSH allows you to run commands on a remote device as if you were sitting in front of it. All communication is encrypted, keeping your data safe over the internet.
SSH is like a secure remote control for a Linux machine.
It’s time for you to deploy your machines on thm.
Â
Introduction to Flags and Switches
Â
Many Linux commands can be extended with extra options, called flags or switches.
Flags are added to commands with a hyphen (e.g., -a) or two hyphens for long options (e.g., --all).
Without flags, commands run their default behavior.
Example: ls Command
lslists files in the current folder, hides hidden files by default.ls -ashows all files, including hidden ones that start with.like.hiddenfolder.
Most commands have a --help option, which lists all available flags and what they do: ls --help
Â
The Manual Page
Every Linux command has a manual page (man page) with full documentation.
Syntax example: man ls
The man page tells you what the command does, which flags are available and examples of usage.
Flags and switches let you control how commands behave, and man pages are your built-in guide to understand them.
Â
❓What directional arrow key would we use to navigate down the manual page?
down
❓What flag would we use to display the output in a "human-readable" way?
-h
Â
Filesystem Interaction Continued
Â
In Linux, you interact with files and folders using simple commands. Here’s a quick guide:
| Command | What It Does |
|---|---|
touch |
Create a blank file |
mkdir |
Create a new folder |
rm |
Remove a file or folder (use -R for folders) |
cp |
Copy a file or folder |
mv |
Move or rename a file/folder |
file |
Check the type of a file |
Â
Creating Files and Folders
To create a file use touch file_name
touch will create a blank file.
To edit file (add content) use commands like vi, nano or so.
To create a directory (new folder) use mkdir folder_name
mkdirliterally means make directory
Â
Removing Files and Folders
To remove file use rm file_name
To remove a folder recursively use option -R. Syntax example: rm -R directory_name
Â
Copying and Moving Files and Folders
To copy a file use cp followed by the name of the file you want to be copied, then followed by the name of the new copy.
To move a file use mv.
Note: mv will merge or modify the second file that you provide as an argument. You can use mv to rename a file (or folder).
You can move files into folders by providing the folder name as the second argument.
Example of renaming the file note2 to be named note3:
Â
Determining File Type
Linux files don’t always rely on extensions.
Use the file command to check what a file actually contains:
Â
❓How would you create the file named "newnote"?
touch newnote
❓On the deployable machine, what is the file type of "unknown1" in "tryhackme's" home directory?
ASCII text
❓How would we move the file "myfile" to the directory "myfolder"
mv myfile myfolder
❓What are the contents of this file?
THM{**********}
Â
Permissions 101
Â
In Linux, files and folders have permissions that control who can read, write, or execute them. Not all users can access all files, and permissions help keep your system secure.
Use ls -l or ls -lh to see files and their permissions:
The first column shows permissions:
r = read w = write x = execute
| Permissions are grouped into Owner | Group | Others. |
Â
Briefly: The Differences Between Users and Groups
a real-world context: the system user that runs a web server must have permissions to read and write files for an effective web application. However, companies such as web hosting companies will have to want to allow their customers to upload their own files for their website without being the webserver system user – compromising the security of every other customer.
Â
Switching Between Users
To switch to another user use su user_name
To switch to another user and inherit this user’s environment use su -l user_name
-l stands for --login
Â
Understanding File Permissions in Numeric Format
In Linux, every file and directory has a set of permissions that control who can read, write, or execute it. These permissions are often displayed in symbolic format, such as: rwxrwxrwx
| Section | Applies To | Example |
|---|---|---|
| First 3 | Owner | rwx |
| Next 3 | Group | rwx |
| Last 3 | Others | rwx |
Each letter represents a specific permission: r = read w = write x= execute
Â
Converting Symbolic Permissions to Numbers
Each permission has a numeric value:
| Permission | Value |
|---|---|
| Read (r) | 4 |
| Write (w) | 2 |
| Execute (x) | 1 |
To calculate the numeric value, we add the values together for each group.
![image]https://github.com/user-attachments/assets/7e6e5127-1b33-4f1c-9606-89cf6511ee0d)
Â
More Common Examples
| Symbolic | Numeric | Meaning |
|---|---|---|
| rwxr-xr-x | 755 | Owner can do everything, others can read and execute |
| rw-r–r– | 644 | Owner can read/write, others can only read |
| rwx—— | 700 | Only the owner has access |
Â
Why This Matters
Many commands like chmod use numeric permissions, for example chmod 750 system_overview.txt
This means:
- Owner: full access
- Group: read + execute
- Others: no access
Â
❓On the deployable machine, who is the owner of "important"?
user2
❓What would the command be to swich to the user "user2"
su user2
❓Output the contents of "important", what is the flag?
THM{**_*****}
Â
Common Directories
Â
Linux has several important root directories that store system, user, and temporary data.
etc
System Configuration - /etc is root directory is one of the most important root directories on your system.
- Contains system files used by the OS.
- Examples:
sudoerslists users/groups allowed to run commands as root.passwd&shadowstore user passwords in encrypted format (SHA512).
Â
var
Variable Data - /var stores frequently updated data from services and applications.
Log files are written in /var/log
Â
root
Root User Home - Home directory for the root user (superuser).
Different from /home, which is for regular users.
Â
tmp
Short for temporary, used for short-lived files. Cleared automatically on reboot. Any user can write here, useful for pentesting scripts or temporary storage.
Â
❓What is the directory path that would we expect logs to be stored in?
/var/log
❓What root directory is similar to how RAM on a computer works?
/tmp
❓Name the home directory of the root user
/root
Â