Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 66

Linux administration Session

Agenda:
Day 1:
 Introduction to Linux

 Installation and Directories

 commands Management

 User & Group

 Permissions & Umask

 Special Permission
Agenda:
Day 2:
 I/O Redirection & Piping

 Searching Management

 Management suders_file

 Management vi, vim Editor

 Management Linux Remotely

 Network Management
Agenda:
Day 3:
 Process Management

 Package Management

 Management Services

 Boot Sequence

 Reset Root Password


DAY (1)
Introduction to Linux
Linux Distribution:
is an operating system that is made up of a collection of software based on
Linux kernel or you can say distribution.
Around 600 + Linux Distributions are available, some of the popular Linux
distributions ( Linux Mint, Ubuntu, Debian, Fedora, openSUSE, Kali, Parrot )
Linux architecture has the following components
Follow Introduction to Linux
Kernel
is the core of the Linux based operating system. It virtualizes the common
hardware resources of the computer to provide each process with its virtual
resources. The kernel is also responsible for preventing and mitigating
conflicts between different processes. Different types of the kernel are: 
1- Monolithic Kernel 2- Hybrid kernels
3- Exo kernels 4- Micro kernels
System Library
Is the special types of functions that are used to implement the functionality
of the operating system.
Shell
It is an interface to the kernel, It takes commands from the user and
executes the kernel’s functions.
System Utility:
It provides the functionalities of an operating system to the user.
Installation and Directories
Type of Partitioning Style

MBR GPT
Installation and Directories
Following Directories
commands Management
How You Can Read Path

Absolute Path Relative Path


Command [Option](s) [argument](s)

Man Command

Chapter 1 Chapter 5 Chapter 8


commands Management
If I create file have the same name of existing file.
what it is happened !

If you copy file to Destination that have file with


the same name. what it is happened !
User & Group Management
Type of users

Super User (Root) Regular User Service User

Commands

Useradd Groupadd
Usermod Gpasswd
Follow User & Group Files
/etc/passwd file format

/etc/gshadow file foemat


Group name : password : administration : member

Important files
/etc/skel /etc/default/useradd
/etc/passwd /etc/group file

/etc/shadow file /etc/shadow file


Permissions & Umask
Permissions & Umask

What is the Supplementary group

Permission File Directory

R Read List every thing in Directory

W Edit file Mkdir,cp,mv,rm

X Execute Give access for user to enter


the Directory
Permissions & Umask

Symbolic
+ grant - Deny = set
Permission Symbolic Numeric

Read +r 4

Write -w 2

Execute =x 1
Permissions & Umask

Chmod u,g=wr , o+r file_test


Chmod 664 file_test
Permissions & Umask

What this command will do ?


Chmod +r file_test
Chmod +w file_test
Chmod +x file_test

What is the meaning of change the (Group for file)


This meaning I want to make this file is sharing for some user have
the permission to access this file
If I change the primary group for user this user created some ( files and
Directories) in (/ path ) and another (files and Directories) in (Home
Directory)
what will happen for both files and Directories after change the Group?
(The files and Directories) in / path > will stay with the old name of
primary Group
(The files and Directories) in Home Directory > will change
Permissions & Umask

Umask
for file : will Subtract (x) from permission
For Directory : will Subtract the umask
Umask

777
Super user 777 Regular user -
-
Umask = 002 002
Umask = 022 022
Directory permission 775
Directory permission 755
-
-
Xxx
Xxx
File permission 664
File permission 644
What is the minimum permission
D1 D2 F1
Touch D1/f1
Mkdir D1/D2
Cp D1/f1 D2
Mv D1/f1 D2
Vm D1/f1

Is it possible to create a file with the same name as an existing folder?


Special Permission
Sticky bit
For Directory, any user create file just the owner of file can delete the file
Set Group Id
For Directory and file, any file or Directory created will inherit the
permission from parent

Set user id
only for file, when execute the file will execute as I'm owner of file
The Numerical permission
Sticky bit 1
Set user id 4
Set group id 2
Special Permission
Owner group other Note the capital S. This means
Rwx rwx rwx there are no execute
permissions
s S s S t T

Set user id Set group id Sticky bit


chmod u+s file1 chmod g+s file1 chmod a+t file1
chmod 4751 file1 chmod 2770 file1 chmod 1777 file1
DAY (2)
Agenda:
 I/O Redirection & Piping
 Searching Management
 Management suders_file
 Management vi, vim Editor
 Management Linux Remotely
 Network Management
I/O Redirection & Piping

I/P Programe O/P

Error
> o/p Redirection (overwrite)
>> o/p Redirection (append)
< I/p Redirection
2> save & overwrite Error in file
2>> save & append Error in file
I/O Redirection & Piping
Some commands

