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

Introduction To Linux - 2

Uploaded by

rp4403682
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Introduction To Linux - 2

Uploaded by

rp4403682
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Introduction To Kali Linux

Operating System is the main system software which is


responsible for the flawless working of the machine. Some
Operating Systems are designed for some specific
purposes. Though we could use them for anything we want
to, but they have some special tools or services available
feasibly to its users which makes it a good OS for the
specific purpose. Like we generally prefer Windows in case
of gaming as most of the games are available for windows
itself. Likewise, we prefer mac OS for designing related
purposes as most of the designing software is easily
available for mac and can be used flawlessly. In the same
way when we have an OS for Network Security, Digital
Forensics, Penetration testing, or Ethical Hacking named
Kali Linux.

Kali Linux is a Debian-derived Linux distribution that is


maintained by Offensive Security. It was developed by Mati
Aharoni and Devon Kearns. Kali Linux is a specially
1

All Rights Reserved.


Copyrights © by MRWEBSECURE.
designed OS for network analysts, Penetration testers, or in
simple words, it is for those who work under the umbrella
of cybersecurity and analysis. The official website of Kali
Linux is Kali.org. It gained its popularity when it was
practically used in Mr. Robot Series. It was not designed for
general purposes, it is supposed to be used by professionals
or by those who know how to operate Linux/Kali. To know
how to install Kali Linux check its official documentation.

Advantages:
It has 600+ Penetration testing and network security
tools pre-installed.
It is completely free and open source. So you can use it
for free and even contribute for its development.
It supports many languages.
Great for those who are intermediate in linux and have
their hands on Linux commands.
Could be easily used with Raspberry Pi.

All Rights Reserved.


Copyrights © by MRWEBSECURE.
Disadvantages:
It is not recommended for those who are new to linux and
want to learn linux.(As it is Penetration Oriented)
It is a bit slower.
Some software may malfunction.

Kali Linux is to be used by those who are professional


penetration testers, cybersecurity experts, ethical hackers,
or those who know how to operate it. In simple words, if
you know how to use Linux and its terminal commands,
architecture, system, and file management then you are
good to go with Kali Linux. And if you are not, then we will
recommend you first start with ubuntu distribution and get
your hands on Linux and after sufficient practice, you could
give Kali Linux a try. This will not only save your time of
searching on the internet but also will make you use it with
ease. However, if you’re a professional penetration tester or
studying penetration testing, there’s no better toolkit than
Kali Linux.

All Rights Reserved.


Copyrights © by MRWEBSECURE.
Why Kali Linux?

If you are interested in penetration testing or cybersecurity


stuff you need some specific tools to perform some tasks
which come pre-installed and settled up in Kali Linux so you
may directly use them without doing any configuration. Or
in case if one wants to check the vulnerabilities on a
website or want to know security-related bugs in any
application then it is great to go with Kali Linux.
Many people think that Kali is a tool for hacking or cracking
social accounts or web servers. This is one of the biggest
myths about Kali Linux. Kali Linux is just another Debian
distribution with a bunch of networking and security tools.
It is a weapon to train or defend yourself not to attack
anyone. Kali Linux was designed mainly for professionals. It
is for those who want to get their hands in Penetration
Testing, Cyber Security, or Ethical Hacking. It is a powerful
tool and in case, not used properly, it may lead to losses
even.

All Rights Reserved.


Copyrights © by MRWEBSECURE.
Elementary LinuxCommands

You might be asking, “Why should I take the trouble to learn


Linux commands? Can I not practice my ethical hacking
skills with any tool?”
My answer is, “No, you cannot move in the right
direction if you don’t know elementary Linux commands.”
In fact, after a certain stage, you will have to master Linux
programming because without mastering Linux
programming, you cannot master ethical hacking or
penetration testing as a whole. In the coming chapters,
you will find many examples where you have to open the
Kali Linux terminal and type commands. For example,
when you work with hacking tools and frameworks such
as Nmap or Metasploit, you have to use the terminal. So,
it is good to get acquainted with some elementary Linux
commands now.
Let me give you a real-life example. You have
installed Kali on your VirtualBox. Now you need to

