0% found this document useful (0 votes)
163 views

SEC201.2 Linux Fundamentals

This document covers Linux fundamentals including installing Linux, common commands, environment variables, setting up a web server, and common beginner pitfalls. It includes sections on the Linux directory structure, hidden files, symlinks, users and groups, permissions, processes, and many terminal commands.

Uploaded by

fransiscu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
163 views

SEC201.2 Linux Fundamentals

This document covers Linux fundamentals including installing Linux, common commands, environment variables, setting up a web server, and common beginner pitfalls. It includes sections on the Linux directory structure, hidden files, symlinks, users and groups, permissions, processes, and many terminal commands.

Uploaded by

fransiscu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 213

||||||||||||||||||||

SEC201.2 Intro to Computer Fundamentals

Linux Fundamentals

©2017 James Lyne | Version C01_01

ir
All Rights Reserved

.
01
This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Day Two Intro

• In day two of this course we will cover enough of Linux


fundamentals to give you a solid start
• You will learn to install Linux
• You will learn about common Linux commands
• You will understand where environment variables are stored
• You will setup your own web server
• And finally we will cover common beginner pitfalls and how to
resolve them

. ir
SEC201 | Intro to Computer Fundamentals 2

01
Day 2 Intro

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

TABLE OF CONTENTS (1) PAGE

What Is Linux? 10

Linux Uses 12

Linux Distributions 13

LAB: Installing Linux 14

Linux – Key Points 50

Directory Structure 51

Hidden Files 57

Symlinks 58

Linux Users & Groups 59

Linux Permissions 60

Linux Permissions – The Long Way 61

ir
Linux Permissions – The Short Way 62

.
SEC201 | Intro to Computer Fundamentals 3

01
This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

TABLE OF CONTENTS (2) PAGE

Linux Permissions – The Shorter Way 65

Linux Processes 66

Linux Terminal 67

Linux Terminal - Environment Variables 68

Linux Terminal – Tab Completion 69

Linux Terminal – Previous Commands 70

Linux Terminal – Important Symbols 71

Linux Terminal – Parameters 73

Linux Terminal – Running Programs 74

Linux Terminal – Exiting a Running Program 75

Linux Terminal – Backgrounding a Task 76

ir
LAB: Mini-Lab Setup 77

.
SEC201 | Intro to Computer Fundamentals 4

01
This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

TABLE OF CONTENTS (3) PAGE

Linux Terminal – Commands - echo 86

Linux Terminal – Commands - ls 89

Linux Terminal – Commands - pwd 92

Linux Terminal – Commands - cd 94

Linux Terminal – Commands - hostname 97

Linux Terminal – Commands - cp 99

Linux Terminal – Commands - mv 101

Linux Terminal – Commands - less 103

Linux Terminal – Commands - cat 105

Linux Terminal – Commands - rm 107

Linux Terminal – Commands - find 110

ir
Linux Terminal – Commands - grep 113

.
SEC201 | Intro to Computer Fundamentals 5

01
This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

TABLE OF CONTENTS (4) PAGE

Linux Terminal – Commands - which 115

Linux Terminal – Commands - man 117

Linux Terminal – Commands - apropos 119

Linux Terminal – Commands - strings 121

Linux Terminal – Commands - nano 124

Linux Terminal – Commands - vim 127

Linux Terminal – Commands - top 131

Linux Terminal – Commands - ps 133

Linux Terminal – Commands - history 136

Linux Terminal – Commands - diff 138

Linux Terminal – Commands - wget 140

ir
Linux Terminal – Commands - chmod 142

.
SEC201 | Intro to Computer Fundamentals 6

01
This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

TABLE OF CONTENTS (5) PAGE

Linux Terminal – Commands - ln 144

Linux Terminal – Commands - chown 146

Linux Terminal – Commands - sudo 148

Linux Terminal – Commands - su 150

Linux Terminal – Pipes 151

Linux Terminal – Redirects 157

Linux – Installing Programs 161

Linux – Package Managers 163

Linux – apt-get 164

Linux – yum 165

Linux – dpkg 166

ir
Linux – rpm 167

.
SEC201 | Intro to Computer Fundamentals 7

01
This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

TABLE OF CONTENTS (6) PAGE

Linux – Compiling from Source 168

LAB: apt-get 169

LAB: dpkg 171

LAB: compile Nmap 174

Linux – Networking 181

Linux – Scheduled Tasks 186

Linux – XWindows 189

LAB: Linux – Setting up a Web Server 191

Linux Troubleshooting – Can’t run a binary executable 202

Linux Troubleshooting – Compiling an executable manually fails 203

Linux Troubleshooting – I’m typing a command but it says it can’t be found 204

ir
Linux Troubleshooting – I’m sure I ran an update but nothing has changed 205

.
SEC201 | Intro to Computer Fundamentals 8

01
This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

TABLE OF CONTENTS (7) PAGE

Linux Troubleshooting – Network service won’t start 206

Linux Troubleshooting – I don’t know what type of file this is 208

Linux Tips – .bashrc 209

EXERCISE: Linux – Installing Arch Linux (Optional Out of Class Exercise) 212

. ir
SEC201 | Intro to Computer Fundamentals 9

01
This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

What Is Linux? (1)

• The name for a group of operating systems that use the Linux
kernel as the core of the OS
• Many distributions of Linux that have been customized for
different purposes
• Some are server distributions with no Graphical User Interface
designed for efficiency
• Others are desktop distributions with a built in Graphical User
Interface. Many of them have been customized to make Linux
easier.

. ir
SEC201 | Intro to Computer Fundamentals 10

01
What Is Linux? (1)

Linux is a name for a group of operating systems that use the Linux kernel as the core of the operating system. Linux was based on Unix;

de
however, where Unix was proprietary and had to be licensed, Linux is open-source software. Linux is fragmented into ‘distributions’, many of
which have specialized functions; however, they all use the Linux kernel. The Linux kernel was originally written by Linus Torvalds; however, it
is now being maintained by the open-source software community.
hi
Linux distributions are often separated into desktop releases and server releases. A desktop release often comes with software pre-installed and,
most notably, a Graphical User Interface (GUI) of some sort is included. Traditionally even desktop releases have been quite difficult for non-
technical users to work with; however, more recently there has been a big push to lower the barrier to entry for Linux with distributions such as
Ubuntu and Elementary OS, making it easier than ever for non-technical users to utilize Linux. On the other hand, server releases often come with
minimal software pre-installed and even lack a Graphical User Interface. This means that server distributions are more efficient; however, the lack
of a GUI means that you have to master the command line.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

What Is Linux? (2)

• Linux operating systems are free and open-source


• Typically considered to be more difficult to use than Windows or
OS X, however recently many distributions have made significant
usability improvements
• Runs very well even on minimal hardware
• Extremely customizable: there are few if any restrictions on what
you can make it do
• The other side of the coin is that it’s easy to break something by
mistake. There are few safety checks which will prevent you from
breaking the operating system.

. ir
SEC201 | Intro to Computer Fundamentals 11

01
What Is Linux? (2)

Linux is typically more difficult to use than other operating systems, such as Windows and Mac. On the other hand, Linux runs extremely well on

de
even old hardware. Furthermore, Linux is highly customizable and there are very few restrictions on what a user can do. Of course, that also
means it’s very easy to break a Linux install if you don’t know what you are doing.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Uses

• Widely used as a server operating system as a result of its efficiency


• Desktop distributions are less widely used in general
• However, desktop distributions are extremely important for this
industry
• The majority of all security tools are developed first for Linux, so
get used to using it!

. ir
SEC201 | Intro to Computer Fundamentals 12

01
Linux Uses

Linux is widely used as a server operating system for two main reasons. First of all, Linux runs extremely well on just about any hardware, which

de
means it’s much more efficient at using the resources that are available. Secondly, server distributions are even more efficient because they don’t
include any unnecessary software, even down to not having a graphical user interface (which of course is unnecessary for a server).

On the other hand, Linux is less widely used as a desktop operating system. However, the security community uses Linux desktop distributions
hi
extensively. This is precisely because of how customizable Linux is. Most security tools are developed first for Linux; some of them are then
ported to other operating systems, however not all. You will always need to have a Linux install available to you.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Distributions

• There are many different distributions on Linux. The two main


types to be aware of are:
• Debian-based distributions
• Fedora-based distributions
• Debian is a distribution of its own, however many other
distributions use it as a base and build on top of it. Therefore,
much of the functionality across Debian-based distributions is the
same.
• Similarly, Fedora is a distribution of its own. It’s also frequently
used as a base by other distributions.

. ir
SEC201 | Intro to Computer Fundamentals 13

01
Linux Distributions

There are many Linux distributions floating around. Many of them even have a specific purpose, such as Kali Linux: a security-focused Linux

de
distribution that comes with many security tools pre-installed. Originally, many Linux distributions were built from scratch around the Linux
kernel, however more and more distributions started to appear based on existing Linux distributions instead. This has evolved to the point where
there are two main ‘base’ distributions, which most other distributions are built from. This is actually a good thing, as it simplifies the learning of
each distribution. It’s much easier to learn one of the base distributions, as most of your knowledge can then apply to other distributions, which are
hi
based on those. Take, for example, Ubuntu, a relatively famous Linux distribution. It was originally built from Debian. It shares many
commonalities with Debian, to the extent where if you know how to use Debian, you know nearly everything you need to know about Ubuntu.

The two main base distributions are Debian and Fedora. They are quite different from each other and most people have a preference one way or
the other. If you learn one of these base distributions you should be able to sit down at any Linux distribution based on them and be able to work it
to a reasonable degree.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (1)

• We have provided a net install version of Debian to practise


installation
• The net install is a smaller file because it relies on an internet
connection to download necessary files
• If you don’t have an internet connection or the installation is too
slow due to internet speed, we have provided an image of the
installed virtual machine with the course material.
• For the pre-made virtual machine, the username is student201
and the password is student201
• The root password is: 201student

. ir
SEC201 | Intro to Computer Fundamentals 14

01
Lab: Installing Linux (1)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (2)

• Open VMware Player and


click on ‘Create a New Virtual
Machine’

. ir
SEC201 | Intro to Computer Fundamentals 15