Ls > file.txt
Echo “ Hello World” > file.txt
Echo “Hello world 2 “ >> file.txt
Wc –l < file.txt
Mkdir d1 f1 2> /dev/null
Tr ‘a-z’ ‘A-Z’ < /etc/passwd >f1.txt
I/O Redirection & Piping

Piping
is used to combine two or more commands, and in this, the output of one
command acts as input to another command, and this command’s output
may act as input to the next command and so on
command_1 | command_2 | command_3 | .... | command_N

Some commands
ls -l | more
cat sample2.txt | head -7 | tail -5
cat result.txt | grep "Rajat Dua" | tee file2.txt | wc –l
Head –n 15 /etc/passwd | tail –n 3 | tr ‘a-z’ ‘A-Z’ | tr –d “:/” > file_txt.txt 2> error.txt

Tee command
Head –n 15 /etc/passwd |tee file_test | tail –n 3 | tee file_test2………….
Searching Management
To search

locate find

locate
It is run on pre build Database(DB) this DB include all path of files
and directory, but the first must run command (updatedb)

find
Slower than locate, but it is smart because have option help me in
search
Find [path to search in ] [the name of file or directory ]
Searching Management

Some commands (find )

Find / test_file
Find / -type f –user test
Find –ctime -10
Find /home/test - perm / 744
Find /home/test –size 1024k
Find –user test –mot –group test
Find –user test –o –group test
Find –not \(-user test –o –user fetoo\ )
Find /home/test –iname *.mp3 –delete
Find /home/test –iname “*”.mp3 –exec cp {} /home/fetoo/d1 \;
Management suders_file

To change the ( Regular user ) to be (administration user)

/etc/sudeors
If I add user to wheel Group this meaning the user has root
permission
%sales > Group called sales
Sales > user called sales

Can I give special permission for user ?


Yes
Ali All=/usr/sbin/useradd, /usr/sbin/userdel
Management vi, vim

Vi , vim
It is an editor like text editor in windows , and we have another app
editor in Linux such as (nano , gedit ) but need to install this packages

https://www.tutorialspoint.co
m/unix/unix-vi-editor.htm#
Management Linux Remotely
Authentication in ssh

User & password Key based


authentication
User & password
Ssh username@ip_of_server
After login the public key of server saved in file ( ~/.ssh/known_host )
And the second time login to same server, it don’t ask me about are u
sure about this server
Management Linux Remotely ( User & password )

The method to transfer files between 2 machine


1- Scp command 3- winscp
2- sftp command 4-MobaXterm
Scp command
Upload
Scp f1 f2 username@ip_server : location
Scp –r f1 f2 username@ip_server : location

Download
Scp username@ip_server:/home/username/d1 /home/localname/
Scp –r username@ip_server:/home/username/d1 /home/localname/
Management Linux Remotely ( User & password )

sftp command
Sftp username@ip_of_server
Upload
Put /home/test/d1/f1
Put –r /home/test/d1/f1
Download
Get /cloud1/test/f1

Winscp & MobaXterm


This are windows application to connect, upload and download
files and directory from win to Linux
Management Linux Remotely

Key based authentication

Public key Private key

Local Cloud
server server

Copy
Public key Save public key in
Private key to ~/.ssh/authorized_key
Management Linux Remotely

Step 1 ( Local server )


Ssh-keygen (command)
to generate key in ~/.ssh it include 2 file
id_rsa private key
id_rsa.pub public key
Step 2 ( Local server )
Need make copy for public key from local machine to cloud machine

ssh-copy-id -i ~/.ssh/ id_rsa.pub username@ip_of_cloud


Network Management

Method to MgMt Network

GUI CLI

ifconfig nmtui nmcli

first check Network service


sudo systemctl status NetworkManager
sudo systemctl status networking
Network Management
ifconfig
If command (ifconfig) not exist : Will install package network-tools

Ifup interface_name
Ifdown interface_name
ifconfig <interface_name> <ip_address> netmask <netmask_address>

To check Routing
ip route
Route –n > list routing _table
Route add default <gateway_ip>
ip route add <network_ip>/<cidr> via <gateway_ip> dev <network_card_name>
* ip route add 10.0.3.0/24 via 10.0.3.1
Network Management

nmtui
Network Management

nmcli
To Create a network profile
Nmcli connection add con-name test ifname ens130 type ethernet ipv4.method manual
Ipv4.address <ip_address> ipv4.gateway <IP_GW> ipv4.dns 8.8.8.8
To Modify
Nmcli connection modify test Ipv4.address <ip_address> ipv4.gateway <IP_GW>
ipv4.dns 8.8.8.8

nmcli connection show