All Rights Reserved.


Copyrights © by MRWEBSECURE.
configure it to its full potential so that you can use it.
Specifically, when you need to update and upgrade your
Kali distribution, you have to open the sources.list file
and uncomment a few lines. If you know a few
elementary Linux commands, this will take not take
more than a few minutes. Either you can do it on a
terminal using vim or nano or you can use the built-in
Leafpad text editor. Either way, it’s a must. But it’s
good to know that Linux programming is easy to learn.
In this chapter, you’ll learn some common Linux
commands. These commands will tell you about the
computer itself. They will tell you the location of the
file system, or where you are on your computer.
You’ll also learn how to change the permission of a
file system, copy a file, or permanently remove a
file. You will also learn how to add a new user to
your system and get a list of files that are currently
in the directory where you are, including the hidden
files.
In a nutshell, you will learn to do basic operations
6

All Rights Reserved.


Copyrights © by MRWEBSECURE.
through your keyboard without using your mouse
pointer. If you are already a seasoned Linux
programmer, you can skip this chapter.

Finding the Kali Terminal

To begin, let’s first start your newly installed Kali


Linux. On the top left of the screen, you will find the
Applications link. Click it, and it will open a list of
applications, as shown in Figure 3-1.

All Rights Reserved.


Copyrights © by MRWEBSECURE.
Figure 3-1. Kali Linux applications

On the top of the list is Iceweasel, the default browser of


Kali. It’s an extension of the normal Mozilla Firefox, so don’t
expect it will keep you anonymous. The logo has changed
recently, so when you install Kali Linux, you will be greeted
by the new logo, but basically, it is Firefox.
Next follows the command-line tool, in other words,

All Rights Reserved.


Copyrights © by MRWEBSECURE.
the terminal. You will need this tool often in the coming
lessons. The command-line tool basically deals with all
types of keyboard inputs. Good programmers
hardly use a mouse pointer. They are more comfortable
using this terminal and typing in the necessary commands.
The Files folder is next, and after that, you can clearly see
the important hacking tools such as Metasploit, Armitage,
Burp Suite, Maltega, and so on. You’ll take a close look at
those tools in the coming chapters.
Let’s start with the command tool by opening it. You can
make it look bigger by pressing Ctrl+Shift and pressing the
+ key. To make it smaller, press Ctrl+Shift and the - sign.

Navigating the File System

Your first command will be pwd (print working


directory). It will show your current position in the file
system.
The pwd command generates output that looks like this:

/root

All Rights Reserved.


Copyrights © by MRWEBSECURE.
This means you are in the root directory. That’s
quite natural since you have logged in as the
superuser, or root.
Let’s type ls to show the list of what’s in this directory.
What does that
ls command mean? It stands for “listing.” You tell Kali
to show the listing of files and folders that you have in
the root directory, and in a fraction of a second, it
shows you all it has.
Next, try the cd command, which stands for “change
directory.” You can use this command to change the
directory to any of the listings that are showing up on
the terminal. If you want to go to the Downloads
directory, you’d type the following:

cd Downloads

You have not downloaded anything, so the directory is


empty.

The next big task is to learn to create another user.


Let’s create another user called sanjib.
10

All Rights Reserved.


Copyrights © by MRWEBSECURE.
Remember that you are logged in as root or
superuser. The commands and the output are shown
here:

root@kali:~# adduser
sanjibAdding user
`sanjib' ...
Adding new group `sanjib' (1001) ...
Adding new user `sanjib' (1000) with group
`sanjib' ...Creating home directory
`/home/sanjib' ...
Copying files from `/etc/skel'
...Enter new UNIX password:

Retype new UNIX password:


passwd: password updated successfully
Changing the user information for sanjib
Enter the new value, or press ENTER for the
defaultFull Name []: sanjib sinha
Room Number
[]: 123Work

11

All Rights Reserved.


Copyrights © by MRWEBSECURE.
Phone []: 321
Home Phone []:
213
Other []: he is a nice guy
Is the information correct? [Y/n] y
root@kali:~#

Congratulations! You have just successfully created a


new user called sanjib. You notice that you were asked for
the password and had to retype the UNIX password.
Figure 3-2 shows what it looks like in the virtual
machine.

12

All Rights Reserved.


Copyrights © by MRWEBSECURE.
Figure 3-2. Adding a user in Kali Linux through
commands

Now change the directory to home and issue the ls


command again. This directory has one folder called
sanjib and a file. The folder sanjibmeans the system
itself has a user called sanjib. You have created that
user as the root or administrator, so you can log in as
sanjib if you want.
13

All Rights Reserved.


Copyrights © by MRWEBSECURE.
As a root user, you can see the newly created user
sanjib with the help of the following command:

//code to move to sanjib


directoryroot@kali:# cd /home
root@kali:/home# ls
sanjib
root@kali:/home# cd
sanjib/
root@kali:/home/sanjib
# pwdhome/sanjib

When you are in the sanjib directory, you can see


the current position by issuing the pwd command.
Here are more details about the ls command:

• In the terminal, you can use ls -a to


view the hidden files.

• There is a difference between ls -r and ls -R. The


ls -r command will list in reverse order,
and ls -Rwill list the directory tree in a
recursive order, showing subdirectories.
14

All Rights Reserved.


Copyrights © by MRWEBSECURE.
• The ls -s and ls -S commands are not
the same. The ls -s command will give
you a simple listing of file sizes. If you
want to sort them according to their
sizes, use ls -S.

• The ls -X command will list by extension name.

If you want to know more about the ls command,


please issue the man -ls command on your terminal.
This is true for any other command you want to
know in detail.

You can create several users on a Linux system so that


from various machines they can log into their files and
folders. However, the users will never have root
privileges. They can’t penetrate the administrator’s space,
but the root user or administrator can always see the
users’ space and watch what they are doing. Also, a root
user or an administrator can always create and delete any
user.
You can now see what is happening in your newly

15

All Rights Reserved.


Copyrights © by MRWEBSECURE.
installed Kali Linux.

You can change the directory and look what sanjib has in
the directory Downloads. Currently, the user sanjib has
nothing in that folder; it is empty.
Next you’ll learn about cp command. This command
stands for “copy.”

You can copy a file from one destination to the other. You
have seen that in the home directory you have a file called
VBoxLinuxAdditions.run. Let’s copy this file to the Documents
directory of user sanjib.
You have already reached sanjib, so you have to come
back to the /home
directory first. Issue the command cd .., which will take you
one step back.

root@kali:/home/sanjib# cd ..
root@kali:/home# cp -v VBoxLinuxAdditions.run
/home/sanjib/Documents/
'VBoxLinuxAdditions.run' -
>'/home/sanjib/Documents/

16

All Rights Reserved.


Copyrights © by MRWEBSECURE.
VBoxLinuxAdditions.run'
root@kali:/home#

Now go to the sanjib documents folder and see


whether the file has been properly copied.

root@kali:/home# cd
sanjib/Documents/
root@kali:/home/sanjib/Documents#
ls VBoxLinuxAdditions.run
root@kali:/home/sanjib/Documents#

Here I have changed directory to


sanjib/Documents and issued the ls command to see
the listing. It shows the file. So, everything is
working properly.
You can learn about any command easily. You just need
to add the

--help command like this:

cp --help

This spits out everything about that command, and the


17

All Rights Reserved.


Copyrights © by MRWEBSECURE.
output is very verbose. It tells you about any command in
full detail.
Another important command is mv. With this
command, you can move

