0% found this document useful (0 votes)
11 views57 pages

Linuxby Avinash

The document outlines an 18-day course designed to teach Linux, covering topics such as the Linux operating system, open source principles, distributions, basic commands, file management, user management, and process management. It provides a comprehensive introduction to Linux, including its directory structure, boot process, and essential commands for file manipulation and user management. The course aims to equip learners with the skills needed to master Linux effectively.
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)
11 views57 pages

Linuxby Avinash

The document outlines an 18-day course designed to teach Linux, covering topics such as the Linux operating system, open source principles, distributions, basic commands, file management, user management, and process management. It provides a comprehensive introduction to Linux, including its directory structure, boot process, and essential commands for file manipulation and user management. The course aims to equip learners with the skills needed to master Linux effectively.
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/ 57

Your Path to Linux Expertise: 18-Day Course

By
Avinash Reddy Thipparthi
YouTube : https://youtube.com/@avizway
LinkedIn : https://www.linkedin.com/in/avizway/
WHAT WILL YOU LEARN TODAY..??

• What is Linux.?
• Why to use Linux.?
• What does Open Source Means.?
• Where to download the Linux Kernel Source Code.?
• Linux Distributions
• How to Practice Linux.?
What is Linux.?

Linux is a family of open source Unix-like operating systems based


on the Linux kernel, an operating system kernel first released on
September 17, 1991, by Linus Torvalds. Linux is typically packaged
in a Linux distribution.

Source : https://en.wikipedia.org/wiki/Linux
Why Linux.?
What is running on Linux.?
➢ Free
➢ Stable
➢ Supercomputers
➢ Secure
➢ Embedded Systems
➢ Open Source
➢ Robotic Operating Systems (ROS)
➢ Satellite Communication Systems
➢ Internet of Things (IoT) Devices
➢ Flight Simulators
➢ Bitcoin and Cryptocurrency Mining
➢ Advanced driver assistance systems
(ADAS)
Open-Source.?

Open-source software is software with source code that anyone can inspect,
modify, and enhance.
▪ We can access the Source code of the Linux OS.
▪ Allowed to run the program for any purpose / usage.
▪ Allowed to Change the program working procedure.
▪ Free to distribute.
https://www.kernel.org/
Linux Distributions

Distribution : Package Management system or Collection of software.


distro in Linux is like a unique flavour or version of the operating system.

Debian-based distributions:
Ubuntu
Linux Mint
Kali Linux

Red Hat-based distributions


CentOS (Free Community Version)
Fedora (Commercial version, Need to pay for support)
How to Mastering Linux.?
Linux Boot Process
Init
• Looks at the “/etc/inittab” file to decide the Linux run level.

• Init identifies the default init level from /etc/inittab and uses that to load all appropriate
program.

• Most of the times default run level is set to 3 or 5.


Runlevel programs

• When the Linux system is booting up, you might see various services getting started.
• In Simple, It is same as Windows startup programs.
• Runlevel default init settings will execute the programs from one of the this directories.
Run level 0 –> /etc/rc.d/rc0.d/ , Run level 1 –> /etc/rc.d/rc1.d/,
Run level 2 –> /etc/rc.d/rc2.d/ …………. Run level 6 –> /etc/rc.d/rc6.d/
• Chkconfig –list
Boot Issues:

• File system corruption is one of the most common boot-time problems.


• It can occur after a system crash causes the machine to shut down without correctly un
mounting its file systems.
• File System corruption happens because the operating system users RAM as disk buffer
to improve performance, when power fails, information written to memory buffers
which is not yet synchronized to the disk is lost.
Linux Directory Structure
/ : This is a top level directory. It is parent directory for all other directories, It is
represented by the forward slash (/). This is called Root Directory

/root : it is home directory for the root user (superuser). It provides the working
environment for the root user. (C:\Users\Administrator)

/home : It is the home directory for other users in Linux. It provides a working
environment for other users (other than root).

/bin : it contains commands used by all users (Binary files) i.e; ls, cp, mv

/boot : The /boot file system contains the Linux kernel, boot support files, and boot
configuration files for Linux. Holds files necessary for booting the OS.
/dev : it contains device files Like hardDisk: /dev/hda cdrom: /dev/cdrom (Similar
to device manager of windows)