nmcli connection show –active
nmcli connection up test
Nmcli connection reload test
Nmcli connection delete test
Network Management
The important files for Network
sudo vi /etc/sysconfig/network-scripts/ifcfg-ens130
Network Management
The important files for Network
/etc/hosts > list local DNS

/etc/hostname > list the hostname

/etc/resolv.conf > list DNS


Network Management
The important files for Network
/etc/resolv.conf > list DNS
DAY (3)
Agenda:
 Process Management
 Package Management
 Management Services
 Boot Sequence
 Reset Root Password
Process Management
Process
A process is an instance of a program running in a computer, it Run by
(user & group) permission.
A process can initiate a subprocess, which is a called a (child process)

To manage process

GUI CLI
Task manager tor
Process Management

command to list all run process


Ps aux
ps aux | grep <name_of_app>
Pgrep <name_of_app>

command to Kill process


Kill <process_id>
kill –<num_of_signal> <process_id>
Pkill <name_of_app>

By default signal 15, named SIGTERM is sent to kill process


Process Management

Signals
Package Management

Pkg.deb > debian –ubunto –kali – parrot – mint (apt , dpkg)


Pkg.rpm > centos, RedHat (yum, rpm)

If install package and this package need another packages the another
packages called (dependences)

package
It is special archive and it include (GPG Key) to (secure) to ensure this
package is trusted

Yum
Yum This is Repository
ine client
f server Include all packages
re de tory
P osi
rep
Package Management
Some command to check repo
Yum list
Yum repolist
Yum repolist all
Every repo under this path
/etc/yum.repos.d
Package Management

How I can create special repo?

1- /etc/yum.repos.d
2- create file.repo (test.repo)
3- vi test.repo
After open (test file) will write this format in file
4-[name] (repo_test)
5-baseurl= put the repo URL
6-enabled=1
7-Gpgcheck=0
Package Management

Some command to install packages


Yum install <pakg_name> Will install package
Yum search <pakg_name> If I don’t know the package name
Yum list installed Will list installed packages
Yum provides /etc/passwd Will list the (package name download this file)
Rpm –qc <pakg_name> list the dependences you need to install package
Rpm –ql <pakg_name> List the path of files that download when install package
Rpm –qi <pakg_name> List information about package

/etc/yum.conf

clean_requirement=false < to remove all dependences


when remove packages
Management Services
Will find all service
/etc/systemd/system/multi_user.target.wants

To Management services

status
start
Systemctl enable <service name>
stop
reload

Any service is enabled , take shortcut from file of service


and putted it under (/etc)
Management Services
Run Level (systemctl)
0 > power off. target 3 > multiuser. Target
1 > rescue. Target 4 > multiuser. Target
2 > multiuser. Target 5 > graphical. Target

The most important target just 2 target


1-multiuser. Target
2-graphical. Target

/etc/systemd/system/default.target
OR
/usr/lib/systemd/system/multi-user.target
To tell system when start, which target will use to
open it.
Management Services

Some commands
Systemctl get_default
Systemctl set_default <multi-user.target>
Systemctl isolate <multi-user.target>

How I can enter the Rescue Mode


Rescue Mode :- to solve the problem in your distory
1-reboot
2-when grup menu display click (e)
3- systemd.unit=rescue.target
Management Services

How you can know the number of service is (enabled)


Here will find all service in enabled

/etc/systemd/system/multi-user.target.wants/

Will list all services

Systemctl list –unit-files

Will list all enabled services


Ls –l /etc/systemd/system/multi-user.target.wants | wc -l
Boot Sequence
1-power
POST (Power on self test) : It is Group of Roles to check the Hardware

2-bootstrap (Bios)
BIOS : include the information (first boot device)
UEFI : It is update of BIOS
Partition table

3-MBR Boot loader

Magic number
Boot Sequence
Boot loader :- called first stage
The function of Boot loader
Is refer to the second stage of Boot loader in Hard disk which partition
include boot loader ex(hd0,sda1/boot/grup)

4-Grup
Boot loader in second stage
It is refer to Kernel and kernel start the init service

5-systemd
Used to start rest of the services Systemd.target
Boot Sequence
Kernel

Kernel file Modules& Drivers

/boot /boot
(vmlinuz……) (initramfs……)

InitRamfs
IT is Very light Image , but temp
Include Complete life destroy, kernel Modules and light file system
Kernel
It initialize the driver by InitRamfs after that execute
the first service systemd
Reset Root Password
To Reset the password follow the steps
1-reboot machine
2-click the character (e) when Grup menu display
3-rd.break
4-ctrl+x
5-will find my destroy inter this path /sysroot
6-mount –o remount,rw /sysroot
7-chroot /sysroot
8-passwd
9-write new password
10-ls –l /etc/shadow < for check
11- touch /.autorelabel
12-exit
13-logout
After logout must display
Warning and some words
to sure every thing is
done

You might also like