any file from one folder to another folder. This


command is more or less like a cp command, but this
command completely moves the file from one place to
the other. Another important command is cat. You
can read any text file with the help of this command,
as you’ll see in the next example.

Working with Text Files

In this section I’ll show another trick that is often


used in Linux. Suppose you want to write a text file
quickly. You can use nano, which comes with every
Linux distribution. Just type nano in your terminal,
and it will open up a text editor on the terminal.
Let’s edit the novel.txt file. In that case, you
need to enter this command in your terminal:
18

All Rights Reserved.


Copyrights © by MRWEBSECURE.
nano novel.txt

This will tell nano to open the file. You can edit any
portion by pressing Ctrl+O and saving it. Then you can exit
the file by pressing Ctrl+X.
Now you can safely read the new file novel.txt with your
cat

command. All you need to do is issue a command on your


terminal like this:

cat novel.txt

It will read your file on the terminal itself.

Usually, seasoned programmers like to work on the


terminal and use a text editor like vi, vim, or nano, which
are extremely popular because they are fast and easy to
work with.

Searching Files

Now you’ll learn an important Linux command called


grep. This command searches inside a file, and it does it
19

All Rights Reserved.


Copyrights © by MRWEBSECURE.
in an interesting manner. Let’s first see what I have in my
root directory.
For a change, I have issued a command like this on
my original operating system Ubuntu terminal to show
the output:

cd /etc/apt
hagudu@hagudu-H81M-S1:/etc/apt$ ls
apt.conf.d sources.list sources.list.save
trusted.gpgtrusted.gpg.d
preferences.d sources.list.d trustdb.gpg
trusted.gpg~hagudu@hagudu-H81M-
S1:/etc/apt$

As you can see, I have changed the directory to


/etc/apt and am showing the listing in Ubuntu. You can
issue the same command in your Kali Linux and see the
difference.
You will see many files here, and for this example you
are interested in the sources.list file of Ubuntu. You can
use the cat command to read the file, but I have

20

All Rights Reserved.


Copyrights © by MRWEBSECURE.
something different in mind.
Say you want to search for a particular word. The
command grep along with another command | (pipe) will
help you do this.
You actually tell the terminal to display the content of
sources.listfirst and then pipe that term to your
searching process. Let’s see how it works.

If you simply enter a command like cat sources.list, it


will display a long listing of the sources of this Linux
system. You can write and see them. But if you are
interested in searching for the word src and want to see
how many times that word has been used in the
sources.list, you would use the following command:

hagudu@hagudu-H81M-S1:/etc/apt$ cat sources.list | grep


src

The output looks like this:

deb-src http://in.archive.ubuntu.com/ubuntu/
trusty mainrestricted
deb-src http://in.archive.ubuntu.com/ubuntu/ trusty-
21

All Rights Reserved.


Copyrights © by MRWEBSECURE.
updatesmain restricted
deb-src http://in.archive.ubuntu.com/ubuntu/ trusty
universedeb-src
http://in.archive.ubuntu.com/ubuntu/ trusty-updates
universe
deb-src http://in.archive.ubuntu.com/ubuntu/ trusty
multiversedeb-src
http://in.archive.ubuntu.com/ubuntu/ trusty-updates
multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ trusty-
backportsmain restricted universe multiverse
deb-src http://security.ubuntu.com/ubuntu trusty-
security mainrestricted
deb-src http://security.ubuntu.com/ubuntu trusty-
securityuniverse
deb-src http://security.ubuntu.com/ubuntu trusty-
securitymultiverse
# deb-src http://archive.canonical.com/ubuntu trusty
partnerdeb-src http://extras.ubuntu.com/ubuntu
trusty main
22

All Rights Reserved.


Copyrights © by MRWEBSECURE.
# deb-src http://archive.ubuntu.com/ubuntu trusty
universehagudu@hagudu-H81M-S1:/etc/apt$