/etc : Contains all system level configuration files Like /etc/passwd, User info /
etc/resolv.conf Preferred DNS /etc/dhcpd.conf

/usr : by default Software are installed in /usr directory (c:\program files)

/sbin : it contains commands used by only Super User (root)


(Super user’s binary files)

/var : Persistent Variable data. Contains data that frequently changes while the
system is operational. Contains files that change in size, like log files (/var/log/messages)
and databases (/var/lib/mysql).
/mnt : This directory is used to mount a file system temporarily. Empty by default

/media : Used by the system to automatically mount removable media, such as CD,
DVD, USB, and Zip drives. it contains all of the removable media like CD-ROM, pen drive

/lib : It contains library files which are used by OS. It is similar to dll files of
windows. Library files in Linux are SO (shared object) files

/proc : It contain process files. Its contents are not permanent, they keep
changing. It is also called as Virtual Directory. It contain useful information used by OS
like RAM/SWAP/CPU

/lib and /lib64 : Holds libraries needed by programs, like libc.so.6.

/opt : This file system holds additional software installed on the system. A sub-
directory is created for each installed software. It is optional directory for usr. It contains
third party softwares.
Linux Basic Commands
env : Displays all the environment variables for the user
which ls : ls is in a directory called bin (/usr/bin/ls)
pwd : Print working directory
history : Shows the history
~user : Specified Users home directory
whoami : Shows as what user we are working now
uname : Prints the system information
man uname : Tell you all commands
uname -a : Print all information
sudo su : switch to root user
ls : list files and directories from current location
ls -a : list all
ls path : list from mentioned path (ex: ls /etc/ or /etc/*)
touch : create a empty file with given name
cd : change directory
cd .. : goes one step back from current path
Cd path. : takes its to the specific path.
Action File Directories
Create touch FILE mkdir NAME
Copy cp FILE TARGET cp –R DIR TARGET
Move mv FILE TARGET mv DIR TARGET
Move / Rename mv FILE TARGET mv DIR TARGET
Delete rm FILE rmdir DIR
rm –r DIR
rm –rf DIR
rm test/* everything inside the test directory
rm -r test recursive
WHAT WILL YOU LEARN TODAY..??

• File level commands


• Vim Editor
• Word Count
• Creating Zip files in Linux
cat filename : View data from a file
more filename : View data from a file
head /etc/passwd : Displays top 10 lines
tail /etc/passwd : Display bottom 10 lines
head -n 2 /etc/passwd : Displays only top 2 lines
tail -n 2 /etc/passwd : Displays only bottom 2 lines
pr /etc/passwd : Gives proper format while printing
sort /etc/passwd : Sort a file alphabetical order
Vim is an editor to create or edit a text file.

There are two modes in vim.


1. Command mode : Can move around the file, delete text etc
2. Insert mode : Can insert text

Changing mode from one to another


From command mode to insert mode type I
From insert mode to command mode type Esc (escape key)

:wq : Write file to disk and quit the editor


:q! : Quit (no warning)
o : Open up a new line following the current line and add text there.
k : Moves the cursor up one line
j : Moves the cursor down one line
X : Delete character
dw : Delete word from cursor on
db : Delete word backward
dd : Delete line
d$ : Delete to end of line
nG : Cursor goes to the specified (n) line
:set number : Sets Number for lines
:set no number : to remove line numbers
Word Count

wc filename : word count in a file (lines, words, bytes)


wc -l file : Only line count
nl filename : It adds line numbers
fmt filename : Split files into multiple lines if have large data
Using ZIP Format
sudo yum install zip -y
sudo yum install unzip -y

zip archive.zip file1.txt file2.txt file3.txt : Zip Multiple Files


zip archive.zip * : Zip everything from cure dir
zip -r archive.zip mydirectory : Zip entire folder
unzip archive.zip : Unzip
ZIP / Unzip files

tar czvf file.tar file1.txt file2.txt (create zip file / verbose file)
gzip file.tar.gz : To compress the tar file
tar ztf file.tar.gz : To view the files from a tar file
tar xzvf file.tar.gz : To unzip tar file
-c: Create a new archive
-z: Compress the archive using gzip
-v: Verbose mode, showing progress in the terminal
-f: Specifies the name of the archive file
WHAT WILL YOU LEARN TODAY..??

• Managing Files and Directory permissions


ls -l --> to view the permissions

We can manage permissions in two ways. Numerical and alphabetical way...

- rw- r-- r-- 1 root root 0 Oct 23 12:29 a.txt


u g o
file type : File permissions : Link Count : Owning User :
owning Group : File size in bytes : Last modified : file name
File Type:

- regular file
d Directory
l link
p named pipe
s socket
c character device (/dev)
b block device (/dev)
chmod : To modify permissions of a file
chown : To change the ownership
chgrp : To change the group

Numerical permissions : ( 2^2 2^1 2^0) (4 2 1)


Read :4 rwx = 4+2+1 = 7 -wx = 0+2+1 = 3
Write :2 rw- = 4+2+0 = 6 -w- = 0+2+0 = 2
Execute :1 r - x = 4+0+1 = 5 -x- = 0+0+1 = 1
r-- = 4+0+0 = 4 --- = 0+0+0 = 0
Chmod U | G | O filename
chmod 7 | 7 | 7 filename chmod rwx rwx rwx filename
chmod 755 filename chmod rwx r-x r-x filename
rwx rwx rwx
user group other
u g o

r --> Read
w --> Write
x --> Execute

we can manage these permissions using below three characters also


+ add
- remove
= set
chmod a=rwx filename
chmod a-x filename : removing X permissions for all
chmod u+x filename : adding X permissions for User
chmod u=rwx,go-wx filename : adding rwx to user and removing
wx for GRp, Oth
chmod -R a+X directory : As it is a directory, applies for sub
folders (Recursive)
WHAT WILL YOU LEARN TODAY..??

• User Management
• Create User and Managing groups
In Linux every process runs as a user.

Every user have it's own home directory (/home)

We have 3 types of Accounts


--> root (admin) - UID 0
--> System Accounts - UID 1-200 (mapped) & 201-999
(reserved/allocated based on installed services)
--> Regular users - UID 1000+.
id : Gives information about currently working user
id root : To view information about root
whoami : Tell you as a what user you are working
id -u : Tells you id
id -un : Tells you username
User Database Files

/etc/passwd : This file contains Account information


Account name : shadow password : UserID : primary Group ID: Full Name :
Home Directory : Login shell

/etc/shadow: This file contains Password information


Account Name : Password Information (algorithm, random Salt, password hash) :
password age
users : Gives information about logged in users
who : More information about logged-In users
w : Detailed information

su - / sudo su : Switch to root user (ec2-user is default user)

useradd username : Created user


passwd username : Set password

getent passwd UN : Entry in passwd file


getent shadow UN : Entry in shadow file
getent group UN : Entry in group file
getent gshadow UN : Entry in gshadow file
usermod : To edit user

usermod -G wheel UN : To change users group

usermod -a -G wheel UN (append group)

usermod -L UN : To locks a user account

usermod -U UN : To unlocks a user account

userdel UN : To delete an account

usermod -s /sbin/nologin testuser : Remove /bin/bash for user


groups : Tells you what group you belongs to

groups UN : Tell you specified user member of how many groups

groupadd GroupName : Group added

usermod -aG GroupName Username

groupdel GroupName : Deletes the group


/etc/passwd : This file contains Account information

username: The user's login name. This must be unique for each user.
x: Placeholder for the password. Actual password information is stored in /etc/
shadow for security reasons.
UID: User ID. A unique number assigned to each user.
GID: Group ID. The primary group ID associated with the user.
comment: A field for additional information about the user. Often used for the
user's full name or contact details.
home_directory: The path to the user's home directory.
shell: The path to the user's default shell (e.g., /bin/bash).
/etc/shadow: This file contains Password information

username: The user's login name. Matches the username in /etc/passwd.


password: The encrypted password. If the password field contains a * or !, it
means the account is locked.
last_change: The number of days since January 1, 1970, when the password was
last changed.
min: The minimum number of days required between password changes.
max: The maximum number of days the password is valid.
warn: The number of days before password expiration that the user is warned.
inactive: The number of days after password expiration that the account is
disabled.
expire: The number of days since January 1, 1970, when the account will be
disabled.
/etc/shadow: This file contains Password information

chage -l Username

Last password change : Oct 23, 2019


Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change :0
Maximum number of days between password change : 99999
Number of days of warning before password expires :7
Lock User :

sudo getent shadow avinash


sudo usermod -L avinash
sudo getent shadow avinash
sudo usermod -U avinash

Restricting a user to Login using “Noshell”:

If you don't want to login any user to login to system, but want to user for
accessing any service, we can set shell to "nologin"

sudo usermod -s /sbin/nologin avinash


WHAT WILL YOU LEARN TODAY..??

• Managing Process
In Linux OS Process Can be started by following services
--> systemd
--> Linux kernel
--> User commands

Some of the Processes will have parent processes

Every process will assign with "PID"

foreground Process: runs in CLI and can view.

Background Process: runs in background and can be executed by adding &


jobs : To view all suspended / background processes.
pstree : Shows the process tree pstree |less
ps : Current running process to our terminal
ps aux : Shows in cleaner way
ps faux : Shows process tree also
q : To Quit
top : shows process, contineously running list /
Monitor system realtime (z gives color)
Process state : R : Running
S : Sleeping (interruptible)
D : sleeping (uninterruptable)
T : Suspended
Z : Zombie (defunct)

uptime : gives system uptime information

Free : shows free memory


Free -h : Shown in readable format

kill PID
WHAT WILL YOU LEARN TODAY..??

• Package Management
• Rpm vs yum
• How to add repository
A package format is a type of archive containing computer programs and
additional metadata needed by package managers.

In simple, software installations, manages and uninstallation will be taken care


by Linux Package Manager.

rpm is the Package manager for RedHat systems


Rpm : RedHat Package Manager.
httpd- 2.4.59-2. fc41. aarch64. rpm
Package Package version Package Release Target Architecture file Ext

rpm -ivh package name

Problem with rpm is, it cannot resolve dependencies automatically, So we have


YUM
YUM : Yellowdog Updater Modified

• We called it as "Wrapper" for RPM.


• Can resolve dependencies.
• Can retrieve packages automatically.
• Automatic updates
• Package groups for clusters.

when we run YUM, it verifies in "Local Storage“ and then Global Repos.
We can get repo list by running “yum repolist” command

/etc/yum.repos.d/*.repo : location of Repos in Amazon Linux


yum update
yum update kernel

Apache installation:
yum search httpd
yum info httpd
yum install httpd

Start the Service


systemctl start httpd service httpd start
systemctl enable httpd chkconfig httpd on
To install epel repository
For Amazon Linux 2 : sudo amazon-linux-extras install epel -y

yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-


latest-7.noarch.rpm
yum-config-manager --enable epel
yum repolist

Nginx install :
yum info nginx
amazon-linux-extras list
amazon-linux-extras install nginx1
yum history
yum history ID
yum history undo ID
Yum history rollback ID
yum history info ID
yum info package_name
yum search keyword
sudo yum update
Yum install/remove package name

/var/log/yum.log
WHAT WILL YOU LEARN TODAY..??

• Setup hostname
• Basic Network commands
• IP Address information
Pipes : output of a command can be delivered as a input to another command

> replace / overwrite the information

>> append

Echo : Generates the same data

Hostname / hostnamectl : Gives us Hostname information


Hostnamectl set-hostname : To set a new hostname
Ping google.com –c3 (Pocket Internet groper)

dig google.com (Domain information groper)


(required : dnsutils/bind-utils)
dig example.com mx/ANY

dig ns google.com : Gives us Name Server records

mtr google.com : Connectivity between local device and website

ss : To know port status

ss -lt : show services running on TCP ports


IP Address Information:

Use the Ec2 Instance Meta-data to know the Public-ip and Private-ip of our
running ec2- instance.
Metadata URL: http://169.254.169.254/latest/meta-data/

NIC Card Information :


Regular Systems : enp0s3 : UP (en : Ethernet, p0 : Port 0, s3 : slot 3)
AWS : eth0
ip address show
ip addr
ip a s
/etc/sysconfig/network-scripts/** : Network config files path

You might also like