Linux Overview & Basics
Linux is an open source and most used operating system created in 1991 by Linus Torvalds. It is widely used in the software industry for developing and maintaining highly robust application. It offers security, privacy, task automation, system updates and it is developer friendly in nature. It has pre installed tools and binaries that helps in the various phases of SDLC.
The benefits of using Linux
It offers a free operating system. You do not have to spend hundreds of dollars to get the OS like Windows!
- Being open-source, anyone with programming knowledge can modify it.
- The Linux operating systems now offer millions of programs/applications to choose from, most of them free!
- Once you have Linux installed you no longer need an antivirus! Linux is a highly secure system. More so, there is a global development community constantly looking at ways to enhance its security. With each upgrade, the OS becomes more secure and robust
- Linux is the OS of choice for Server environments due to its stability and reliability (Mega-companies like Amazon, Facebook, and Google use Linux for their Servers). A Linux based server could run non-stop without a reboot for years on end.
There are two types of distributions on which linux has been distributed.
- Debian Based:
Debian based distros contains . deb files/packages. The packages/softwares can be installed by the package manager(dpkg/apt). Most common known debian based distros are ubuntu, Linux Mint, kali linux etc…
2. RPM Based
Rpm based distros contains .rpm files/packages. The packages/software can be installed by the package manager( yum/ dnf ). Most commonly rpm based distros are(Fedora, CentOS, RHEL).
Types of Users:
There are three types of user in linux: — Root, Regular and Service. Each user on a Linux system is assigned a unique user identification number, also known as a UID. It is the same as we have in windows, administrator, standard and guest.
Root users: Root users are the administrative users also known as super user, that has access to all the files, services and commands in linux. For root, the associated UID,GID is set to 0.
Regular users: Regular users are the users created by the root or another user with sudo privileges. Usually, a regular user has a real login shell and a home directory. Each user has a numeric user ID called UID and GID attached.
Service users: Services such as Apache, Nginx, mail, games, and printing have their own individual service accounts. These accounts exist to allow each of these services to interact with your computer.
A Kernel is at the nucleus of a computer. It makes the communication between the hardware and software possible. While the Kernel is the innermost part of an operating system, a shell is the outermost one.A shell in a Linux operating system takes input from you in the form of commands, processes it, and then gives an output. It is the interface through which a user works on the programs, commands, and scripts. A shell is accessed by a terminal which runs it.
UID: User ID
GID: Group ID
PID: Process ID
Linux Directory Structure
Different types of shell
Shell scripting/ Bash Scripting:
A shell script is a list of commands in a computer program that is run by the linux shell which is a command line interpreter in order to execute a particular task. Shell scripts has an extension of .sh. It includes manipulation of strings, output, and files/directories etc.
The steps in creating a Shell Script:
- Create a file using a vi editor(or any other editor). Name script file with extension .sh
- Start the script with #!/bin/sh
- Write some code.
- Save the script file as filename.sh
- For executing the script type bash filename.sh
echo "what is your name?"
echo "How do you do, $name?"
echo "I am $remark too!"
Every file and directory in your UNIX/Linux system has following 3 permissions defined for all the 3 owners discussed below.
- Read: This permission give you the authority to open and read a file. Read permission on a directory gives you the ability to lists its content.
- Write: The write permission gives you the authority to modify the contents of a file. The write permission on a directory gives you the authority to add, remove and rename files stored in the directory. Consider a scenario where you have to write permission on file but do not have write permission on the directory where the file is stored. You will be able to modify the file contents. But you will not be able to rename, move or remove the file from the directory.
- Execute: In Windows, an executable program usually has an extension “.exe” and which you can easily run. In Unix/Linux, you cannot run a program unless the execute permission is set. If the execute permission is not set, you might still be able to see/modify the program code(provided read & write permissions are set), but not run it.
You can check the permission on directories and files with this command:
A ‘cron’ is a job scheduler that is found in Unix-like operating systems. Any task that is scheduled to be down is called a ‘cron job’. This is useful for any action that needs to scheduling. Something like, say, scheduling emails! The schedule for all tasks is stored in the ‘crontab
Usage: To schedule a command or program to run at a particular interval of time.
This cron job will run every minute, all the time:
* * * * * [command]
This is also an hourly cron job but run at minute 15 instead (i.e. 00:15, 01:15, 02:15 etc.):
15 * * * * [command]
This will run once a day, at 2:30am:
30 2 * * * [command]
This will run once a month, on the second day of the month at midnight (i.e. January 2nd 12:00am, February 2nd 12:00am etc.):
0 0 2 * * [command]
This will run on Mondays, every hour (i.e. 24 times in one day, but only on Mondays):
0 * * * 1 [command]
You can use multiple numbers separated by commas. This will run three times every hour, at minutes 0, 10 and 20:
0,10,20 * * * * [command]
Division operator is also used. This will run 12 times per hour, i.e. every 5 minutes:
*/5 * * * * [command]
Dash can be used to specify a range. This will run once every hour between 5:00am and 10:00am:
0 5-10 * * * [command]
Also there is a special keyword that will let you run a cron job every time the server is rebooted:
Universal Default Ports
#Default portsFTP 21 REDIS 6379
SSH 22 ORACLE 1512
Telnet 23 MONGODB 27017
SMTP 25 SQL 3306
DNS 53 MARIADB 3306
HTTP 80 MS SQL 1433
HTTPS 443 DB2 50000
RDP 3389 ELASTIC 9200