If you issue a command like this, the long output


will show all the statements that have src in them:

cat sources.list | grep src

You can even filter the source file more distinctly. For
example, you can narrow down your search and tell the
terminal to find the word src only in lowercase by writing
this command:

cat sources.list | grep –i src

In the future, you will need to use this grep command


extensively to scan a network for a particular word.

Writing to the Terminal

Another important command is echo. This command


literally “echoes” everything you write on your terminal.
You can also do something more with this command. You

23

All Rights Reserved.


Copyrights © by MRWEBSECURE.
can change a text file with this command.
Previously, you wrote a text file called novel.txt and
saved it in the home directory. Now you’ll overwrite that
file with this echo command:

hagudu@hagudu-H81M-S1:~$ echo "I DON'T LIKE THIS


NOVEL ANYMORESO I CHANGE IT" > novel.txt
hagudu@hagudu-H81M-S1:~$ cat novel.txt

Here is the output:

I DON'T LIKE THIS NOVEL ANYMORE SO I CHANGE IT

You first echoed some text on the terminal and then


used the redirect command (>) to put that text into the
file novel.txt. Then, you used the cat command to read the
file novel.txt and find out that the file has been changed.

24

All Rights Reserved.


Copyrights © by MRWEBSECURE.
Working with Directories

Now you will learn how to make directories in Linux.


The useful command mkdir stands for “make directory.”
Let’s make a directory named after this project: Ethical
Hacking. You may have guessed that the command is
extremely simple, as shown here:

mkdir Ethical Hacking

No, it is not. In this case, if you write that way,


the Linux terminal understands something else. It
comprehends that you want to create two separate
directories. One is Ethical, and the other is Hacking.
It creates two directories in that way. So, let’s
remove them first, and next you will create a
meaningful directory.
To remove a directory, you must have root
privileges. This means you need to be an
administrator or superuser of the system. On Ubuntu,
if you want to be a root or superuser, you issue the

25

All Rights Reserved.


Copyrights © by MRWEBSECURE.
command sudo first. In Kali Linux, it is su.
Nevertheless, in both cases, once you write that
command, the system will ask for the password
through the terminal.
Let’s see how it works.

First issue the command, and in the next step, you


check with the ls command to see whether those
directories exist anymore. Suppose you log in as user
sanjib and have a folder called Ethical Hacking that was
created by the root user in the /home/sanjib folder. If
sanjib wants to delete it, he needs to know the root
password first. Next he has to issue this command:

sanjib@kali#
supassword:

The su command asks for the password. Now sanjib


has to type the root password to gain control as the
superuser. After that, he can issue the rm (remove)
command.

root@kali:/home/sanjib# rm -rf Ethical/ Hacking/


26

All Rights Reserved.


Copyrights © by MRWEBSECURE.
It worked; two directories have been removed
successfully. Let’s try to understand this more. You already
know that the rm command stands for the word remove.
But what about the -rf command that follows it? The
command -rf means “do it recursively with force.”
Generally, this -rf command is used to remove directories.
You have to be careful about using this command. In
Linux, once you have used this command, the file or
directory is deleted permanently. It is next to impossible
to retrieve them. It is wise to be careful about using it.
Let’s again make the directory properly and this time
name it Ethical-Hacking so that the system will no longer
interpret it as two separate directories.

hagudu@hagudu-H81M-S1:~$ mkdir Ethical-


Hackinghagudu@hagudu-H81M-S1:~$ cd
Ethical-Hacking/ hagudu@hagudu-H81M-
S1:~/Ethical-Hacking$ ls
hagudu@hagudu-H81M-S1:~/Ethical-Hacking$ touch
file1 file2hagudu@hagudu-H81M-S1:~/Ethical-Hacking$
ls
27

All Rights Reserved.


Copyrights © by MRWEBSECURE.
file1 file2
hagudu@hagudu-H81M-S1:~/Ethical-Hacking$

