LEARN LINUX FROM BASIC TO PRO {A BEGINEER'S GUIDE} - BEING HACKER

YOUR SECURITY IS OUR PRIORITY

Tuesday, 10 October 2017

LEARN LINUX FROM BASIC TO PRO {A BEGINEER'S GUIDE}

LEARN LINUX FROM BASIC TO PRO

CONTENTS

  • LINUX BASICS
  • LINUS SYSTEM ORGANIZATION
  • LINUX DIRECTORY STRUCTURE
  • CREATING FILES
  • EDITING FILES
  • LISTING FILE AND DIRECTORIES
  • DELETING FILE AND DIRECTORIES
  • LOGGING OUT
  • CONNECTING TO A REMOTE HOST
  • SSH ON LINUX

LINUX BASICS :


Linux operating system was developed in 1991 by Linus Torvalds when he was a student of Helsinki University, Finland. He posted about the source code that he developed in the Minix news group. The feedback was good and the source code started to spread around the world via FTP and over the years Linux became a very popular operating system. Today, many great network programs, security tools and servers including DNS, Email and Web server are being developed for Linux by programmers and hackers around the world.

Linux System Organization :

The functioning of Linux is organized in terms of the following layers as shown in the Figure below

  • Hardware Layer consists of the actual hardware devices like CPU, Memory, Hard Disk Drive etc.
  • Kernel is the core component which lies at the heart of the operating system that directly interacts with the hardware using the machine language

  • Shell (or the command interpreter) acts as a mediator that takes commands from the user and then conveys them to the kernel which ultimately executes them.
  • Tools and Applications reside on the outer crust and gives user most of the functionalities of an operating system

Linux Directory Structure :

A directory structure is the way in which the file system and its files of an operating system are displayed to the user. People who are new to the Linux operating system and the structure of its File System often find it troublesome and messed up in dealing with the files and their location. So, let us begin to explore some of the basic information about the Linux File System.

Any standard Linux distribution has the following directory structure as shown below:




Below is a brief description of the purpose and contents of each directory:


/ - ROOT Directory



Every single file and the directory of the Linux file system starts from the root directory. Only “root” user has the write privilege to this directory.

/bin - Binaries

Contains executable binary files required for booting and repairing of the system. Also contains file and commands required to run in single user-mode such as: ls, ping, grep etc.

/lib - System Libraries

Contains system libraries and kernel modules required for the booting of the system.

/dev - Device Files

Contains device related files for all the hardware devices of the system.

/etc - Configuration Files
Contains configuration files required by all programs. It also contains start-up and
shutdown shell scripts used to start or stop individual programs.

/home - Home Directories

This forms the “home directory” of individual users to store their personal information. Every time a new user is added, a new directory is created in the name of the user under “/home”.

/user - User Programs

This directory is used to store executable binaries, documentation, source-code  files  and libraries for second level programs.

/tmp - Temporary Files

Contains temporary files for system and users.

/var - Variable Files

Contains files whose size is expected to grow. Examples of such files include log files, print queues, lock files and temp files.

Linux Commands :

All commands in Linux are typed in lowercase and are case sensitive. Each Linux command has to be typed and executed in a window called “terminal emulator” or simply referred to as a terminal. It is a program similar to the command prompt of Microsoft Windows where a user can run the commands and get the results displayed. A terminal simply takes the user commands, passes it on to the shell for execution and displays the results back to the user.

To run commands in the terminal, you will have to first load the Linux from the Live DVD that you have created. To do this, just insert the Kali Linux DVD into the drive, boot from it and select the “Live option”. Once the booting is completed you should see your desktop loaded on your screen.

To start the terminal window, just click right-click on the desktop and select the option Open in Terminal as shown in the below snapshot :




Once the terminal window is loaded you should be able to start typing the commands. A snapshot of the terminal window is shown below:




Creating Files :


There are two commands for creating files: touch and cat. Here is how they are to be used:
# touch sample
This creates an empty file called “sample”. If you want to create multiple empty files quickly it can be done as follows:
# touch sample1 sample2 sample3 sample4 sample5
In order to store a few lines of data onto the file just type the following command:
# cat > sample
When you press the Enter key, you will find the cursor positioned in the next line waiting for you to type the content that you want to store in the file “sample”. Just type in the following line:

This is a sample file containing some sample text.

Once you are done, press Ctrl+D. This will save the contents onto the file and automatically take you back to the # prompt. Now, to display the contents of the file “sample” just type the command as follows:



# cat sample
This should display the contents of the file as shown in the snapshot below:




Editing Files :

To edit a given file one has to use the vi command. In order to edit a given file “sample” the command is as follows:


# vi sample


When you type the above command and hit Enter, you should see the contents of the file “sample” displayed in the vi editor window as shown in the Figure :




In order to start your edit process you need to enter the INSERT mode by pressing the key
i. Now, your cursor should move freely inside the editor window allowing you to make necessary changes to the content. Once you are done with the editing, press the Esc key. Now type :wq as shown in the below snapshot and hit Enter. The w stands for write/save

and q stands for quit. This should save changes to your file, close the vi editor and take you back to the # prompt. If you are to quit without saving changes just type :q! instead of :wq and hit Enter.






Listing Files and Directories :
  
To display the list of files and directories the command used is ls. ls is the Linux equivalent of DIR command in Windows. To list the files and directories just type the following command and hit Enter.

# ls

Deleting Files and Directories :

In Linux rm command is used to delete files and directories. To delete a file use the command as shown below:

# rm samplefile

When you hit Enter, you are asked for delete confirmation. Just type y and hit Enter again. This should complete the deletion of the file “samplefile”.

To delete a directory and all its contents use the following command:

# rm -r sampledir

When you hit Enter, you are asked for a delete confirmation. Just type y and hit Enter again. This should complete the deletion of the directory “sampledir” and all the contents inside it.

Logging Out :

Once you are done with your work, you can close the terminal window using the exit
command as follows:

# exit
Connecting to a Remote Host :

So far we have discussed ways to execute commands on your own Linux computer. However, since Linux is a multi-user operating system it is possible for the users to connect to a computer running Linux even if they are miles away from its physical location. In this section we will discuss some of the ways through which you can connect to a remote computer and execute commands on it.

SSH (Secure Shell) is the most popular and the easiest way to accomplish this task. This is a protocol that allows a client to connect to a remote host and carry out operations on it.

SSH on Linux :

If you are on a Linux computer, connecting to another Linux computer is very easy. Just open the Terminal window and type the following command:

Command Syntax:ssh username@host

Here username means username of your account on the remote computer and host can be a domain name such as xyz.com or the IP address of the remote computer. The following examples make it more clear:

# ssh john@xyz.com

# ssh john@66.226.71.129

# ssh root@xyz.com

# ssh root@66.226.71.129

If the user exists on the target machine, the connection will be established and you will be asked to enter the password. Once you enter the password and hit Enter (password entered will be invisible due to security reasons), you will be granted access to the target Linux machine where you are free to execute any command on it as discussed in the previous section.

Here is a list of some of the useful websites to expand your Linux knowledge:


Linux Official Website






Here is a list of some of the great books worth reading:


How Linux Works





No comments:

Post a Comment