Ahmed Elghazaly
7 min readFeb 27, 2023

Linux Fundamentals Part 2 — TryHackMe

#Task1:-Introduction

Welcome to the second part of the reworked “Linux Fundamentals” series. We’ll be applying our knowledge from the first installment in this series.

#Task2:-Accessing Your Linux Machine Using SSH (Deploy)

Deploying Your Linux Machine then Deploying the TryHackMe AttackBox and
Using SSH to Login to Your Linux Machine.

#Task3 :-Introduction to Flags and Switches

In Linux, flags and switches are often used with command-line utilities to modify their behavior. These utilities are often called “commands” or “programs”, and they provide functionality for tasks such as managing files, manipulating text, or configuring system settings.

Flags are usually preceded by a single hyphen (-) and are used to modify the behavior of a command. For example, the “ls” command is used to list the contents of a directory, but you can modify its behavior using flags. For instance, the “-l” flag is used to display the contents of a directory in a long format, showing additional information about each file, such as permissions and ownership.

Switches, on the other hand, are usually preceded by two hyphens ( — ). They are used to enable or disable certain features of a command. For example, the “grep” command is used to search for text within files, and the “ — ignore-case” switch is used to make the search case-insensitive.

Using our ls example, ls informs us that there is only one folder named "folder1" as highlighted in the screenshot below. Note that the contents in the screenshots below are only examples.

However, after using the -a argument (short for --all), we now suddenly have an output with a few more files and folders such as ".hiddenfolder". Files and folders with "." are hidden files.

the "--help" option is used to display a brief help message or usage information.
The "--help" option is often the first place to look when you are trying to learn how to use a new command or program. It can help you quickly understand the available options and how to use them effectively.

example of how to use it

The Man(ual) Page

To access this documentation, we can use the man command and then provide the command we want to read the documentation for. Using our ls example, we would use man ls to view the manual pages for ls like so:

Questions:-

1-What directional arrow key would we use to navigate down the manual page?

Answer →down

2-What flag would we use to display the output in a “human-readable” way?

Answer →-h

#Task4: -Filesystem Interaction Continued

In this task, we’re going to learn some more commands for interacting with the filesystem to allow us to create, move, copy, delete files.

touch →Create file.

mkdir →Create a folder.

cp →Copy a file or folder.

mv → Move a file or folder.

rm →Remove a file or folder.

file →Determine the type of a file.

the touch command is used to create file, here in this example

touch tryhackme.txt →this command will create file named “tryhackme.txt”

the mkdir command is used to create directory, here in this example

mkdir mydirectory→this command will create directory named “mydirectory”

the “cp” command is used to copy files and directories from one location to another. The name “cp” stands for “copy.”

he basic syntax for the “cp” command is:$cp source_file destination_file

for example in the screenshot below we will create copy of “test.txt” in the Picture directory

the mv command used to move or rename files and directories. The name “mv” stands for “move.”

The basic syntax for the “mv” command is:$mv source_file destination_file

for example , in the screenshot below, we are renaming the file “note2” to be named “note3”. “note3” will now have the contents of “note2”.

“rm” command is extraordinary out of the commands that we've covered so far. You can simply remove files by using “rm”. However, you need to provide the -R switch alongside the name of the directory you wish to remove.

for example, in the screenshot below, we are removing the file named test.txt.

the “file” command is used to determine the type of a file.

The “file” command reads the contents of a file and uses the information to identify the file type and format.

Questions:-

1-How would you create the file named “newnote”?

Answer →touch newnote

2–On the deployable machine, what is the file type of “unknown1” in “tryhackme’s” home directory?

Answer →ASCII text

3-How would we move the file “myfile” to the directory “myfolder”

Answer →mv myfile myfolder

4-What are the contents of this file?

Answer →THM{FILESYSTEM}

Task5:- Permissions 101

A file or folder can have a couple of characteristics that determine both what actions are allowed and what user or group has the ability to perform the given action — such as the following:

  • Read
  • Write
  • Execute

Using “ls -lh” to list the permissions of all files in the directory

Briefly: The Differences Between Users & Groups:

users and groups are both important concepts for managing file and directory permissions and controlling access to system resources on Linux. Users are individual accounts with unique identities, while groups are collections of users with shared permissions.

Switching Between Users:

On Linux, you can switch between users in several ways, depending on your needs and the privileges of the users involved.

The “su” command stands for “switch user” and allows you to switch to another user account by entering their password. By default, “su” will switch to the root user if no username is specified.

for example,in the screenshot below, when using “su”to switch to "user2", our new session drops us into our previous user's home directory.

Questions:-

1-On the deployable machine, who is the owner of “important”?

Answer →user2

2-What would the command be to switch to the user “user2”?

Answer →su user2

3-Output the contents of “important”, what is the flag?

Answer →THM{SU_USER2}

#Task6:-Common Directories

Here are some Common Directories, but not all!

1-/etc: This directory contains configuration files for the system and various programs and services, such as the “passwd” and “hostname” files.

2-/var: This directory contains variable data files that change frequently, such as log files, temporary files, and print spools.

3-/root: This directory is the home directory for the root user.

Unlike the /home directory, the /root folder is actually the home for the “root” system user. There isn’t anything more to this folder other than just understanding that this is the home directory for the “root” user. But, it is worth a mention as the logical presumption is that this user would have their data in a directory such as “/home/root” by default.

4-/tmp: This directory contains temporary files created by the system and user applications.

Questions:-

1-What is the directory path that would we expect logs to be stored in?

Answer →/var/log

2-What root directory is similar to how RAM on a computer works?

Answer →/tmp

3-Name the home directory of the root user

Answer →/root

#Task7:- Conclusions and Summaries

Nice work! This room was quite theory-heavy and covered quite a range of the fundamentals in getting you familiar with Linux. To quickly recap, this room taught you:

  • How to connect to a Linux machine remotely using SSH
  • Advancing your use of commands by providing flags, switches and where you can go to learn about these for each command (man pages)
  • Some more commands that you’ll frequently be using to interact with the filesystem and its contents
  • A brief introduction to file permissions & switching users
  • A summary paragraph of the important root directories on a Ubuntu Linux install and how we may be able to use the data stored within these.

I encourage you to go through this room again once or twice to gain some familiarity with the concepts. After all, practice makes perfect!

#Task8:-Linux Fundamentals Part 3

Visit part three of the Linux fundamentals series here! https://tryhackme.com/room/linuxfundamentalspart3

My writeup for linux fundamental part1 click here

Thanks for reading! I hope you learned well from these writeup.