First, you made the directory Ethical-Hacking. Then,


you used cd to go inside it, and with the help of ls you
checked that the directory is empty. Afterward, you
issued the touch command to create two files:
file1 and file2. Again, you issue the ls command to check
that two files have been created successfully.

Setting File Permissions

In ethical hacking, anonymity is a big deal. In the


coming chapter of building Kali Linux server, you’ll learn
about it in great detail. Here, you need to understand
that in the process of being anonymous, it is good to be
a regular user rather than the root user. As the root or
superuser, you have learned to add a user in your
virtual Kali Linux. Basically, you set a password, shut
down Kali Linux, reboot, and log in as the new user. It is
a good practice.
As the root or superuser, you can add as many
28

All Rights Reserved.


Copyrights © by MRWEBSECURE.
users as you want. You can delete them any time.
You can restrict their activities from any angle. As an
administrator, you can add a user who will not be
able to log in after six months. You can create groups
and set a rule so that entry is restricted. Some users
can enter into that group. Some can’t.
A user is not permitted to access or tamper any file
of the root or superuser. However, as a superuser,
you can always change the file permissions. It is an
important concept from every angle. On the Internet,
the concept of file permissions is extremely important.
Any file has three types of permissions related to it.

• Read: The file can be read.

• Write: The file can be written to.

• Execute: If a file is executable, you can


perform an action by running it.
Suppose you’ve written a simple
Python program. This program will
take inputs from users and give
29

All Rights Reserved.


Copyrights © by MRWEBSECURE.
outputs. After writing a Python file, you
can make it executable.

Let’s see how it happens. Let’s open the Kali Linux


terminal, and with the help of the ls command, you can
see what you have there.

sanjib@kali:~$ cd
Documents/
sanjib@kali:~/Documents$
ls VBoxLinuxAdditions.run
sanjib@kali:~/Documents$
ls -latotal 7048
drwxr-xr-x 2 sanjib sanjib 4096 May 29 10:30 .
drwxr-xr-x 18 sanjib sanjib 4096 Jun 3 09:59 ..

-r-xr-xr-x 1 root root 7208397 May 29


10:30VBoxLinuxAdditions.run
sanjib@kali:~/Documents$

First, you go to the Documents folder and issue the ls


command. That shows only one file: VBoxLinuxAdditions.run.
The next command is
30

All Rights Reserved.


Copyrights © by MRWEBSECURE.
ls -la. It means you want a listing of all files with all
details. You can see the difference in the previous
example. It shows two hidden files with the previously
shown file. It also shows the owners of files, as well as
the permissions. Let’s consider this line in more detail:

-r-xr-xr-x 1 root root 7208397 May 29


10:30VBoxLinuxAdditions.run

This tells you that the owner of this file is root and the
group name is
root. The starting line is important. It handles file
permissions.

r-xr-xr-x

What does this mean? It has three distinct parts


consisting of three characters each. Each part in the
previous code is r-x. Here, r stands for “read,” and x
stands for the “execute” permission. The – is a blank
where the write permission is not set.

• The first part (the first three characters)


31

All Rights Reserved.


Copyrights © by MRWEBSECURE.
is for the owner of the file.

• The second part is for group permissions.

• The third part is for the superuser.

I have already created another user called sanjib and


have logged in as sanjib. So, the permissions you see
here are for this user.

Now to make this concept clearer, you will create a


user named xman, and you will log in as xman to see
what you have in the Documents folder. Here are the
commands:

xman@kali:~$ cd
Documents/
xman@kali:~/Documents
$ ls
xman@kali:~/Documents
$ ls -latotal 8
drwxr-xr-x 2 xman xman 4096 Jun 3 10:33 .
drwxr-xr-x 14 xman xman 4096 Jun

32

All Rights Reserved.


Copyrights © by MRWEBSECURE.
3 10:33
..xman@kali:~/Documents$