01
Lab: Installing Linux (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (3)

• Select the Debian net install


ISO file as the installer disk

. ir
SEC201 | Intro to Computer Fundamentals 16

01
Lab: Installing Linux (3)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (4)

• Tell VMware about the


operating system you will be
installing…

. ir
SEC201 | Intro to Computer Fundamentals 17

01
Lab: Installing Linux (4)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (5)

• Name the virtual machine and


specify the location for the files
to be saved in

. ir
SEC201 | Intro to Computer Fundamentals 18

01
Lab: Installing Linux (5)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (6)

• Specify the maximum size for


the disk. Make sure you tell it
to split it

. ir
SEC201 | Intro to Computer Fundamentals 19

01
Lab: Installing Linux (6)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (7)

• Select ‘Customize Hardware’

.ir
SEC201 | Intro to Computer Fundamentals 20

01
Lab: Installing Linux (7)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (8)

• Change the memory to


1024 MB

ir
.
SEC201 | Intro to Computer Fundamentals 21

01
Lab: Installing Linux (8)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (9)

• Press ‘OK’ and the virtual


machine will be created. You
can find it in the library
section of VMware Player.
• Power it on

. ir
SEC201 | Intro to Computer Fundamentals 22

01
Lab: Installing Linux (9)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (10)

• Select the standard install


option by pressing ‘enter’

ir
.
SEC201 | Intro to Computer Fundamentals 23

01
Lab: Installing Linux (10)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (11)

• Navigate with the arrow keys


and press ‘enter’ to select an
option

. ir
SEC201 | Intro to Computer Fundamentals 24

01
Lab: Installing Linux (11)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (12)

ir
.
SEC201 | Intro to Computer Fundamentals 25

01
Lab: Installing Linux (12)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (13)

ir
.
SEC201 | Intro to Computer Fundamentals 26

01
Lab: Installing Linux (13)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (14)

ir
.
SEC201 | Intro to Computer Fundamentals 27

01
Lab: Installing Linux (14)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (15)

• Set the name of the computer


(hostname)

.ir
SEC201 | Intro to Computer Fundamentals 28

01
Lab: Installing Linux (15)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (16)

• Set the domain for the


network. For our purposes,
just use something.local

ir
.
SEC201 | Intro to Computer Fundamentals 29

01
Lab: Installing Linux (16)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (17)

• Establish the root password.


This is essentially the password
of the admin user

. ir
SEC201 | Intro to Computer Fundamentals 30

01
Lab: Installing Linux (17)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (18)

• Set the name for the non-


admin user

ir
.
SEC201 | Intro to Computer Fundamentals 31

01
Lab: Installing Linux (18)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (19)

ir
.
SEC201 | Intro to Computer Fundamentals 32

01
Lab: Installing Linux (19)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (20)

• Handle partitioning of the


disk. In a VM you can use the
whole disk, if you were
installing this on a live system
with dual boot you would
need to select manual here.

. ir
SEC201 | Intro to Computer Fundamentals 33

01
Lab: Installing Linux (20)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (21)

ir
.
SEC201 | Intro to Computer Fundamentals 34

01
Lab: Installing Linux (21)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (22)

ir
.
SEC201 | Intro to Computer Fundamentals 35

01
Lab: Installing Linux (22)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (23)

ir
.
SEC201 | Intro to Computer Fundamentals 36

01
Lab: Installing Linux (23)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (24)

ir
.
SEC201 | Intro to Computer Fundamentals 37

01
Lab: Installing Linux (24)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (25)

ir
.
SEC201 | Intro to Computer Fundamentals 38

01
Lab: Installing Linux (25)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (26)

ir
.
SEC201 | Intro to Computer Fundamentals 39

01
Lab: Installing Linux (26)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (27)

• If you are in an enterprise


which requires using a proxy
to make HTTP requests, you
need to configure the proxy
here
• For our purposes, it can stay
blank

. ir
SEC201 | Intro to Computer Fundamentals 40

01
Lab: Installing Linux (27)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (28)

ir
.
SEC201 | Intro to Computer Fundamentals 41

01
Lab: Installing Linux (28)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (29)

ir
.
SEC201 | Intro to Computer Fundamentals 42

01
Lab: Installing Linux (29)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (30)

• This screen is the most important


one. You will need a GUI, so use the
arrow keys to go to GNOME and
press ‘space’ to select it.
• It is selected if you see an [*]
next to it
• You can de-select the print
server
• Then select SSH server
• Press tab until ‘Continue’ is selected

ir
• Then press ‘enter’ to continue

.
SEC201 | Intro to Computer Fundamentals 43

01
Lab: Installing Linux (30)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (31)

ir
.
SEC201 | Intro to Computer Fundamentals 44

01
Lab: Installing Linux (32)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (33)

• The boot loader is responsible


for starting the OS at boot. In a
VM, it’s safe to just press ‘Yes’.
• You probably shouldn’t do this
if you plan to dual boot on a
real system though

. ir
SEC201 | Intro to Computer Fundamentals 45

01
Lab: Installing Linux (33)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (34)

ir
.
SEC201 | Intro to Computer Fundamentals 46

01
Lab: Installing Linux (34)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (35)

ir
.
SEC201 | Intro to Computer Fundamentals 47

01
Lab: Installing Linux (35)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (36)

ir
.
SEC201 | Intro to Computer Fundamentals 48

01
Lab: Installing Linux (36)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Lab: Installing Linux (37)

• This is VERY IMPORTANT!


• Don’t delete the VM, we’ll be using it again later today!
• You can shut it down for now if you want, however

. ir
SEC201 | Intro to Computer Fundamentals 49

01
Lab: Installing Linux (37)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Key Points

• There are some things you should keep in mind about Linux:
• Linux is case sensitive. Two files called ‘File’ and ‘FILE’ are completely
different.
• In Linux, everything is a file. A file is a file, a folder is a file (that references
other files), a USB drive is a file, even a mouse is considered to be a file.
This will make more sense later, just bear it in mind!
• In Linux, the superuser account called ‘root’ is allowed to do absolutely
anything. Most distributions now force you to run as a normal user and
you have to elevate your privileges to the ‘root’ level temporarily when you
need to.

. ir
SEC201 | Intro to Computer Fundamentals 50

01
Linux – Key Points

You should be aware of several key points in Linux that might become stumbling blocks for you.

de
Linux is case sensitive. This is a common mistake because Windows is not case sensitive. On Linux, two files called ‘File’ and ‘FILE’ are
separate files entirely. If you type ‘File’ when meaning to access ‘FILE’ then you will be accessing the wrong file.
hi
In Linux, everything is represented as a file. This may seem weird, but take a look into the ‘/proc’ directory and you will see each process running
on the computer is represented as a file in that directory. You might also look into the ‘/dev’ directory where you will see every hardware device
connected to the computer (including hard disks) is represented as a file. Even folders are just files with references to the files contained within
them.

In Linux, usually, you run as a normal ‘un-privileged’ user. This user will be restricted from doing certain things such as installing software,
adding user accounts and so on. To do things that require privileges you must switch over to the ‘root’ account. Root is the ‘superuser’ account
and is allowed to do absolutely anything on the computer. Keep in mind that ‘root’ is dangerous if you’re not sure what you’re doing. You will be
allowed to do anything including deleting critical system files or even erasing the entire hard drive and you usually won’t be warned or prompted
to make sure you want to proceed. Most modern Linux distributions will not tell you what the ‘root’ password is to prevent you from logging in to
it directly. It’s much better practice to do everything as a normal user and temporarily elevate your privileges to root as necessary.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Directory Structure (1)

• In Linux, the directory structure starts at ‘/’. This is the ‘root’ of the
filesystem or the top level if you prefer.
• Within ‘/’ there are several folders. We will go through them one by
one.
• ‘/bin’ contains executable binary files, which are programs that
come with the operating system
• ‘/boot’ holds files that are important during the boot process,
including the Linux kernel itself

. ir
SEC201 | Intro to Computer Fundamentals 51

01
Directory Structure (1)

In Linux, the directory structure starts at ‘/’ which represents the ‘root’ of the filesystem or the top level of the file system. Remember, ‘root’ is the

de
starting point, the base that everything else is built on.

From the root, we have several directories. There is no way to enforce the usage for each of the directories but we will cover what they are
typically used for.
hi
/ - The root of the file system.
/bin – Typically contains binary executable files that come with the operating system.
/boot – Typically holds files that are important to the boot process, including the Linux kernel itself.
/dev – Contains the devices that are connected to the system, such as the hard disks, keyboard, mouse, etc.
/etc – Typically contains application configuration files.
/home – Typically contains the home directories of users on the system (except for the home directory of the root account).
/lib – Contains library files and kernel modules which are required by the operating system.
/media – Contains media devices that are connected to the OS, such as CD-ROMs and DVDs.
/mnt – Contains the files of any file system mounted to the operating system (such as hard disks, USB devices, etc).
/opt – Opt stands for ‘optional’. The user can decide what to put in here. It is commonly used to store binary executable files that do not come
with the operating system.
/proc – Contains files that represent each process running on the OS currently.
/root – The home directory for the ‘root’ account. This is the only one that is not in /home by default.
/sbin – Similar to /bin, it is typically used for binary executable files that come with the operating system.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

/tmp – The temporary directory. Anything can write to it but files here are meant to be temporary. The files in /tmp are deleted periodically and after a
reboot.
/usr – Typically contains binary executable programs, libraries and source code for the normal user level accounts.
/var – Typically contains log files and lock files (to tell if a file is being used or not).

. ir
01
de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

As with many things on Linux, nothing is forcing you to use these conventions. You could put your programs into /var if you want, but it isn’t
recommended. Knowing the directory structure will help you to understand the most likely places to find things on the file system; however, not
everyone follows these conventions so you may need to do some searching around.

. ir
01
de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Directory Structure (2)

• ‘/dev’ contains the devices that are connected to the Linux system.
(Remember, devices are files so they have to be somewhere!)
• ‘/etc’ contains application configuration files
• ‘/home’ contains the home directories of users on the system
• ‘/lib’ contains library files and kernel modules which are required
by the operating system
• ‘/media’ contains the media devices that are connected to the Linux
system (such as CD-ROMS)

. ir
SEC201 | Intro to Computer Fundamentals 53

01
Directory Structure (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Directory Structure (3)

• ‘/mnt’ contains the filesystem files


• ‘/opt’ stands for ‘optional’. The user can decide what to put in there
but typically it’s used for third party applications.
• ‘/proc’ contains files for every running process (Again, everything is
a file so processes are files)
• ‘/root’ is the home directory of the root user. Not to be confused
with ‘/’, which is the root of the filesystem.
• ‘/sbin’ is similar to ‘/bin’. It contains binary programs required by
the operating system.

. ir
SEC201 | Intro to Computer Fundamentals 54

01
Directory Structure (3)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Directory Structure (4)

• ‘/tmp’ contains temporary files. This directory is cleared out


periodically and after a reboot.
• ‘/usr’ contains executable binary programs, source code and
libraries for user-level programs
• ‘/var’ typically contains log files and lock files

. ir
SEC201 | Intro to Computer Fundamentals 55

01
Directory Structure (4)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Directory Structure (5)

• The directory structure is just a guide. Like anything on Linux, it’s


completely customizable.
• If you want to install your programs into /var you can! (Not
recommended.)
• The directory structure is still good to know, as most people follow
these conventions and it will help you to navigate the filesystem

. ir
SEC201 | Intro to Computer Fundamentals 56

01
Directory Structure (5)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Hidden Files

• Hidden files and folders have a ‘.’ at the start of their name
• You can create a hidden file by calling it something that starts with
a ‘.’
• Hidden files can be viewed with the right command, described later

. ir
SEC201 | Intro to Computer Fundamentals 57

01
Hidden Files

On Linux, hidden files are denoted with a period (‘.’) at the start of the file name. This makes the file invisible to normal viewing, although it can

de
still be viewed using the right commands or by changing your file explorer software settings to be able to view hidden files on a GUI.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Symlinks

• There is a special type of file called a ‘symlink’. It stands for


‘symbolic link’.
• It’s just an alias and is a reference to the actual file that is stored
somewhere else on the system
• You can delete a symlink without deleting the original file but if you
open the file up in an editor any changes you make will be made to
the original file also
• This is because when you open it in an editor, the file you are
opening is the original file
• The symlink file just tells the editor that it should be opening this

ir
file here instead

.
SEC201 | Intro to Computer Fundamentals 58

01
Symlinks

A symlink is a ‘symbolic link’. It is a way of creating a file that references another file, similar to a shortcut in Windows. Referencing a symlink is

de
the same as referencing the file it is linked to. For example, if you write some data to a symlink of a file, you will be writing to the original file
itself. You can, however, delete a file which is a symlink without deleting the original file.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Users & Groups

• Most distributions come with a lot of users already set up. Only one
of these is meant for use by a user
• The other users can’t be used for logging in and are instead used by
software that runs on the operating system
• Each user belongs to a group
• Groups are just for organising ‘permissions’: essentially, which user
is allowed to do what

. ir
SEC201 | Intro to Computer Fundamentals 59

01
Linux Users & Groups

Linux distributions use a permissions scheme to specify who has access to which files. Users can be put into groups as a way of controlling who

de
can access which files. Most distributions come with several groups already set up, such as the ‘wheel’ group. Root is able to create new groups
and also add users to groups.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Permissions

• Each file in Linux has three sets of permissions. The first set is
‘Owner’ which is the set that applies to the owner of the file.
• This is typically the person who created the file but it can be
changed (more on that later)
• The next set is ‘Group’, which is the set that applies to a user who
isn’t the Owner but is in the Group that owns the file. This can also
be changed.
• The last set is ‘Everyone’, which is the set of permissions that
applies to anyone that isn’t the Owner and isn’t in the matching
Group

. ir
SEC201 | Intro to Computer Fundamentals 60

01
Linux Permissions

Each file on Linux has three sets of permissions. The first set is ‘Owner’. These are the permissions that apply to the owner of the file (typically

de
the creator of the file, unless the owner was specifically changed). The next set of permissions is ‘Group’. This is the set of permissions that apply
to whoever is in the group that owns the file. This is typically the group that the user who created the file was in but, again, it can be changed. The
last set of permissions is for ‘Everyone’. This set of permissions applies to everyone who isn’t the owner or the group.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Permissions – The Long Way

• You may see permissions written like so:


• rwxr-xr--
• ‘x’ stands for execute, ‘w’ stands for write and ‘r’ stands for read. A
dash means that the permission isn’t set.
• Starting from the left, the first three are for the Owner, the second
three are for the Group and the last three are for everyone else.
• In this case, the Owner can read, write and execute the file. The
Group can only execute and read and everyone else can only read
the file.

. ir
SEC201 | Intro to Computer Fundamentals 61

01
Linux Permissions – The Long Way

You will often see Linux permissions written like so:

rwxr-xr--
de
The first three letters are for the Owner. The next three are for the group and the last three are for everyone. ‘r’ stands for read, ‘w’ stands for
hi
write and ‘x’ stands for execute. Finally, a ‘-’ means no permission was set in that space. Taking the first example, the Owner of the file can read,
write and execute the file. Anyone in the group that owns the file can read and execute the file, but not write to it. Finally, everyone else can read
the file, but not write to it or execute it.

Writing permissions like this is the long form. You will see it frequently, specifically when you list the files in a directory.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Permissions – The Short Way (1)

• You may also hear people talk about setting permissions to ‘755’,
for example. This is a shorthand way of expressing permissions.
• Many people struggle with how to calculate this, but it’s actually
quite simple. You’ll need to know your binary though.
• Each set of permissions is represented by one digit, so the Owner is
7, the Group is 5 and Everyone is 5
• 7 in binary is 111. Notice that there are three digits in binary and
there are three permissions, rwx. Each binary digit represents one
of the permissions. A 1 means that permission is enabled, a 0
means it is disabled.

. ir
SEC201 | Intro to Computer Fundamentals 62

01
Linux Permissions – The Short Way (1)

Linux permissions can also be expressed as a numerical value such as 755. This is considered shorthand, but you will need to know it specifically

de
when it comes to setting permissions on files. Many people struggle with calculating permissions like this, but it’s actually simple when you have
a background in counting in binary, as you should already do.

Simply put, each set of permissions is represented by a single digit. So in the case of ‘755’ the ‘7’ represents the Owner’s permissions, the first ‘5’
hi
represents the Group’s permissions and finally the last ‘5’ represents everyone else’s permissions. Let’s look more closely at the first ‘7’, the
Owner’s permission.

7 in Binary is written: 111. Notice that the binary representation has three digits. Each of these digits represents whether a permission is on or off.

rwx
111

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Permissions – The Short Way (2)

OWNER GROUP EVERYONE


r w x r w x r w x
1 1 1 1 0 1 1 0 1
7 5 5

• Owner can read, write and execute


• Group can read and execute, but not write
• Everyone can read and execute, but not write

. ir
SEC201 | Intro to Computer Fundamentals 63

01
Linux Permissions – The Short Way (2)

So we can see a 1 under ‘r’ means that read permissions are enabled, a 1 under ‘w’ means that write permissions are enabled and a 1 under ‘x’

rwx
101
de
means that execute permissions are enabled. So let’s look at 5 now. 5 in binary is 101.
hi
So in the case of 5, ‘read’ is enabled and ‘execute’ is enabled but ‘write’ is not enabled.

Ultimately, the permissions 755 means that the Owner can read, write and execute, but the Group and Everyone can only read and execute.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Permissions – The Short Way (3)

OWNER GROUP EVERYONE


r w x r w x r w x
1 1 1 1 0 0 0 0 0
7 4 0

• Owner can read, write and execute


• Group can read, but not write or execute
• Everyone can do nothing at all

. ir
SEC201 | Intro to Computer Fundamentals 64

01
Linux Permissions – The Short Way (3)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Permissions – The Shorter Way

• Just remember that:


• Read = 4
• Write = 2
• Execute = 1
• Then just add them up to get the final number for that permission
• For example:
• Read and Write but not Execute is: 4 + 2 = 6
• Write and Execute but not Read is: 2 + 1 = 3
• Read and Execute but not Write is: 4 + 1 = 5

. ir
SEC201 | Intro to Computer Fundamentals 65

01
Linux Permissions – The Shorter Way

There’s an even quicker way to calculate permissions in shorthand and that is just to remember that ‘read’ is worth 4, ‘write’ is worth 2 and

de
‘execute’ is worth 1. By adding up the values you want to set, you get an accurate result.

For example, ‘read’ and ‘execute’ would be 4 + 1 = 5. In binary ‘read’ and ‘execute’ is 101, which is 5 in denary, so we can see that this method
works. If you can’t remember the values, you can always calculate them from first principles by looking at the binary again.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Processes

• A process is just a running program


• On Linux, each process has an ID number associated with it
• A process is a file and the files live at ‘/proc’
• A process can have one of four states:
• Running – A running process is either running or ready to run
• Waiting – A waiting process is waiting for an event or resource to become
available
• Stopped – A stopped process is a process that has been stopped (e.g. if it
was stopped for debugging)
• Zombie – A zombie process is a dead process

. ir
SEC201 | Intro to Computer Fundamentals 66

01
Linux Processes

We already know that a process is just a running program. On Linux, each process has an ID associated with it and each process is represented by
a file that lives in ‘/proc’.

There are four states for processes:


de
hi
• Running – A running process is either running or ready to run.
• Waiting – A waiting process is waiting for an event or resource to become available.
• Stopped – A stopped process is a process that has been stopped (e.g. if it was stopped for debugging).
• Zombie – A zombie process is a dead process.

Often you will need to find the process ID of a process before you can terminate the process from the command line.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal

• The Linux Terminal is the most important interface the user can
have with the operating system
• Many times you will not even have a GUI and will have to work in
the terminal alone
• The terminal consists of a ‘shell’ program which is responsible for
interpreting your commands. Each shell has different features.
• A common default shell is the ‘bash’ shell. It supports features such
as tab-completion.

. ir
SEC201 | Intro to Computer Fundamentals 67

01
Linux Terminal

The Linux Terminal is by far the most useful and important interface the user can have within the Linux operating system. You can access it from

de
the ‘terminal’ application on desktop distributions but on server distributions, the terminal is all you get. It’s a purely text-based interface. Each
terminal has a ‘shell’ program which is responsible for interpreting your commands. There are many different types of shell and many people have
their own preferences but usually the default one is the bash shell. The bash shell has many useful features such as tab completion which allows
you to type something then press tab part of the way through to have the terminal automatically fill the rest in for you.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Environment Variables

• In Linux, data can be stored in environment variables. Generally


you can store any data in any environment variable.
• Some environment variables are established by default such as the
‘PATH’ environment variable. Environment variables are
referenced with the ‘$’ symbol. E.g. $PATH
• The PATH is important for the Linux Terminal, it consists of a
semi-colon separated lists of folder paths where the shell looks for
programs when you type a command
• For example, if you type ‘foo’ into the terminal, it will look for the
executable binary called ‘foo’ in all of the folders listed in the PATH

ir
in the order that they appear

.
SEC201 | Intro to Computer Fundamentals 68

01
Linux Terminal – Environment Variables

Environment variables are a way of storing data and giving that data a name so that it can be accessed later. Perhaps the most important

de
environment variable is the ‘PATH’ environment variable. Environment variables can be accessed by appending the $ symbol to the front, for
example, $PATH means ‘get the value in the environment variable PATH’. It’s important to note that environment variables are typically
temporary. Normally, the PATH environment variable is set to be loaded the first time the terminal starts. That means if you want to alter the
PATH and have it stay that way permanently then you need to alter the place that loads the PATH variable up the first time the terminal starts.
hi
This is typically in the configuration file of your shell program (such as .bashrc for the bash shell).

The PATH environment variable is a particularly important one: it consists of a semi-colon separated list of folder paths where the shell looks for
programs when you type a command. This means instead of typing /sbin/ls, for example, to access the ls command, you can simply type ‘ls’ on its
own and, as long as /sbin is in your PATH, the shell will look there for the command you typed. The PATH directory list is in order of priority,
therefore if you have two programs called ‘foo’, one in /sbin and one in /bin and they do different things, when you type ‘foo’, the executable file
in the first directory in the PATH will be the one that gets used.

If you type a command and it isn’t found but you know that it is installed somewhere, it’s likely that the directory it is installed in is not in the
PATH and therefore you need to add it.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Tab Completion

• In the Linux Terminal, most shells support tab completion. You can
complete a command or a folder name by pressing tab when you
are part of the way through typing it.
• This is a big time saver, however you should be aware that tab
completion will not work if there is more than one possible match
• For example, if you have typed fold and there are two folders,
folder1 and folder2, it wont know which one you want
• You can press tab twice quickly to get a list of possible matches

. ir
SEC201 | Intro to Computer Fundamentals 69

01
Linux Terminal – Tab Completion

Most shell programs you can use with the Terminal offer tab completion. This allows you to complete a command or folder name by pressing tab

de
when you are part way through typing it. This can save you a lot of typing, particularly if you are typing out a long folder path. You should know
that tab completion will not work if there is more than one possible match.

Say you have two folders in your current directory, ingeniously named ‘folder1’ and ‘folder2’. If you were typing ‘fold’ and then pressed tab,
hi
nothing would happen. That is because the terminal doesn’t know to match folder1 or folder2, both are possible matches. You can press tab twice
in quick succession to output a list of possible matches to your command, which is also quite useful.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Previous Commands

• Another big time saver is using the up and down arrows on the
keyboard to cycle through previous commands
• Be warned though that sometimes it’s faster to re-type a command
than cycling back through twenty or so commands to find one you
typed earlier
• The up arrow goes back through the command history and the
down arrow goes forward in the command history
• You can also perform a search on all your previous commands with
CTRL + r. This will allow you to type a partial command and get a
list of all previously typed commands that match. You can navigate

ir
the list with the up and down arrow keys.

.
SEC201 | Intro to Computer Fundamentals 70

01
Linux Terminal – Previous Commands

Another useful aspect to the terminal is the ability to cycle through previously typed commands and re-run them. You can use the up and down

de
arrow keys to cycle through previous commands. This is useful, but don’t fall into the trap of spending longer cycling through previous commands
when it might have been faster to type the command out from scratch. Luckily there is a method that is the best of both worlds: you can perform a
reverse command search using ctrl + r. This will allow you to type a partial command and then use the up and down arrows to cycle through
previous commands that match your partially typed command.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Important Symbols

• In the Linux Terminal there are some symbols which have special
meanings
• The ‘/’ symbol represents the root of the filesystem. It’s also the
character that separates folders in a file path. For example,
/home/username/Desktop. Whereas on Windows it’s a backslash
‘\’ that does it.
• The ‘~’ (tilde) symbol represents the home folder of the current
user
• The characters ‘..’ represent the folder one level higher in the
directory structure

ir
• The character ‘.’ represents the current directory

.
SEC201 | Intro to Computer Fundamentals 71

01
Linux Terminal – Important Symbols

In Linux, there are several symbols that are important to know.

de
/ – The forward slash represents the root of the filesystem. It also separates folders directories in a file path. For example:
/home/username/Desktop. The first slash is obviously the root of the file system. So from the root, we go to the home directory then the username
directory and then the Desktop directory.
hi
~ – The tilde symbol represents the home folder of the current user, so, for example, ~/Desktop will take you to /home/<<name of user>>/Desktop
.. – The ‘..’ characters represent the directory one level higher in the directory structure. For example, if you are in /home/username/Desktop and
you go to the ‘..’ folder, you will end up in /home/username.
. – The ‘.’ character represents the current directory

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Important Symbols

• The ‘./’ symbol means ‘execute the file in the current folder’
• The ‘*’ symbol (asterisk) is known as the wildcard symbol. This
means that it matches anything. For example, if you wanted to
match all the files in a folder that end in .jpg you could do: *.jpg.

. ir
SEC201 | Intro to Computer Fundamentals 72

01
Linux Terminal – Important Symbols

./ - The ‘./’ character means ‘execute the file in the current directory’. So, for example, ‘./find’ will execute the file called find that is in the current

directory.
de
directory. This is important because if you just type ‘find’ on its own, the shell will look in the PATH for a file called ‘find’ and not in the current

* - The asterisk symbol is known as the wildcard symbol. It matches anything. For example, if you wanted to list all files in a folder that end in
.jpg you could type: ls *.jpg. The wildcard would match any filename that ends in .jpg.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Parameters

• Many commands in Linux allow for parameters to be passed in


• Parameters are usually (but not always, it depends on the program)
preceded by either a – or a --
• Usually a – precedes a single letter parameter such as –h
• Usually a -- precedes a word parameter such as --help
• If there are multiple single letter parameters they can be written on
the same line. E.g. ‘ls –alth’
• If a program expects a parameter and isn’t given one it will either
perform some default behavior such as printing the help

ir
documentation or error and suggest you read the help

.
SEC201 | Intro to Computer Fundamentals 73

01
Linux Terminal – Parameters

Many terminal commands in Linux allow for additional parameters to be passed in that change or modify the way the command functions.

de
Parameters are usually, but not always preceded by a single dash (-) or double dash (--). Usually, a single dash (-) is used when the parameter is a
letter such as –h for the help menu. A double dash (--) is more commonly used when the parameter is a word, such as in --help.

Multiple single letter parameters can be written on the same dash, such as in ‘ls –alth’.
hi
If a program requires a parameter to function and you do not provide it, either an error message will be printed to the screen or the program will
perform some other default behavior such as printing the help menu for that command.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Running Programs

• If the binary executable you want to run is in the PATH, you just
have to type the name of the program to run it from wherever you
are
• If the program is not in the PATH and is saved somewhere else and
you want to run it, you need to use ‘./program’
• You can also do it from a remote directory using a longer path such
as: ‘./home/username/Desktop/program’

. ir
SEC201 | Intro to Computer Fundamentals 74

01
Linux Terminal – Running Programs

Running a program that is located somewhere in the PATH is as simple as typing the name of the file. On the other hand, if you want to run a

‘./home/username/Desktop/file’.
de
program that is in the current directory you need to use ‘./’ such as ‘./program’. You can also use a file path instead such as

If there is a conflict between the name of a program in the PATH and one elsewhere, be sure you use the right method when running the file or
hi
you may see unexpected behavior such as running the wrong program.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Exiting a Running Program

• Once a program is running, you can exit it and get back to the
prompt by pressing ‘ctrl+c’. This sends a terminate signal to end
the process
• It is not recommended you use this, unless there is no other way to
exit the program
• If the program allows you to exit by pressing ‘q’, for example, you
should do it the way the program wants
• Terminating a program with ‘ctrl+c’ is a last resort

. ir
SEC201 | Intro to Computer Fundamentals 75

01
Linux Terminal – Exiting a Program

To exit a running program from the terminal, you can use ctrl-c. This sends an interrupt signal to end the running process. This is a bit of a nuclear

de
option, so you should use this method only as a last resort. In some programs there may be a way to shut down the program gracefully, so be sure
to use that if it is available. For example, some programs let you exit if you press ‘q’.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Backgrounding a Task

• A running task can paused by pressing ctrl + z


• From this state, you can send the task to the background by typing
‘bg’ and pressing enter
• This will resume the task, but it will resume in the background
• You can then see all running background tasks with ‘jobs’
• You can bring a particular job to the foreground by typing ‘fg’
followed by the id of the job
• If you pressed ctrl + z by mistake as sometimes happens if you are
aiming for ctrl + c, then you can resume the task in the foreground

ir
by typing ‘fg’ on its own

.
SEC201 | Intro to Computer Fundamentals 76

01
Linux Terminal – Backgrounding a Task

A running task can be sent to the background so you can work on other things without having to create a new terminal window. This is

de
particularly useful if you are connecting to a remote server over SSH (Secure Shell) and you don’t want to have to create a new SSH session.

To do that, first, we have to pause the running task with ctrl + z. With the task paused, we can type ‘bg’ to resume the task in the background.
With the task running in the background, we can bring it back to the foreground by typing ‘jobs’ to list all the running background tasks. To bring
hi
a particular background task back to the foreground, you can type ‘fg’ followed by the id of the job.

If you pressed ctrl + z by mistake and didn’t intend to pause the task, you can resume it by typing ‘fg’ on its own.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Mini-Lab Setup (1)

• In the course materials, you should have a file called Slingshot.ova


• This is an open virtual machine format which is widely supported
by many types of virtualization software
• To use it, we will need to convert it into a VMware format

. ir
SEC201 | Intro to Computer Fundamentals 77

01
Linux Terminal – Mini-Lab Setup (1)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Mini-Lab Setup (2)

• Open VMware Player


• Go to File -> Open, then select the ova file

. ir
SEC201 | Intro to Computer Fundamentals 78

01
Linux Terminal – Mini-Lab Setup (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Mini-Lab Setup (3)

• Enter a name for the virtual machine


• Then specify the folder where the virtual machine will be saved
after it is converted

. ir
SEC201 | Intro to Computer Fundamentals 79

01
Linux Terminal – Mini-Lab Setup (3)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Mini-Lab Setup (4)

• The OVA will be converted. Wait for it to finish.

. ir
SEC201 | Intro to Computer Fundamentals 80

01
Linux Terminal – Mini-Lab Setup (4)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Mini-Lab Setup (5)

• When the process is finished, you should see the new virtual
machine in the VMware Player Library

• Right-click on it to bring up the following menu

• Then select settings

. ir
SEC201 | Intro to Computer Fundamentals 81

01
Linux Terminal – Mini-Lab Setup (5)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Mini-Lab Setup (6)

• With the settings window open,


select Memory and increase the
memory to a sensible default
• 1024 MB should be plenty
• Press OK to save the settings

. ir
SEC201 | Intro to Computer Fundamentals 82

01
Linux Terminal – Mini-Lab Setup (6)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Mini-Lab Setup (7)

• From the VMware Player Library, select the Slingshot Virtual


Machine
• Then press the green play icon to start it
• When the virtual machine boots, you should see a login screen
• Select the account SEC201. The password is: sec201.

. ir
SEC201 | Intro to Computer Fundamentals 83

01
Linux Terminal – Mini-Lab Setup (7)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Mini-Lab Setup (8)

• When the account loads, you will see an ‘activities’ icon in the top
left

• Select it, then select the terminal icon from the dock on the left

. ir
SEC201 | Intro to Computer Fundamentals 84

01
Linux Terminal – Mini-Lab Setup (8)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Mini-Lab Setup (9)

• With the terminal open, you are ready to walk through the mini-
labs in the next section

. ir
SEC201 | Intro to Computer Fundamentals 85

01
Linux Terminal – Mini-Lab Setup (9)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - echo (1)

• The ‘echo’ command just prints text to the screen


• For example: ‘echo hello’ will print hello to the terminal window
• Handy for use in shell scripts
• Typically also used for printing environment variables from the
terminal. E.g. ‘echo $PATH’ will print out the list of folders in the
PATH.
• The above example is particularly useful when you are trying to
find out why a program you installed can’t be found. This is usually
because it was installed into a folder not in the PATH.

. ir
SEC201 | Intro to Computer Fundamentals 86

01
Linux Terminal – Commands - echo (1)

The echo command just prints text to the screen. It’s used quite often in shell scripts to display output, but it’s also useful for printing the values of

de
environment variables. You could, for example, do echo $PATH to print the value of the PATH environment variable. That can be helpful when
you’re diagnosing why a program you installed can’t be found. Usually this will be because it was installed into a folder that isn’t in your PATH.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - echo (2)

• Open up the terminal in your Linux virtual machine and play with
the echo command a bit
• Try the following commands:
• $ echo hello world!
• $ echo $PATH
• $ echo $PS1
• $ echo $SHELL

. ir
SEC201 | Intro to Computer Fundamentals 87

01
Linux Terminal – Commands - echo (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - echo (3)

. ir
SEC201 | Intro to Computer Fundamentals 88

01
Linux Terminal – Commands - echo (3)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - ls (1)

• The ‘ls’ command stands for list


• It lists files and folders. On its own it lists folders in the current
working directory (the directory you’re in now).
• You can also pass in parameters such as the folder to list the
contents of. E.g. ‘ls /home’.
• There are other parameters that can be added such as ‘-l’, which
outputs the results in a more detailed view (stands for ‘long’
format)

. ir
SEC201 | Intro to Computer Fundamentals 89

01
Linux Terminal – Commands - ls (1)

The ‘ls’ command stands for list. It is used to list the contents of a directory. If you use ‘ls’ on its own, it will list the files and folders in the

de
current directory. You can also pass in a folder or file name as a parameter. For example, ‘ls /home’ will display the files and folders in the
‘/home’ directory. There are other parameters that the command takes, such as ‘–l’, which outputs a more detailed view which includes file
permissions and ownership information.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - ls (2)

• The ‘ls’ command can also be used to view hidden files with the ‘-a’
parameter
• It’s ‘a’ for ‘all’
• This will show you all files and folders, even those prefixed with a ‘.’

. ir
SEC201 | Intro to Computer Fundamentals 90

01
Linux Terminal – Commands - ls (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - ls (3)

• Open up the terminal in your Linux virtual machine and play with
the ls command a bit
• Try looking at the help:
• $ ls --help
• Then try the following commands:
• $ ls -l
• $ ls –h
• $ ls –a
• $ ls –halt
• $ ls /bin

ir
• $ ls ..

.
SEC201 | Intro to Computer Fundamentals 91

01
Linux Terminal – Commands - ls (3)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - pwd (1)

• The ‘pwd’ command stands for ‘print working directory’


• It tells you the directory that you are currently in
• Not often used since usually the terminal prompt will show you
that information
• But you might need it on a system with a customized prompt
• Alternatively you might need it if you have exploited a system as
you won’t always be able to see the prompt under those
circumstances
• It’s a key command to look out for in log files if you’re a system
administrator as most legitimate users will already have this

ir
information!

.
SEC201 | Intro to Computer Fundamentals 92

01
Linux Terminal – Commands - pwd (1)

The ‘pwd’ command stands for ‘print working directory’. It tells you which directory you are currently in. Most terminals already show you this

de
information in the prompt but sometimes you may come across instances where the prompt has been customized to remove such information.
There are other circumstances in which you may not have a prompt at all, so you need to know how to find this information under those
circumstances.
hi
If you see this command being run on your servers, and you haven’t removed such information from your prompt, then seeing this command can
indicate that someone has compromised your system.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - pwd (2)

• Open up the terminal in your Linux virtual machine and play with
the pwd command a bit
• Try the following command:
$ pwd

. ir
SEC201 | Intro to Computer Fundamentals 93

01
Linux Terminal – Commands - pwd (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - cd (1)

• The ‘cd’ command stands for ‘change directory’


• This is the command that lets you navigate around folders in the
filesystem
• You just need to type ‘cd’ followed by the folder name or path
• You can use relative or absolute paths. For example, if you are in
/home/username you can do ‘cd Desktop’ to get to
/home/username/Desktop.
• You can also do ‘cd /home/username/Desktop’ which is an
absolute path

ir
• Using the ‘..’ shortcut you can also do: cd ‘../username/Desktop’

.
SEC201 | Intro to Computer Fundamentals 94

01
Linux Terminal – Commands - cd (1)

The ‘cd’ command stands for ‘change directory’. This command allows you to navigate the file system. All you need to do is to type cd followed

de
by the path to your folder. You can do ‘cd Desktop’ or you can use an absolute path. Absolute paths start with a ‘/’ which indicates it starts from
the root of the file system. It’s a common beginner mistake to put a ‘/’ at the start of relative paths. Of course, this does not work, as a leading ‘/’
in, for example, ‘/Desktop’ means start at the root of the file system then go to the folder called Desktop which does not exist there.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - cd (2)

• Open up the terminal in your Linux virtual machine and play with
the cd command a bit
• First go to ‘~/Documents/day2/terminal/cd’ by typing:
$ cd ~/Documents/day2/terminal/cd
• List the contents, you should know how by now
• You will see two folders, cd into folder1 by typing:
$ cd folder1

. ir
SEC201 | Intro to Computer Fundamentals 95

01
Linux Terminal – Commands - cd (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - cd (3)

• Now cd back into the parent directory by typing:


$ cd ..
• Now cd back into folder1
$ cd folder1
• Then cd directly from folder1 into folder2 by typing:
$ cd ../folder2
• See what happened? ‘..’ represents the parent directory so you are
changing into the parent directory and then into folder2

. ir
SEC201 | Intro to Computer Fundamentals 96

01
Linux Terminal – Commands - cd (3)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - hostname (1)

• The ‘hostname’ command does what it sounds like, it prints the


hostname of the computer
• The hostname is just an identifier for that computer
• It is usually displayed in the terminal prompt, unless the prompt
has been customized
• Can be useful if you have multiple SSH (remote shell) logins open
on your computer and you can’t remember which is which

. ir
SEC201 | Intro to Computer Fundamentals 97

01
Linux Terminal – Commands - hostname (1)

The hostname command prints out the hostname of the computer. The hostname is just a way of identifying the computer. Usually, this

de
information is shown in the terminal prompt, unless you customized the prompt. This command can be useful if you have multiple SSH sessions
open with many different computers as it can help you identify which computer each session is connected to.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - hostname (2)

• Open up the terminal in your Linux virtual machine and play with
the hostname command a bit
• Look at the help by typing:
$ hostname –h
• Try the following command:
$ hostname

. ir
SEC201 | Intro to Computer Fundamentals 98

01
Linux Terminal – Commands - hostname (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - cp (1)

• The ‘cp’ command stands for ‘copy’. It can copy a file or folder from
one place to another
• By default the ‘cp’ command can only copy files. To copy a folder
you need to add a parameter to make it recursive
• To do that you need ‘cp –R’
• ‘Recursive’ just means that if you specify a folder it will also apply
to each item within that folder
• There are many commands which take a ‘recursive’ parameter

. ir
SEC201 | Intro to Computer Fundamentals 99

01
Linux Terminal – Commands - cp (1)

The ‘cp’ command stands for copy. It does what it sounds like; it copies files from one location to another. In its default setting, the cp command

de
can only copy files and not folders. To make it copy folders you need to add a parameter to make it ‘recursive’. To do that you need to use cp –R.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - cp (2)

• Open up the terminal in your Linux virtual machine and play with
the cp command a bit
• Let’s look at the help for cp first:
$ cp --help
• Now cd to ~/Documents/day2/terminal/cp. Here you will see a
folder called folder1. Within is a text file called file1.txt. Copy it to
file2.txt:
$ cp folder1/file1.txt folder1/file2.txt
• Now make a copy of folder1 called folder2:
$ cp –R folder1 folder2

. ir
SEC201 | Intro to Computer Fundamentals 100

01
Linux Terminal – Commands - cp (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - mv (1)

• The ‘mv’ command stands for ‘move’. It can move a file or folder
from one place to another
• It can also be used as a ‘rename’ function, since you can move a file
to the same folder but with a new name
• You first specify the file you want to move, then the place you want
to move it to
• For example: ‘mv file1 /opt/file1renamed’. In this case file1 in the
current working directory will be moved into /opt and renamed to
file1renamed.

. ir
SEC201 | Intro to Computer Fundamentals 101

01
Linux Terminal – Commands - mv (1)

The ‘mv’ command stands for ‘move’. It can move a file or folder from one place to another. Note, this is not the same as a copy. With a move,

de
the file will no longer be in the original location after it is moved, whereas with copy the original will also remain in place. Move is also frequently
used to rename a file. Think about it, if you move a file from one location to the same location but you specify a new name, it’s the same as
renaming the file.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - mv (2)

• Open up the terminal in your Linux virtual machine and play with
the mv command a bit
• Let’s look at the help for mv first:
$ mv --help
• Now cd into ‘~/Documents/day2/terminal/mv’. Here you will see
folder1. Within is a text file called file1.txt. Rename it to file2.txt:
$ mv folder1/file1.txt folder1/file2.txt
• Now let’s move folder1 to folder2:
$ mv folder1 folder2
• You will see that folder1 is now called folder2

. ir
SEC201 | Intro to Computer Fundamentals 102

01
Linux Terminal – Commands - mv (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - less (1)

• The ‘less’ command is a program that can be used to read files


• It is based off of the ‘more’ command, which is older and does
much the same thing
• It has a text-based interface which allows you to use the arrow keys
to scroll through a document
• In order to quit the program you must hit the ‘q’ key on the
keyboard

. ir
SEC201 | Intro to Computer Fundamentals 103

01
Linux Terminal – Commands - less (1)

The ‘less’ command is a program that can be used to read files. The good thing about less is that it works really well for reading very large files.

de
That’s because it doesn’t load the whole file into memory all at once, it reads the file by ‘pages’. Less is also an example of a program that has a
text-based interface where you can use the arrow keys to navigate the text, but you have to press ‘q’ to exit the program. Less is based off of an
older program called ‘more’ which did much the same thing.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - less (2)

• Open up the terminal in your Linux virtual machine and play with
the less command a bit
• First cd into ~/Documents/day2/terminal/less. You will see a file
called ‘lessismore.txt’. Open it up in less with:
$ less lessismore.txt
• Navigate through the document with the arrow keys and when you
are done quit by hitting ‘q’

. ir
SEC201 | Intro to Computer Fundamentals 104

01
Linux Terminal – Commands - less (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - cat (1)

• The ‘cat’ command stands for concatenate


• The command is used for getting the contents of several files and
concatenating them (adding them together) and printing the
results to the terminal
• However the more common usage is to ‘cat’ a single file, which will
print its contents to the terminal alone

. ir
SEC201 | Intro to Computer Fundamentals 105

01
Linux Terminal – Commands - cat (1)

The ‘cat’ command stands for concatenate. The command is used for getting the contents of several files and concatenating them (adding them

de
together) and printing the results to the terminal. However, the more common usage for the ‘cat’ command is to use it on a single file, which will
just print the contents of the file to the terminal.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - cat (2)

• Open up the terminal in your Linux virtual machine and play with
the cat command a bit
• First cd into ~/Documents/day2/terminal/cat. You will see three
text files: file1.txt file2.txt and file3.txt.
• Try these commands:
• $ cat file1.txt
• $ cat file1.txt file2.txt
• $ cat file1.txt file2.txt file3.txt
• $ cat file*.txt

. ir
SEC201 | Intro to Computer Fundamentals 106

01
Linux Terminal – Commands - cat (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - rm (1)

• The ‘rm’ command stands for remove


• It is used for deleting files and folders
• The command on its own does not work with folders, you need to
specify –R for recursive
• The command will ask if you’re sure you want to delete the files or
folders unless you pass in the –f parameter (force)
• The files and folders will be deleted instantly, they will NOT be
moved to a trash folder or recycle bin
• This command can be used to delete your entire filesystem, so
make sure of what you’re typing!

. ir
SEC201 | Intro to Computer Fundamentals 107

01
Linux Terminal – Commands - rm (1)

The ‘rm’ command stands for remove. It’s used for deleting files and folders. Similar to the ‘cp’ command, it does not work on folders by default.

de
If you need to delete a folder you need to pass in the recursive parameter (-R). Be very careful when using this command, as there is no undo
button. The files will be instantly deleted, even if you asked it to delete recursively from the root of the file system, it will go ahead and delete
everything and break your installation.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - rm (2)

• Open up the terminal in your Linux virtual machine and play with
the rm command a bit
• First cd to ~/Documents/day2/terminal/rm. You will see a folder
called folder1. Within is a text file file.txt. Delete the text file with
rm:
$ rm folder1/file.txt
• Next try deleting folder1:
$ rm folder1
• Notice it didn’t work

. ir
SEC201 | Intro to Computer Fundamentals 108

01
Linux Terminal – Commands - rm (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - rm (3)

• Try again with the correct command:


$ rm –Rf folder1
• Notice we’re also using force here so it wont check if you’re sure
you want to delete it

. ir
SEC201 | Intro to Computer Fundamentals 109

01
Linux Terminal – Commands - rm (3)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - find

• The ‘find’ command can search the filesystem for particular files
• It can be quite tricky to use
• First you specify the location to search in and then you specify how
you’re matching the file
• For example: ‘find / -name sans’ would search in the root of the
filesystem and all files and folders within it for files with the
filename ‘sans’
• There are other ways you can match, for example, size for file size
• On older systems, you may need to tell find to print the results to
the screen with the –print parameter.

. ir
SEC201 | Intro to Computer Fundamentals 110

01
find

The ‘find’ command is used to search the filesystem for matching files. The syntax can be quite tricky and it often sends people running in fear,

de
but it’s not too bad once you get the hang of it. First you have to specify the location you want to search in; then, you need to specify the match
condition. So, for example, if you wanted to search the whole filesystem for files called ‘sans’ you would do: find / -name sans. You can use other
match conditions, such as –size to match based on file size. See the manual page for find for the full list.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - find (1)

• Open up the terminal in your Linux virtual machine and play with
the find command a bit
• First cd to ~/Documents/day2/terminal/find. Within you will find
a text file called ‘file_name.txt’.
• First search within ~/Documents/day2/terminal/find for files with
the name ‘name’ as part of the name with:
$ find ~/Documents/day2/terminal/find –name “*name*”
• The search should find file_name.txt

. ir
SEC201 | Intro to Computer Fundamentals 111

01
Linux Terminal – Commands - find (1)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - find (2)

• Now re-write the search. You could instead do:


$ find . –name “*name*”
• The ‘.’ represents the current directory

. ir
SEC201 | Intro to Computer Fundamentals 112

01
Linux Terminal – Commands - find (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - grep (1)

• The ‘grep’ command can search for keywords within a text file and
returns the surrounding text
• You first specify the keyword you are searching for, then the
filename of the file to search in
• For example: grep “password” logfile.txt
• You can also specify multiple files to search in

. ir
SEC201 | Intro to Computer Fundamentals 113

01
Linux Terminal – Commands - grep (1)

The grep command can search for keywords within a text file and returns the surrounding text. First you have to specify the keyword you are

de
searching for; then, you need to specify the file or files you want to search in. You can pass in multiple files as parameters.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - grep (2)

• Open up the terminal in your Linux virtual machine and play with
the grep command a bit
• First cd into ~/Documents/day2/terminal/grep. You fill find
several text files in here. Search for the word ‘SANS’ within them:
$ grep ‘SANS’ textfile1.txt
• You could do it one by one, or you could do them all at once:
$ grep ‘SANS’ textfile1.txt textfile2.txt
• Even better:
$ grep ‘SANS’ *.txt

. ir
SEC201 | Intro to Computer Fundamentals 114

01
Linux Terminal – Commands - grep (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - which (1)

• It can be helpful sometimes to know where the executable file for a


command is located
• We can do that with ‘which’
• You just need to pass it the name of the command you want to find
the executable for as a parameter

. ir
SEC201 | Intro to Computer Fundamentals 115

01
Linux Terminal – Commands - which (1)

The ‘which’ command is incredibly useful for locating the executable files that various commands call. You type ‘ls’, for example, but where is

de
the ‘ls’ program located in the file system? Which can tell you. You just need to type ‘which ls’.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - which (2)

• Open up the terminal in your Linux virtual machine and play with
the which command a bit
• Find the location of the ‘passwd’ command
$ which passwd
• How about the location of the ‘which’ command?
$ which which

. ir
SEC201 | Intro to Computer Fundamentals 116

01
Linux Terminal – Commands - which (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - man (1)

• The ‘man’ command stands for manual


• It is used to display documentation for programs installed on the
system. This is usually much more in depth than using –h or –help.
• Using man actually opens the manual file in ‘less’ so you can scroll
with the arrow keys and you have to exit by pressing ‘q’
• Nearly all programs also install man pages when they are installed
• Very useful particularly if you don’t have access to the internet

. ir
SEC201 | Intro to Computer Fundamentals 117

01
Linux Terminal – Commands - man (1)

The ‘man’ command stands for manual. It can show you a manual page or man page for most programs installed on the system. This is usually

de
more in depth than the help pages which can be accessed by passing in –h or --help. When you use man, the manual pages are actually opened in
‘less’ so you can navigate using the arrow keys and you have to remember to quit by pressing ‘q’.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - man (2)

• Open up the terminal in your Linux virtual machine and play with
the man command a bit
• Let’s look at some of the man pages for the commands we’ve
learned so far:
• $ man less
• $ man grep
• $ man ls
• $ man cd
• $ man find
• $ man man

. ir
SEC201 | Intro to Computer Fundamentals 118

01
Linux Terminal – Commands - man (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - apropos (1)

• The ‘apropos’ command is used to search man pages for particular


information
• This is useful if you need to know how to do something but you
don’t know which command can be used to accomplish it

. ir
SEC201 | Intro to Computer Fundamentals 119

01
Linux Terminal – Commands - apropos (1)

The ‘apropos’ command is used to search man pages for particular information. This is useful if you know what you want to accomplish but you

de
don’t know which tool you could use to accomplish it. In English, apropos means ‘very appropriate to a particular situation.’ This may help you to
remember the command.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - apropos (2)

• Open up the terminal in your Linux virtual machine and play with
the apropos command a bit
• First let’s look for a single keyword ‘print’:
$ apropos print
• Then let’s look for two keywords by using the –a parameter (and):
$ apropos print –a lines
• And more:
$ apropos print –a lines –a pattern

. ir
SEC201 | Intro to Computer Fundamentals 120

01
Linux Terminal – Commands - apropos (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - strings (1)

• The strings command looks in files for any ASCII characters that
look like they might form a string and prints them to the terminal
• The characters don’t necessarily make sense, as it tries to interpret
everything as ASCII whether it is or not
• It’s useful for reverse engineering and sometimes you can even pull
passwords out of files
• Keep in mind that, by default, any strings three characters or less
will be ignored. You can change this with the –n parameter.

. ir
SEC201 | Intro to Computer Fundamentals 121

01
Linux Terminal – Commands - strings (1)

The strings command looks in files for any ASCII characters that look like they might form a string (a word or sentence) and prints them to the

de
terminal. The characters it finds don’t necessarily make sense, as it tries to interpret everything as ASCII whether it is or not. Typically the strings
command looks for any 4 consecutive characters or more but you can change this default behavior with the –n parameter where you can specify
the number of characters to match. For example, strings –n 3 to match three consecutive characters or more.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - strings (2)

• Open up the terminal in your Linux virtual machine and play with the strings
command a bit
• First cd to ~/Documents/day2/terminal/strings. Here you will find two binary
executables that have been compiled from C.
• If you run binary1 with:
$ ./binary1
• It will ask for a password. Find the password using strings. First ctrl + c to exit
binary1. Then run strings on binary1:
$ strings binary1
• You should be able to search the output for the password
• Re-run binary1 and enter the password to check you got it right!

. ir
SEC201 | Intro to Computer Fundamentals 122

01
Linux Terminal – Commands - strings (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - strings (3)

• Now try running binary2. It’s the same deal, so run strings against
binary2
• The problem is, you can’t see the password. That’s because this
program was written so the password is broken up in chunks of
three characters and only assembled in memory.
• To get around that you need to pass the –n parameter to strings.
$ strings –n 3 binary2
• You should be able to assemble the password now, so run binary2
to check you got it right!

. ir
SEC201 | Intro to Computer Fundamentals 123

01
Linux Terminal – Commands - strings (3)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - nano (1)

• The ‘nano’ command is a command line text editor that can be used
to create, modify and read files
• If the filename you specify exists, it will be opened. If it doesn’t
exist, a new file with that name will be created.

. ir
SEC201 | Intro to Computer Fundamentals 124

01
Linux Terminal – Commands - nano (1)

The ‘nano’ command is a command line text editor which can be used to create, modify and read files. It’s very easy to use compared to say Vi or

de
Vim (which we’ll be covering shortly), however it has fewer features than more advanced editors. Simply type ‘nano’ and then pass in a file name
as a parameter. If the file exists, it will be opened in the text editor, if the file doesn’t exist then it will be created. Nano has a text-based interface
with clear shortcuts for things like scrolling through pages, find, and saving.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - nano (2)

• Open up the terminal in your Linux virtual machine and play with
the nano command a bit
• First cd to ~/Desktop
• Create a file called nano_demo and put some random text in there:
$ nano nano_demo
• Then type something and press Ctrl + x to exit. Make sure to save
the file when it asks.

. ir
SEC201 | Intro to Computer Fundamentals 125

01
Linux Terminal – Commands - nano (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - nano (3)

• You can check the contents of the file to make sure it saved
properly with:
$ cat nano_demo
• Then you can go ahead and edit to add more text again with:
$ nano nano_demo

. ir
SEC201 | Intro to Computer Fundamentals 126

01
Linux Terminal – Commands - nano (3)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - vim (1)

• The ‘vim’ command is another text editor similar to nano; however,


it has much greater functionality.
• Despite this, it’s considered to be much more difficult to use than
nano
• However, it is still worth learning as you will sometimes be on a
system with only Vim available and no ability to install your own
software
• Vim is actually a more modern version of ‘Vi’. On most modern
systems ‘Vi’ has been replaced with ‘Vim’ so you can either use ‘Vi’
or ‘Vim’ and typically both of these commands will give you Vim.

. ir
SEC201 | Intro to Computer Fundamentals 127

01
Linux Terminal – Commands - vim (1)

The vim command is another text editor that is similar to nano, however it has many more features. It’s equally more difficult to use than nano, but

de
it is worthwhile learning both Vim and its predecessor Vi. That’s because you will occasionally find yourself in a situation when all you have is Vi
or Vim and you aren’t allowed to install nano. Vim and Vi are both frequently installed by default for many distributions, while nano is not as
globally available.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - vim (2)

• Open up the terminal in your Linux virtual machine and play with
the vim command a bit
• First cd to ~/Desktop
• Create a file called vim_demo:
$ vi vim_demo
• Enter insert mode to add or edit text: press ‘i’. Now you can add
text.

. ir
SEC201 | Intro to Computer Fundamentals 128

01
Linux Terminal – Commands - vim (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - vim (3)

• Press ‘ESC’ or ‘Ctrl+C’ to exit insert mode


• Now save the file by typing
:x
• This is the command for writing a file
• If you want to exit without saving changes you can type:
:q!
• Note that an exclamation mark (!) after the letter means force. In
this case we’re forcing the application to quit when there are
unsaved changes to the document.

. ir
SEC201 | Intro to Computer Fundamentals 129

01
Linux Terminal – Commands - vim (3)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - vim (4)

• This is far from the extent of what you can do with Vi


• It’s worth you spending some time and effort on learning it in your
own time. Covering every aspect of Vi could fill up its own book!
• Here’s a personal favourite, using Vi as a hex editor by opening a
file in Vi first
• Then type:
:%!xxd
• After you’ve made your changes, you can convert the file back by
pressing ctrl+c and then typing:
:%!xxd -r

. ir
SEC201 | Intro to Computer Fundamentals 130

01
Linux Terminal – Commands - vim (4)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - top (1)

• The ‘top’ command brings up a resource monitor type window


which acts similarly to the task manager in Windows
• Useful for looking at how much RAM is being used, and the CPU
usage
• It also shows you the ‘load’ on your system, the first value is the
current load, and the other two are previous load values. This way
you can see trends, if the load is increasing or decreasing over time.
• The ‘top’ command is a command that needs to be exited using
‘Ctrl + C’

. ir
SEC201 | Intro to Computer Fundamentals 131

01
Linux Terminal – Commands - top (1)

The ‘top’ command acts as a resource monitor, similar to the task manager in windows. It’s useful for looking at system resources, how much load

de
the computer is under and which processes are using up the most resources. Where load is shown, the first value is the current load, the other two
are previous load values. This is done so you can see a trend in resource usage, i.e. is it falling or rising.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - top (2)

• Open the terminal in your Linux virtual machine and play with the
top command a bit
• Just type:
$ top
• and look around
• When you’re done, exit with Ctrl + C

. ir
SEC201 | Intro to Computer Fundamentals 132

01
Linux Terminal – Commands - top (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - ps (1)

• The ‘ps’ command lists running processes


• By default only shows processes running under your username
• Parameters can be passed in to change the default behavior
• There are two syntax styles for parameters which can make things
confusing. These are Unix syntax and BSD syntax. Both work, and
you can even mix and match.

. ir
SEC201 | Intro to Computer Fundamentals 133

01
Linux Terminal – Commands - ps (1)

The ‘ps’ command lists running processes. By default it only shows the processes that are running under your username, but you can add

de
parameters to show all running processes and also the command that was used to execute the processes. This is a good example why it’s never a
good idea to pass passwords to programs on the command line, because any other user on the system will be able to see the parameters you
entered when starting that process. There are two types of syntax for the ‘ps’ command, generally they both work although you should not use
them interchangeably.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - ps (2)

• Open the terminal in your Linux virtual machine and play with the
ps command a bit
• First type
$ ps
• on its own and note the processes
• Then type
$ ps aux
• This is BSD syntax, it will show you all processes along with
detailed information on them

. ir
SEC201 | Intro to Computer Fundamentals 134

01
Linux Terminal – Commands - ps (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - ps (3)

• The equivalent in Unix syntax is:


$ ps –ef –f
• Both should work
• Make sure to check out the man page for ps for more detailed
information

. ir
SEC201 | Intro to Computer Fundamentals 135

01
Linux Terminal – Commands - ps (3)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - history (1)

• The ‘history’ command shows you a list of previously typed


commands on the system
• Good for retracing your steps, or looking at what an attacker has
done on a system (if they forgot to clear the history file)
• The history file can be cleared by passing a parameter to the history
command: ‘history –c’
• Each user has their own history file, so you won’t be able to see
root’s history unless you become root

. ir
SEC201 | Intro to Computer Fundamentals 136

01
Linux Terminal – Commands - history (1)

The ‘history’ command shows you a list of previously typed commands on the system. In reality, the commands are stored in a history file and the

de
history command only prints out the contents of the file. This is a good method for retracing your steps, it can also show you what an attacker has
been doing on the system if he forgot to clean up after himself. It’s possible to clear your history file with ‘history –c’ or by simply deleting the
history file wherever it is stored.
hi
Each user has their own history file, so you won’t be able to see what other people have been doing unless you have permissions to access their
history file.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - history (2)

• Open the terminal in your Linux virtual machine and play with the history
command a bit
• First type:
$ history
• to view the history file
• Once you’ve seen it, type
$ history –c
• to clear it
• Now view the history file with
$ history
• again and look at the difference

. ir
SEC201 | Intro to Computer Fundamentals 137

01
Linux Terminal – Commands - history (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - diff (1)

• The ‘diff’ command shows you the differences between files


• This is good for showing you sections of code that have been
updated if you’re looking at two different software versions
• Simply the syntax is ‘diff file1 file2’

. ir
SEC201 | Intro to Computer Fundamentals 138

01
Linux Terminal – Commands - diff (1)

The ‘diff’ command shows you the differences between files. This is good for looking at differences in sections of code, such as when a patch has

de
been released. The syntax is simple, you just need to pass in the two files to compare as parameters.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - diff (2)

• Open the terminal in your Linux virtual machine and play with the
diff command a bit
• First go to ~/Documents/day2/terminal/diff. You will see two text
files here. ‘text1.txt’ and ‘text2.txt’
• Find the differences between them with the ‘diff’ command
$ diff text1.txt text2.txt

. ir
SEC201 | Intro to Computer Fundamentals 139

01
Linux Terminal – Commands - diff (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - wget (1)

• The ‘wget’ command allows you to download a file from a web


server
• The syntax is simple: ‘wget http://webserver.com/myfile.txt’
• The file will be saved in your current working directory

. ir
SEC201 | Intro to Computer Fundamentals 140

01
Linux Terminal – Commands - wget (1)

The ‘wget’ command can be used to download files from the internet. The syntax is simple, ‘wget’ followed by the link to the file to download.

de
The file will be saved in the current working directory.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - wget (2)

• Open your terminal in your Linux virtual machine and play with
the wget command a bit
• Find an image in google and copy the image link
• In your terminal, download the file with wget:
$ wget https://imgs.xkcd.com/comics/security.png
• Open the image to make sure it downloaded correctly

. ir
SEC201 | Intro to Computer Fundamentals 141

01
Linux Terminal – Commands - wget (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - chmod (1)

• The ‘chmod’ command can be used to change the permissions of a


file or folder
• It can take a parameter such as +x which tells it to make the file
executable for the owner, group and everyone
• It can also take a number such as 755, which can express a much
more thorough set of permissions
• You can use –R to make it recursive. If you do that you will set the
permissions on all files and folders within the folder to those
permissions.
• Be careful! You can easily destroy your installation by overwriting

ir
the permissions of system files.

.
SEC201 | Intro to Computer Fundamentals 142

01
Linux Terminal – Commands - chmod (1)

The ‘chmod’ command can be used to change the permissions of a file or folder. It can take a parameter such as +x which tells it to make the file

de
executable for everyone. It can also take a number such as 755, which is much more thorough. You should remember how to calculate Linux
permissions and express them as a number in this manner.

By default chmod can work on a file or a group of files or even a folder, but if you want to apply the permissions not just to that folder but also to
hi
subfolders and files contained within that folder, you need to pass in the recursive parameter –R. Make sure you don’t overwrite the permissions
on system files unless you’re absolutely sure that they are wrong or else you risk corrupting your system. Imagine if you accidentally change the
permissions on chmod so that you can’t change the permissions back.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - chmod (2)

• Open the terminal in your Linux virtual machine and play with the
chmod command a bit
• First cd to ~/Documents/day2/terminal/chmod. Within you have two
folders. In folder1 set the permissions of the file file1.txt to read only
for all. Remember how to calculate permissions?
$ chmod 444 folder1/file1.txt
• Use nano to open the file and make some changes. Can you save it
afterwards? If you can, the permissions are still wrong.
• Let’s do some recursive changes. Let’s remove all permissions from
folder2:
$ chmod –R 000 folder2

ir
• Can you cd to it still?

.
SEC201 | Intro to Computer Fundamentals 143

01
Linux Terminal – Commands - chmod (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - ln (1)

• The ‘ln’ command can be used to create a symbolic link (symlink)


• Think of it as ‘link’
• The syntax is ‘ln –s /path/to/original /path/to/symlink’
• Can be a good way to keep applications elsewhere but ‘symlink’
them into a folder in the PATH

. ir
SEC201 | Intro to Computer Fundamentals 144

01
Linux Terminal – Commands - ln (1)

The ‘ln’ command can be used to create a symbolic link (symlink). Think of it as ‘link’. The syntax is ‘ln –s /path/to/original /path/to/symlink’.

de
This can be a good way to install applications wherever you want but also keeping them in the path. For example, if you install a program into /opt
and /opt isn’t in the path you could symlink the binary from its location in /opt to /bin or /usr/bin which is in the path. Keep in mind that if you
make changes to a link, the changes will apply to the original, but if you delete a link the original file will stay behind.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - ln (2)

• Open the terminal in your Linux virtual machine and play with the ln
command a bit
• First cd to ~/Documents/day2/terminal/ln. Within there is a text file,
text1.txt.
• Use ln to generate a symlink in the same folder with the filename
text2.txt:
$ ln –s text1.txt text2.txt
• Edit text1.txt and make some changes. Save them and examine
text2.txt to verify if the changes also applied there.
• Then edit text2.txt and examine text1.txt

ir
• Finally, use ‘rm’ to delete text2.txt. Verify that text1.txt is still there.

.
SEC201 | Intro to Computer Fundamentals 145

01
Linux Terminal – Commands - ln (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - chown (1)

• The ‘chown’ command can be used to change the owner or group


for a file
• On some systems, the owner of a file can give away ownership, but
on most modern systems only root can change the owner of a file.
• This is considered a security feature.
• The syntax is ‘chown username:group file’
• This command also supports –R for recursive, which will not only
change the ownership of the folder but all items contained within

. ir
SEC201 | Intro to Computer Fundamentals 146

01
Linux Terminal – Commands - chown (1)

Chown stands for ‘change ownership’. It can be used to change the owner or group of a file or folder. Usually, only the current owner of the file

de
can change the owner or group, essentially this means giving away ownership rights. Root can also change the ownership of any file, no matter
who owns it. The syntax is easy, simply ‘chown username:group file’. Like with chmod, if you want to apply the permissions changes to a folder
and any items within it, you need to add the recursive parameter (-R).
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - chown (2)

• Open the terminal in your Linux virtual machine and play with the
chown command a bit
• First cd to ~/Documents/day2/terminal/chown. Within is a folder
‘folder1’. The folder is readable only by the owner, which is
currently you.
• Change the ownership of the folder to root with:
$ sudo chown –R root:root folder1
• Now try to cd to the folder. Does it still work?
• Look at the permissions of the folder with
$ ls –halt

. ir
SEC201 | Intro to Computer Fundamentals 147

01
Linux Terminal – Commands - chown (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - sudo (1)

• The ‘sudo’ command allows you to execute another command as


another user temporarily. By default, the user it runs as is ‘root’.
• It is considered best practice to always use sudo rather than logging
in as root directly
• The sudo command only works for authorised users. The list of
authorised users is listed in the ‘sudoers’ file and can be edited to
add more users as well as restrict them to only allow sudo
privileges for specific commands.
• You can generally edit the sudoers file using the ‘visudo’ command.
This is the only safe way to do it, using any other method risks

ir
locking yourself out of sudo.

.
SEC201 | Intro to Computer Fundamentals 148

01
Linux Terminal – Commands - sudo (1)

The ‘sudo’ command lets you run a command as another user. This is most typically used to run commands with ‘root’ privileges without actually

de
logging in as root. This is actually the recommended behavior and many distributions don’t even give you the root password anymore.

The way it works is simple, you use ‘sudo’ followed by the command you want to run and that will try to run the command as the root user. You
will be prompted for your account password and then the command will run as root. Why does this work? Well, your account has to be in the
hi
‘sudoers’ file, which is a list of users who are allowed to sudo and what users they are allowed to become.

Only root is able to edit the sudoers file, but it’s actually quite dangerous to do it. Imagine if you don’t know the root password, you then go edit
the sudoers file and corrupt it making sudo stop working for you. You can then no longer edit the sudoers file back to how it was because you are
no longer allowed to use sudo. That’s why using the command ‘visudo’ is a better way to edit the sudoers file. Visudo will check if the sudoers file
is valid before overwriting it.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - sudo (2)

• Open the terminal in your Linux virtual machine and play with the
sudo command a bit
• First type:
$ whoami
• This is a command that tells you what user you are currently logged in
as
• Now type:
$ sudo whoami
• You will be asked for a password, this is your user’s account password
and not root’s. See the difference between what is reported?
• You can use sudo privileges to do anything that root can do including

ir
changing permissions on files you don’t own

.
SEC201 | Intro to Computer Fundamentals 149

01
Linux Terminal – Commands - sudo (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - su (1)

• The ‘su’ command stands for switch user and it can allow you to
switch to another user
• By default it tries to switch to the root user
• It is good practice to always add a – to the end of the command so
that the environment variables from the user you are switching to
get loaded
• E.g. su –
• Or su user2 –
• You will need to enter the account password for the account you

ir
are switching to

.
SEC201 | Intro to Computer Fundamentals 150

01
Linux Terminal – Commands - su (1)

The ‘su’ command stands for switch user. Using this command you can switch your terminal session to be logged in as another user. If you don’t

de
pass in any parameters, the default user to switch to is the root user. Otherwise, you have to specify the user you want to switch to. It’s also good
practice to add a – to the end of the ‘su’ command. This will load various environment variables for that user. If you forget to add the -, some
things may not work as intended.
hi
Once you have switched to another user, you can go back to your old user by typing ‘exit’.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - su (2)

• Open the terminal in your Linux virtual machine and play with the
su command a bit
• First switch to the root user with
• $ su –
• Enter the root password, which is: ‘usingSUDOisWayBetter’

. ir
SEC201 | Intro to Computer Fundamentals 151

01
Linux Terminal – Commands - su (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Commands - su (3)

• Now type
$ whoami
• Finally, exit out of the switched context with the command:
$ exit
• Now type
$ whoami

. ir
SEC201 | Intro to Computer Fundamentals 152

01
Linux Terminal – Commands - su (3)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Pipes (1)

• Now that you have a good basis in commands, we should cover


pipes
• Pipes look like this: ‘|’. They allow you to pass output from one
command to another.
• For example, if you are running ‘strings’ against a particular binary
and the output is very large you might want to just look for a
particular keyword
• To do that you can combine strings with grep: strings file | grep
password. First the strings command will be run and the output
will be sent to the grep command.

. ir
SEC201 | Intro to Computer Fundamentals 153

01
Linux Terminal – Pipes (1)

A pipe allows you to pass (or pipe) output from one command to another. A pipe character looks like this: |. Take, for example, a strings

strings filename | grep keyword.


de
command, the output of the command might be very long. If you’re only searching for a keyword you could combine strings with grep like so:

First strings will be run on the filename, then the result from the strings command will be piped to the grep command. So grep will run looking for
hi
the keyword in the results of the strings command. You could go even further and pipe the output of grep into less so you’d end up with: strings
filename | grep keyword | less.

Don’t ignore pipes, they are incredibly powerful. It’s tough to work in Linux without using them.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Pipes (2)

• You can chain them as much as you want. Take this one, for
example: strings file | grep password | less which will do the same
thing as the previous command, but the output will be opened in
less.
• Pipes are incredibly useful when you need to narrow down a large
output

. ir
SEC201 | Intro to Computer Fundamentals 154

01
Linux Terminal – Pipes (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Pipes (3)

• Open the terminal in your Linux virtual machine


• Now run:
$ top
• Open another terminal without closing down top
• Now run this command:
$ ps aux
• You will see a lot of processes

. ir
SEC201 | Intro to Computer Fundamentals 155

01
Linux Terminal – Pipes (3)

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Pipes (4)

• Try it again, but this time let’s only show the process you need:
$ ps aux | grep top
• Now that we have the process id for top, let’s kill it:
$ kill [process id]
• The top process running in your other terminal window should
have exited now

. ir
SEC201 | Intro to Computer Fundamentals 156

01
Linux Terminal – Pipes (4)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Redirects (1)

• Another useful thing we can do with the terminal is a redirect


• A redirect lets you redirect the output of a command into a file
instead of printing it into the terminal
• There are two types of redirect. The first kind is overwrite, for
example: ‘ps aux > filename.txt’. In this case the output from
running ps aux is written to filename.txt, however if filename.txt
already existed it would overwrite the file.
• The second type is append, for example: ‘ps aux >> filename.txt’. In
this case, instead of overwriting filename.txt, it would append the
output to the end of the file.

. ir
SEC201 | Intro to Computer Fundamentals 157

01
Linux Terminal – Redirects (1)

Redirects function similar to pipes, except they allow output from a command to be written to a file. There are two types of redirects, overwrite

output is appended to the end of the existing file.


de
and append. With overwrite mode, the output is saved to a file, overwriting the file if it already exists. With append, if the file already exists, the

To perform an overwrite redirect you need to use >. As in ‘ps aux > filename.txt’. To perform an append redirect you need to use >>. As in ‘ps
hi
aux >> filename.txt’.

You can also use redirects to send output that you don’t want to see to /dev/null. This is an area which contains nothing and therefore anything that
it sent there stops existing. This is particularly useful if you’re setting up scheduled tasks and you don’t want to have the results of whatever
command you scheduled e-mailed to you (for example).

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Redirects (2)

• Open the terminal in your Linux virtual machine


• Now type:
$ echo hello1 > filename.txt
• Now view the contents of filename.txt with
$ cat filename.txt
• You should see it says ‘hello1’

. ir
SEC201 | Intro to Computer Fundamentals 158

01
Linux Terminal – Redirects (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Redirects (3)

• Now let’s do:


$ echo hello2 > filename.txt
• Cat the file again and you will see it says only ‘hello2’.
• Now let’s do:
$ echo hello3 >> filename.txt
• Cat the file again and you will see both ‘hello2’ and ‘hello3’
• That is the difference between using ‘>’ and ‘>>’

. ir
SEC201 | Intro to Computer Fundamentals 159

01
Linux Terminal – Redirects (3)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Terminal – Redirects (4)

• There is one more useful way of using redirects and that is to


redirect to /dev/null
• /dev/null is a device that, essentially, is nowhere. If you redirect
something to /dev/null it will just disappear into the ether.
• This is commonly used if you don’t want to see the output of a
command. For example, if you set up a cron job (scheduled task,
more on this later), but you don’t want the results of the command
to go anywhere, you would redirect the result to /dev/null.
• E.g. ‘echo hello > /dev/null’ wouldn’t produce any output

. ir
SEC201 | Intro to Computer Fundamentals 160

01
Linux Terminal – Redirects (4)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Installing Programs (1)

• These days programs called package managers can be used to


install most programs
• They download a list of software packages from ‘repositories’. The
list includes versions and other software that the package requires
(dependencies).
• When you use a package manager, it looks up the most recent
version, or the version you specified, then it looks up the
dependencies. It finds what you don’t already have installed and
then it installs it all, handling all the dependencies for you
automatically.

. ir
SEC201 | Intro to Computer Fundamentals 161

01
Linux – Installing Programs (1)

Depending on the methods available, installing programs in Linux is either extremely simple or extremely difficult. In modern distributions, you

de
can find most software has been packaged for use with package managers. These are tools which come with the distributions which can
automatically install software and any related dependencies for you. Package managers are also very helpful in managing updating software, you
can generally update any software that was installed with a package manager with one command.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Installing Programs (2)

• Not all packages are available in repositories, however


• There are package formats which can be installed using programs
such as ‘rpm’ or ‘dpkg. Typically, dependencies are not handled
automatically, however.
• The final alternative if there is no software package compatible
with your distribution of Linux is to compile the code from source
• Most projects will make this as easy as possible for you by
providing configuration scripts and make files. (More on this later).

. ir
SEC201 | Intro to Computer Fundamentals 162

01
Linux – Installing Programs (2)

Not all packages are found in package manager repositories, however. Sometimes you might find software that has been packaged in either .deb or

de
.rpm formats. These are package formats for Debian or Fedora based operating systems (respectively) and they can be installed using the tools
available for those distributions (dpkg or rpm). With this method, package dependencies will not be automatically installed but it will clearly tell
you what you are missing.
hi
On the more difficult end of the spectrum is software that hasn’t been packaged at all. In these cases, you will have to compile the code from
source. Usually, a makefile will be provided, which greatly simplifies things. However, in this case, it is up to the user to manage dependencies. It
may not even be clear from the error message what software you are missing, so often troubleshooting these things takes some research.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Package Managers

• Package managers are the easiest way to install software, as nearly


everything is handled for you automatically
• There are two main package managers; most distributions will have
one or the other
• The first is ‘apt-get’ and the second is ‘yum’
• apt-get is usually found on debian-based distributions
• yum is usually found on fedora-based distributions.
• You will usually have to run a package manager as ‘root’, so
remember to use ‘sudo’ before the command

. ir
SEC201 | Intro to Computer Fundamentals 163

01
Linux – Package Managers

Package managers are the easiest way to install software, everything is handled for you, even the installation of programs which the program you

de
want to install requires. Most distributions (though not all) will have one of two package managers. The first package manager to consider is ‘apt-
get’ and the second is ‘yum’. They both function in a similar manner. Apt-get is usually found in Debian based distributions, while Yum is usually
found on Fedora based distributions. Package managers require root privileges to install software, so make sure you use them with ‘sudo’.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – apt-get

• With apt-get the ‘update’ parameter updates the list of software packages and
their versions
• sudo apt-get update
• The ‘upgrade’ parameter will upgrade your installed software packages
automatically
• sudo apt-get upgrade
• The ‘dist-upgrade’ parameter will upgrade your operating system to a newer
version
• sudo apt-get dist-upgrade
• The ‘install’ parameter will install new software
• sudo apt-get install nano
The ‘remove’ parameter will uninstall software

ir

• sudo apt-get remove nano

.
SEC201 | Intro to Computer Fundamentals 164

01
Linux – apt-get

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – yum

• With yum the ‘update’ parameter upgrades your installed software


packages automatically
• sudo yum update (updates all packages)
Or
• sudo yum update nano (updates the specified package)
• The ‘install’ parameter installs new software
• sudo yum install nano
• The ‘remove’ parameter uninstalls software
• sudo yum remove nano

. ir
SEC201 | Intro to Computer Fundamentals 165

01
Linux – yum

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – dpkg

• A program that can install ‘.deb’ files


• Usually found on debian-based distributions
• To install a .deb file:
• Download the .deb package first
• sudo dpkg –i nano.deb
• To uninstall a program installed with dpkg:
• sudo dpkg –l (to list all packages in order to find the package name)
• sudo dpkg –r nano

. ir
SEC201 | Intro to Computer Fundamentals 166

01
Linux – dpkg

Dpkg is a program which can install software that has been packaged in the ‘.deb’ format. It is not a package manager, it does not automatically

de
resolve dependencies; however, it is a much easier solution than compiling programs from the source code. Dpkg is usually found on Debian
based distributions.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – rpm

• A program that can install ‘.rpm’ files


• Usually found on fedora-based distributions
• To install a .rpm file:
• sudo rpm –Uvh nano.rpm
• To uninstall a program installed with rpm:
• sudo rpm –qa (to list all packages in order to find the package name)
• sudo rpm –e nano

. ir
SEC201 | Intro to Computer Fundamentals 167

01
Linux – rpm

RPM is a program which can be used to install software that has been packaged in the ‘.rpm’ format. It is the equivalent of ‘dpkg’, except it is for
Fedora based distributions.
de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Compiling from Source

• Always read the readme or INSTALL file first. Sometimes the


instructions may vary!
• Usually you will see a file called ‘configure’ in the project directory
• Run the configure file with ‘./configure’
• The script will generate a Make file which is customized for your
system.
• Run the Make file by typing ‘make’ when you are in the same directory
as it
• Then run ‘sudo make install’ to install the compiled program
• You may encounter errors if you are missing some dependencies, so
make sure you read the list of what the project requires and install it

ir
first!

.
SEC201 | Intro to Computer Fundamentals 168

01
Linux – Compiling from Source

Not all software has been conveniently packaged for us, sometimes you will need to compile it from the source code for yourself. This is often less

error message to explain what it is you are missing.


de
tricky than it seems, but you may run into some common problems where dependencies are not resolved and indeed there is usually no simple

You should first read the INSTALL file that comes with the source code, most software will have this and it will usually contain instructions for
hi
compiling the program. The usual process, however, is to run the configure file with:

$ ./configure

This will generate a Make file which is customized to work with your system. Once that has been done, you run the make file with:

$ make

Finally, you will need to install the program into a directory in your PATH. You can do this with make install; however, you will have to have root
privileges to do this:

# make install

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – apt-get Lab (1)

• Today we will install a program called ‘cowsay’


• It does what it says on the tin!
• First we’ll type ‘cowsay’ in the terminal to see if it’s already
installed
• Seeing that it isn’t installed, we can then use ‘apt-get’ to install it:
$ apt-get install cowsay
• Once cowsay is installed, try running it from the terminal with:
$ cowsay

. ir
SEC201 | Intro to Computer Fundamentals 169

01
Linux – apt-get Lab (1)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – apt-get Lab (2)

ir
.
SEC201 | Intro to Computer Fundamentals 170

01
Linux – apt-get Lab (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – dpkg Lab (1)

• Now let’s look at dpkg by installing the ‘cmatrix’ program


• It’s a program which will make it seem like you’re in the matrix…
for people who still remember those movies
• The .deb file is saved for you in ‘/home/sec201/Documents/day2’,
so ‘cd’ there
• Install it with:
$ sudo dpkg –i cmatrix_1.2a-5_i386.deb
• Check the installation was successful by typing:
$ cmatrix

. ir
SEC201 | Intro to Computer Fundamentals 171

01
Linux – dpkg Lab (1)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – dpkg Lab (2)

.ir
SEC201 | Intro to Computer Fundamentals 172

01
Linux – dpkg Lab (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – dpkg Lab (3)

• And the end result…

.ir
SEC201 | Intro to Computer Fundamentals 173

01
Linux – dpkg Lab (3)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Compile Nmap Lab (1)

• Nmap is a ‘port scanner’, a tool used for finding open ports on a


remote system
• It is very widely used and also somewhat famous. Several movies
have featured it in their ‘hacking’ scenes. Including the
aforementioned ‘The Matrix’.
• Today we will compile it from source although there are packages
for it in apt-get (and the program is actually already installed)

. ir
SEC201 | Intro to Computer Fundamentals 174

01
Linux – Compile Nmap Lab (1)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Compile Nmap Lab (2)

• The source files are compressed in a .tar.gz file in the


‘/home/sec201/Documents/day2’ folder
• Un-compress them with:
$ tar -xvf nmap-7.25BETA1.tgz
• There should now be a folder called ‘nmap-7.25BETA1’
• Use ‘cd’ to go to it:
$ cd nmap-7.25BETA1
• Now start the installation process by typing:
$ ./configure

. ir
SEC201 | Intro to Computer Fundamentals 175

01
Linux – Compile Nmap Lab (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Compile Nmap Lab (3)

ir
.
SEC201 | Intro to Computer Fundamentals 176

01
Linux – Compile Nmap Lab (3)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Compile Nmap Lab (4)

• If it was successful you should see:

. ir
SEC201 | Intro to Computer Fundamentals 177

01
Linux – Compile Nmap Lab (4)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Compile Nmap Lab (5)

• Now the next step is to run:


$ make
• which will actually build the binary executable

. ir
SEC201 | Intro to Computer Fundamentals 178

01
Linux – Compile Nmap Lab (5)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Compile Nmap Lab (6)

• The build process can take awhile…


• Once it is done, you will see there is an ‘nmap’ binary in this folder
• Verify it by typing:
$ ./nmap
• Don’t forget the ‘./’ which will make sure you run the Nmap that is
in this folder and not the one that is already installed on the system

. ir
SEC201 | Intro to Computer Fundamentals 179

01
Linux – Compile Nmap Lab (6)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Compile Nmap Lab (7)

• Normally the next stage would be to type:


$ sudo make install
• This command needs to be run with root privileges and all it does is
move the ‘nmap’ binary that we just created into a folder on the
system such as ‘/usr/bin’
• This step is OPTIONAL here since we already have a version of
‘nmap’ installed but you can do it if you want to!

. ir
SEC201 | Intro to Computer Fundamentals 180

01
Linux – Compile Nmap Lab (7)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Networking (1)

• Every available network interface can be listed on Linux using the


command: ‘ifconfig’
• Each interface is assigned an identifier, for example, eth0 (for
Ethernet) or wlan0 (for wireless)
• The ‘ifconfig’ command can be used to configure the network
adapters, however these changes are only temporary and won’t
survive a reboot!
• To change the settings with ifconfig you must pass in the network
identifier along with the settings you want to change

. ir
SEC201 | Intro to Computer Fundamentals 181

01
Linux – Networking (1)

Knowing how to configure your network settings is absolutely crucial. You can use the ‘ifconfig’ command to get information on your network

de
settings and also to make changes to your network settings. The changes you make with ifconfig are only temporary, though; they won’t survive a
reboot, so keep that in mind. Each network adapter or network card on your computer has its own network settings, and each one gets its own
identifier. For wired Ethernet connections, the adapter tends to be called ‘eth’ followed by a number starting from 0, so, for example, eth0, eth1,
etc. For wireless cards, the adapters tend to start with ‘wlan’ followed by a number starting from 0, for example, wlan0, wlan1, etc.
hi
You can use ifconfig on its own to list your network adapters and their settings. To change the settings of a particular adapter you can use ifconfig,
followed by the adapter identifier and then pass in parameters for the network settings. For example, ifconfig eth0 192.168.0.5 netmask
255.255.255.0. This assigns the IP address 192.168.0.5 to the eth0 network adapter and sets the netmask to 255.255.255.0.

To set the gateway or router address, you must use the ‘route’ command, for example, route add default gw 192.168.0.1.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Networking (2)

• Here are some examples of using ifconfig:


• ifconfig eth0 192.168.0.5
• ifconfig eth0 192.168.0.5 netmask 255.255.255.0
• The gateway on the other hand has to be set with the ‘route’
command:
• route add default gw 192.168.0.1
• The network interfaces can be disconnected or re-connected using
‘ifdown’ or ‘ifup’:
• ifdown eth0
• ifup eth0

. ir
SEC201 | Intro to Computer Fundamentals 182

01
Linux – Networking (2)

You can disable a network interface using the ifdown command, for example, ifdown eth0. You can bring a disabled network interface back up

de
using ifup, for example, ifup eth0. This is useful in VMware when you change the network settings on the virtual machine hardware and need to
refresh them from inside the VM.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Networking (3)

• Changes made in this manner are only temporary. To make permanent


changes you must edit the configuration file that handles network settings.
• This can vary from distribution to distribution, however the most common
method is to edit the file at: /etc/network/interfaces
• The default is usually to get the network settings automatically via DHCP,
however you can change it to use static values:
auto eth0
iface eth0 inet static
address 192.168.0.5
netmask 255.255.255.0
gateway 192.168.0.1

. ir
SEC201 | Intro to Computer Fundamentals 183

01
Linux – Networking (3)

To make more permanent changes to your network settings, you will have to edit the /etc/network/interfaces file. This file controls the network

de
settings for each network adapter. Usually, the default setting is to automatically get network settings via DHCP. This is a reasonable default and
will work out of the box for most people. If you do need to use static network settings, you can edit the interfaces file and use the following
settings, replacing the network settings with your own:
hi
auto eth0
iface eth0 inet static
address 192.168.0.5
netmask 255.255.255.0
gateway 192.168.0.1

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Networking (4)

• As for setting your DNS servers, you will also need to edit a
configuration file and as always with Linux it can vary between
distributions
• However, the most common file is at: /etc/resolv.conf
• Here you just enter the DNS servers you prefer to use in the order
of priority
• For example:
nameserver 8.8.8.8
nameserver 8.8.4.4

. ir
SEC201 | Intro to Computer Fundamentals 184

01
Linux – Networking (4)

To edit your DNS servers, you will need to modify /etc/resolv.conf. All you need to do is put in nameserver followed by the IP address. It is good

de
practice to use multiple DNS servers so that if one goes down, it will automatically fail over to use the next one in the list.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Networking (5)

• Once you’ve changed whatever configuration file is necessary for


your distribution you must either restart the computer or restart
the networking service
• The method for this can also vary from distribution to distribution.
The most common way, however is with: ‘sudo service networking
restart’.

. ir
SEC201 | Intro to Computer Fundamentals 185

01
Linux – Networking (5)

Once configuration files have been edited, you need to restart the computer or restart the networking service. You can restart the networking
service using:

$ sudo service networking restart


de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Scheduled Tasks (1)

• A scheduled task in Linux is called a ‘cron job’


• You can specify a command to run at a specific time
• There is a cron file available for every user on a system, including
root. The command is run as that user.
• To list all cronjobs you can run:
$ crontab –l
• To edit the cron file, you can use:
$ crontab –e

. ir
SEC201 | Intro to Computer Fundamentals 186

01
Linux – Scheduled Tasks (1)

In Linux, a scheduled task is called a ‘cron job’. Simply put, you can specify a time for a command to be executed and whenever that time is

list all cronjobs for your current user with:

$ crontab –l
de
reached the command will run. Each user has their own cron file which lists the jobs, and each command is run as the user in question. You can
hi
To edit the cron file you can use:

$ crontab –e

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Scheduled Tasks (2)

• A cron entry is in the format:


• Minute Hour DayOfMonth Month DayOfWeek Command
• A wildcard operator ‘*’ can be used to specify every, such as every month
• The comma ‘,’ can be used to specify a list of values such as 1,7 (1 st month
and 7th month)
• The dash ‘-’ can be used to specify a range of values such as 1-7 (1st month
to the 7th month)
• The command should be the absolute path to the command

. ir
SEC201 | Intro to Computer Fundamentals 187

01
Linux – Scheduled Tasks (2)

The format of a cron entry is:

Minute Hour DayOfMonth Month DayOfWeek Command


de
You can use a wildcard operator to specify every, such as every month or every day. You can use a comma to specify a list of values such as 1,7
hi
for days 1 and 7. Alternatively, you can specify a range of values with a dash (-) such as 1-4 for months 1 through to 4.

It’s also important that you use the full (absolute) path of the command when you enter it.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Scheduled Tasks (3)

• Let’s look at some cron examples:


• 0 3 * * * /root/backup.sh
• (Run the script at /root/backup.sh every day of the week, every month,
every day of the month, at the third hour and 0 minutes. So the script will
run every day at 3:00 am).
• 0 22 * * 1-5 /root/backup.sh
• (Run the script on 1st day of the week through to the 5th day of the week
every month and every day of the month at the 22 nd hour and 0 minutes.
So the script will run every weekday at 10pm.)

. ir
SEC201 | Intro to Computer Fundamentals 188

01
Linux – Scheduled Tasks (3)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Xwindows (1)

• Linux was originally a command line only operating system


• The program that runs which gives you a Graphical User Interface
(GUI) is called an X-Windows system
• In many distributions of Linux, the X-Windows system starts on
boot
• If it does not start on boot, you can start it with ‘startx’. You can
also stop it with ‘stopx’.

. ir
SEC201 | Intro to Computer Fundamentals 189

01
Linux – Xwindows (1)

The XWindows Server is the software that is responsible for drawing the Graphical User Interface (GUI) on the screen. Most desktop operating

de
systems automatically start it on boot. If for some reason it does not start automatically and you wind up at a terminal prompt, you can try to start
it with the ‘startx’ command. Likewise, you can stop it with the ‘stopx’ command.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Xwindows (2)

• Individual programs responsible for the appearance of the GUI are


layered on top of the XWindows system
• The two main programs are GNOME and KDE
• Many people have their own preferences, generally you can use
either
• Some applications are specifically built for one or the other and
don’t work without one particular program
• Most applications will function on either

. ir
SEC201 | Intro to Computer Fundamentals 190

01
Linux – Xwindows (2)

The X-Windows system is not responsible for the design of the interface, it is only responsible for drawing interface elements on screen. The

de
design of the interface is handled by a separate program which is layered on top of X-Windows. The two popular interfaces are KDE and
GNOME, it’s really personal preference which one you prefer. There are other less well-known ones; some of them have specific purposes such
as having as minimal a footprint as possible.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Setting up a Web Server Lab (1)

• Go back to the Debian 8 VM


you created earlier in the day
• We’re going to turn it into a
basic web server
• Once it’s booted, click on
‘Activities’ and then type in
Terminal to get to the
terminal

. ir
SEC201 | Intro to Computer Fundamentals 191

01
Linux – Setting up a Web Server Lab (1)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Setting up a Web Server Lab (2)

• With the terminal open type


in the following command:
• $ sudo apt-get install
apache2
• See a problem? Sudo
command not found
• Apparently Debian does not
come with ‘sudo’ installed, so
we have to install it

. ir
SEC201 | Intro to Computer Fundamentals 192

01
Linux – Setting up a Web Server Lab (2)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Setting up a Web Server Lab (3)

• Let’s elevate to the ‘root’ user first with su:


$ su –
• Enter the root password you set when you installed the VM
• If you’re using the pre-built VM the root password is ‘201student’
• Now let’s use apt-get to install ‘sudo’
# apt-get install sudo

. ir
SEC201 | Intro to Computer Fundamentals 193

01
Linux – Setting up a Web Server Lab (3)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Setting up a Web Server Lab (4)

. ir
SEC201 | Intro to Computer Fundamentals 194

01
Linux – Setting up a Web Server Lab (4)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Setting up a Web Server Lab (5)

• With ‘sudo’ installed, we’re making progress. There’s one problem


though.
• The ‘student’ user, or whatever you called your user, does not have
permissions in the sudoers file to do anything as root
• Let’s add that in now:
# visudo

. ir
SEC201 | Intro to Computer Fundamentals 195

01
Linux – Setting up a Web Server Lab (5)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Setting up a Web Server Lab (6)

• Use the arrow keys to navigate to where you see:


• root ALL=(ALL:ALL) ALL
• Then add an entry directly below that line:
• student ALL=(ALL:ALL) ALL
• Make sure to replace ‘student’ with whatever your user account is
called
• Exit with CTRL + X and save your changes
• This will allow the user to use sudo to perform anything as root
• Now type ‘exit’ to switch back to your normal user

. ir
SEC201 | Intro to Computer Fundamentals 196

01
Linux – Setting up a Web Server Lab (6)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Setting up a Web Server Lab (7)

• From your normal user account, re-run the following command:


$ sudo apt-get install apache2
• You will be prompted for your user account password
• If you are using the pre-built VM, the student account password is:
‘201student’
• Next we should install PHP, so run the following command:
$ sudo apt-get install php5
• Finally, restart apache with:
$ sudo systemctl restart apache2

. ir
SEC201 | Intro to Computer Fundamentals 197

01
Linux – Setting up a Web Server Lab (7)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Setting up a Web Server Lab (8)

• We have a very basic web server up and running now


• It’s not ready for production! You’ll need to tweak the settings, but
it will do to test html and PHP code.
• Let’s try it out
• Click on ‘Activities’ and then open Firefox from the dock
• Type: 127.0.0.1 in the browser. This is an IP address that always
points to the local computer. It’s also known as ‘localhost’.

. ir
SEC201 | Intro to Computer Fundamentals 198

01
Linux – Setting up a Web Server Lab (8)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Setting up a Web Server Lab (9)

. ir
SEC201 | Intro to Computer Fundamentals 199

01
Linux – Setting up a Web Server Lab (9)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Setting up a Web Server Lab (10)

• Let’s customise the page briefly to prove it works


• Open the terminal back up, and then change directory to
/var/www/html
• Use nano to create a new file called demo.php. Remember to use
sudo, normal users can’t write to /var/www/html!
• Type out the code below the slide and save it. You don’t have to
understand it yet.
• Then browse to: 127.0.0.1/demo.php and you should see the page
rendering

. ir
SEC201 | Intro to Computer Fundamentals 200

01
Linux – Setting up a Web Server Lab (10)

<html>
<head>

</head>
<body>
<title>It Works!</title>
de
hi
<h1>It Works!</h1>
<p><?php echo “hello”; ?></p>
</body>
</html>

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Linux – Setting up a Web Server Lab (11)

. ir
SEC201 | Intro to Computer Fundamentals 201

01
Linux – Linux – Setting up a Web Server Lab (11)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Troubleshooting – Can’t Run a Binary Executable

• “I can’t run this binary executable.”


• The most common issue is that the executable file has no ‘execute’
permissions
• Use:
$ ls –halt
• to examine the permissions of the file
• If you see there are no ‘x’ permissions set then…
• Set the appropriate permissions with chmod:
$ chmod +x file

. ir
SEC201 | Intro to Computer Fundamentals 202

01
Linux Troubleshooting – Can’t Run a Binary Executable

If you are having trouble running a file which you believe should be executable, most likely the file does not have execute permissions set on it.

de
You can use the ‘ls’ command to view the file permissions:

$ ls –halt
hi
If you see no ‘x’ permissions for your user account (owner, group or other, depending on which you are), then you need to add them. You can do
this with the chmod command:

$ chmod +x file

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Troubleshooting – Compiling an Executable Manually Fails

• “Compiling this executable from the source code manually keeps


failing.”
• This could have a variety of solutions, most likely however is that
you are missing some dependencies
• Sometimes the error will be enough to hint what you are missing
• Other times, you may have to google the error message or re-read
the project’s instructions (usually they will have a list of
dependencies)
• Once you know what you are missing, install it

. ir
SEC201 | Intro to Computer Fundamentals 203

01
Linux Troubleshooting – Compiling an Executable Manually Fails

The reasons a manual compilation can fail are many, too many to cover here. The most common reason would be a missing dependency or

de
dependencies. The error message is usually a helpful indication of what you are missing. Use your package manager to install the missing package
and then try again. If it fails with a different error, install that dependency too, and so on until the program works.

If the error message is not clear, however, try searching for it in google. More often than not, someone else will have had the same problem.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Troubleshooting – I’m Typing a Command but It Says It Can’t be Found

• “I’m typing a command but it says it can’t be found…”


• If you’re sure you installed it, it may not have been moved to your
PATH
• Verify if it is in your PATH by typing:
$ which [command]
• E.g. ‘which cat’
• If the which command does not find it, then it is not in your path
• Use ‘echo’ to determine your PATH:
$ echo $PATH
• Search your system for the binary executable and copy it to a folder in

ir
your PATH

.
SEC201 | Intro to Computer Fundamentals 204

01
Linux Troubleshooting – I’m Typing a Command but It Says It Can’t be Found

If you’ve been trying to run a program and Linux complains that the command is not found, then it may not have been installed into your PATH

de
properly. The PATH is an environment variable which specifies which folders Linux should look in to find executable files when you type a
command. The list is in priority order, so the first entry in the PATH is searched first and if it is found, the other directories are never searched.
This means if you have multiple copies of an executable, you need to make a decision about which one takes priority.
hi
To find if an executable is in your PATH, you can use the ‘which’ command. The syntax is as follows:

$ which [command]

Which will give you the folder which the command is installed in. If it can’t, then that executable file is not in your PATH. You need to figure out
where it was installed and either move it into a folder in your PATH or add the folder it was installed into your PATH. Remember the PATH is an
environment variable so it typically does not survive a reboot. You’ll need to update it in the .bashrc file in your home folder. (Covered in a few
slides).

You can see your PATH with the echo command as in:

$ echo $PATH

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Troubleshooting – I’m Sure I Ran an Update but Nothing Has Changed…

• “I’m sure I ran an update but nothing has changed…”


• Some package managers such as ‘apt-get’ don’t actually update the
system with the ‘update’ command
• Instead the ‘update’ command only downloads a new index for
available software versions
• This is ‘updating’ the repository list
• To actually update software the ‘upgrade’ command is necessary:
$ sudo apt-get upgrade

. ir
SEC201 | Intro to Computer Fundamentals 205

01
Linux Troubleshooting – I’m Sure I Ran an Update but Nothing Has Changed…

If you are trying to update software on your system with the built-in package manager, make sure you are using the right command. For example,

de
with the ’apt’ package manager on Debian based distributions, the command ‘apt-get update’ does not actually update software packages installed
on your system. Instead, that command will update the repository list, which is used to determine if any of your programs needs to be updated.

In order to actually perform the update, after you’ve updated your repository list, you must follow up with an ‘apt-get upgrade’.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Troubleshooting – Network Service Won’t Start (1)

• “I’m trying to start this network service (web server, ftp server,
etc.), but it just won’t start…”
• There may be an application already listening to that port installed
• Remember that each port is unique to an application
• Check with the command:
$ netstat –tpan
• This should show you the application that is listening to the port
you wish to use

. ir
SEC201 | Intro to Computer Fundamentals 206

01
Linux Troubleshooting – Network Service Won’t Start (1)

If you are trying to start a network service and it is failing, it may be because there is already an application listening on that port. You can use the

de
‘netstat’ command to view a list of listening ports. See if the port your application is trying to use is in that list. The syntax is:

$ netstat –tpan
hi
Once you’ve found the application that is listening on the port you want to use, you should either uninstall or, if you need a temporary solution
only you can kill the process.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Troubleshooting – Network Service Won’t Start (2)

• You can then uninstall it, or if you just need to kill it you can get the
PID of the application with:
$ ps aux
• and then
$ kill [PID]
• Note that it may start again at boot if it was setup as a service

. ir
SEC201 | Intro to Computer Fundamentals 207

01
Linux Troubleshooting – Network Service Won’t Start (2)

In order to kill a process that is using a port, first, you must determine the process name. Once you have the name determined you need the PID or

de
Process Identifier for that process. You can find that using the ‘ps’ command. The syntax is as follows:

$ ps aux
hi
You should be able to find the process amongst that list. It may help to pipe the results to grep such as:

$ ps aux | grep –i “processname”

Once you have the PID, you can kill the process with the kill command:

$ kill [PID]

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Troubleshooting – I Don’t Know What Type of File This Is…

• “I don’t know what type of file this is, there is no file extension…”
• Linux does not make much use of file extensions, instead it focuses
on the ‘file header’
• The file header is part of the file and says what kind of file it is
• Linux provides a ‘file’ command which can read the header and tell
you what kind of file it is
• Just type:
$ file filename

. ir
SEC201 | Intro to Computer Fundamentals 208

01
Linux Troubleshooting – I Don’t Know What Type of File This Is…

Most files except for plaintext files and encrypted files will contain a file header. The file header is a series of bytes which indicates the type of

as follows:

$ file filename
de
file it is. Linux has a ‘file’ command, which reads these bytes and looks them up against a listing to tell you what type of file it is. The syntax goes
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Tips – .bashrc (1)

• The ‘.bashrc’ file is a hidden file that lives in the user’s home
directory
• It is a list of commands that get run when the user opens up an
interactive shell/terminal. This also applies to when a user logs in
through the GUI.
• You can do things like export environment variables here so that
they always exist

. ir
SEC201 | Intro to Computer Fundamentals 209

01
Linux Tips – .bashrc (1)

The .bashrc file is a hidden file that lives in the user’s home directory. It contains a list of commands that get run when a user opens up an

de
interactive shell / terminal. This applies when logging in through the GUI, as well as over SSH. It is a good place to export environment variables
so that they persist across a reboot.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Tips – .bashrc (2)

• The .bashrc file also allows you to setup aliases. This means you
can specify a command name and then what will run when you
type it.
• A common one would be to map ‘sl’ to ‘ls’ because it is commonly
mistyped
• In addition to aliasing commands, you can change the bash prompt
here
• The bash prompt is actually an environment variable called $PS1
• By editing the variable you can change the appearance of the
prompt

. ir
SEC201 | Intro to Computer Fundamentals 210

01
Linux Tips – .bashrc (2)

You can also use the .bashrc file to create aliases for commands. A common one is to alias ‘ls’ to ‘ls –Gh’ to turn on color coding of different

de
filetypes. There are usually some reasonable defaults in this file already so you can use them as a reference. Finally, you can use the .bashrc file to
customize the terminal prompt. The $PS1 environment variable is the one to change here.
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux Tips – .bashrc (3)

• Here is an example of a $PS1 setting:


• \\u@\h : \\w]\\$
• The u is for username
• The h is for the hostname (up to the first ‘.’)
• The w is the path of the current working directory
• So you would see the prompt as:
• SEC201@slingshot : ~/Documents/day2$

. ir
SEC201 | Intro to Computer Fundamentals 211

01
Linux Tips – .bashrc (3)

The $PS1 setting: \\u@h: \\w]\\$ will display a prompt such as: SEC201@slingshot: ~/Documents/day2$. The format is:

u = username
h = hostname (up to the first ‘.’)
w = current working directory path
de
hi
By changing this format you can either add more information to the prompt or remove some information. Since the file is in .bashrc the
environment variable will only be changed after closing the terminal and opening a new one.

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||
||||||||||||||||||||

Linux – Installing Arch Linux (Optional Out of Class Exercise)

• Arch Linux is a highly customizable distribution


• Famous for its difficult installation process
• Everything must be installed piece by piece, as there is no
automated process
• Must be installed from a terminal prompt
• Worth doing at least once in your lives, it will solidify many of the
things learned in this book
• Find a guide on the installation process online if you need it, but
make sure you understand what each command you type does!

. ir
SEC201 | Intro to Computer Fundamentals 212

01
Linux – Installing Arch Linux (Optional Out of Class Exercise)

This page intentionally left blank.

de
hi

Join us now -> hide01.ir | donate.hide01.ir | t.me/Hide01 | t.me/RedBlueHit


||||||||||||||||||||

You might also like