Now I’ll create a file using the nano text editor. Here
is the executable file in Python:

#!/usr/bin/python3
print("TYpe your
name.")inputs =
input(">>>>>>")
outputs = inputs
def main():
print(outputs)
if name == ' main ':
main(
)

33

All Rights Reserved.


Copyrights © by MRWEBSECURE.
I’ve saved the file as pyfile.py and then exit nano. Now
let’s issue
ls -la to see what it shows:

xman@kali:~/Documents
$ ls -latotal 12
drwxr-xr-x 2 xman xman 4096 Jun 3 10:50 .
drwxr-xr-x 15 xman xman 4096 Jun 3 10:42 ..
-rw-r--r-- 1 xman xman 86 Jun 3
10:44 pyfile.pyxman@kali:~/Documents$

As you see, the command output tells you everything


about the file. It says that now the Documents folder has one
new file called pyfile.py, and it was created at 10:44. The
owner is xman, and it has file permissions like this:

rw-r--r--

Now, what does this mean? It means the user xman can
read and write this file, because it is prefixed by rw; here w
stands for write permission.

34

All Rights Reserved.


Copyrights © by MRWEBSECURE.
However, the user xman can’t execute this file. Can you
make it executable? You can with the following code:

xman@kali:~/Documents$ chmod +x
pyfile.pyxman@kali:~/Documents$ ls -la
total 12
drwxr-xr-x 2 xman xman 4096 Jun 3 10:50 .
drwxr-xr-x 15 xman xman 4096 Jun 3 10:42 ..
-rwxr-xr-x 1 xman xman 86 Jun 3
10:44 pyfile.pyxman@kali:~/Documents$

Look how you use the chmod command to change the


file permission to executable. Once you have changed the
file permission to executable, it changes the color to
green. You can also change the file permission by using
numbers such as 775; you will find tons of free reading
materials on this topic. I encourage you to do more
research on this topic because file permission is an
integral part of Linux security programming.
Also, look at this file permission:

rwxr-xr-x
35

All Rights Reserved.


Copyrights © by MRWEBSECURE.
The first part of the permission says x has been added
since you used this:

xman@kali:~/Documents$ chmod +x pyfile.py

Let’s execute the file and see how it takes the input and
give the output.

xman@kali:~/Documents$
./pyfile.pyTYpe your name.
>>>>>
>xman
Xman

When you run the file, it asks you to type your


name, and it gently spits back the output.
Another important command is chown. Since Linux is a
multiuser OS,

as a system administrator you must keep an eye on


everything. You need to be careful about who is
allowed to access a file and how they can access it. If
you feel a file should not belong to a certain user, you

36

All Rights Reserved.


Copyrights © by MRWEBSECURE.
can change the owner of the file.
Look at the next commands:

ls -l myfile
-rw-r--r-- 1 sanjib group1 0 2018-05-22 20:03
myfilechown root myfile
ls -l myfile
-rw-r--r-- 1 root group1 0 2018-05-22 20:03 myfile

By issuing chown root myfile, you have changed the


owner of the file.
Likewise, you can change the group by changing group1 to
group2.

Issue this command:

chown sanjib:group2 myfile

This will change the owner and the group at the same
go. Now again

sanjib is the owner of this file; however, the group has


been changed.

37

All Rights Reserved.


Copyrights © by MRWEBSECURE.
In this chapter, you learned a few basic Linux
commands. You have an idea of how a Linux system
works and how you can use your terminal or
command line to operate your system.

In the learning process of ethical hacking, you will find


learning Linux programming extremely useful. In the future,
you will need to learn a few more Linux commands. Your
knowledge of Linux or any other operating system must be
commendable if you want to be an expert ethical hacker.

38

All Rights Reserved.


Copyrights © by MRWEBSECURE.
39

All Rights Reserved.


Copyrights © by MRWEBSECURE.

You might also like