/Linux-
Linux is an open source operating system.
In Linux, We use the command line interface to run the programs .
In Linux Open Source OS we can run an application without having hardware and software requirements.
AWS cloud - it provides all the services that we need a virtual machine or software to run in a local machine.
EC2(Elastic Computing Cloud) - EC2 is a web service where the computing can be resizable.
Cloud computing can be categorized into three groups-
1. Private Cloud.
2. Public Cloud.
3. Hybrid Cloud.
Servers-
1. mail server.
2. web server.
3. proxy server.
4. ftp(file transfer protocol)
Containerisation-
Docker
podman
skopeo
buildah
kubernetes
LINUX COMMANDS-
# - denotes root
$ - denote normal user
AWS cloud-
(instance launch)
sudo yum -y install httpd
cat > index.html(command)
sudo systemctl enable httpd
sudo systemctl start httpd
=================
-whoami
(root) - #
-hostname
your hostname will be displayed.
-pwd
present working directory
-useradd
to add a normal user root can add users.
-passwd user_name
to add the password
-su - user_name
we will switch from root to user
example-
useradd chitransh
passwd chitransh
1234
[root@server ~]# su - chitransh
[chitransh@server ~]$ exit
exit command is used to logout
-ls
this command is used to show all the files inside the root
-cat > chitransh
Hi! there mate
-cat chitransh
Hi! there mate(content will be shown)
-rm chitransh
file will be deleted.
-cp chitransh /sub
bin- cmds that all can access.
sbin- cmds only run by root.
=========================
ssh is used to remote access any server/Telnet
but telnet is not secured enough.
ssh root@
==========================
ls command --
Listing directory content
[root@servera ~]# - what does mean
>root- the user (whether root or normal user)
>servera- name of the host(computer)
~ - this represents that root is in its home
# - this represents the root user
In linux, everything is a file
> hardware
> components
>everything
/ - slash directory(super root)
which includes everything
[root@servera ~]# pwd
pwd- present working directory
> /root
[root@servera ~]# useradd chitransh
[root@servera ~]# passwd chitransh
1234
1234
[root@servera ~]# su - chitransh
[chitransh@servera ~]$ su - root
[root@servera ~]# cd /var
[root@servera var]# pwd
/var
here, instead ~ we have var dir specified after the machine name
which says that this is the home where the root user is.
[root@servera var]# cd
[root@servera ~]# touch file1
touch cmd is used to create an empty file
[root@servera ~]# ls
gives the contents insides the directory(/root)
but it doesnot include the hidden files.
Hidden files- starts with a period(.)
Blue color- Directory
White color- File
[root@servera ~]# ls -a
hidden files also be shown
[root@servera ~]# ls -l
longlisting of directory
[root@servera ~]# ls ll
do the same (long listing)
[root@servera ~]# ls --all
it also show all directory with hidden files(Alter:- ls -l)
[root@servera ~]# ls -r
Reverse order
==============================26/08/21
everything is a file
we need a dir to store a file
we have two user
root- /root
normal- /home
/bin - all cmds
/sbin- system binaries (super user authorisation)
/boot-
redhat linux kernel
(core of os)
> kernel related files
/dev
device files
(hardisk, processor, memory)
/etc
server configuration files
> ip address
> mail server file
/usr
>bin(copy)
>sbin(copy)
>tmp
>local
>unix system resource
>documentation
>help pages
/var
variable types of data
dynamic data
(log files)
/run
removabale devices
pan drive
/tmp
temporary mount point
du -hs cmd - file size
ctrl+c = kill the process
how to creatte a file-
cat > file100
this is my file(ctrl+d)
cat file_name
. current dir
cp file_from_copy file_to
mv - to rename
mv file100 file1009
create a dir-
mkdir dir100
mkdir -p dir100/dir200/dir300-> making a tree
-p is used to create parent dir as well
like-
[root@chitransh ~]# mkdir Videos/blow
error will be shown because Videos folder didnot spell correctly.
[root@chitransh ~]# mkdir -p Videos/blow
if you use this instead blow dir will be created inside the new Videos folder
tree dir100
cd - = previous working dir
cd.. = parent folder
cd ../.. = second parent
rm -rf dir100 - used to delete the filled dir(Without any confirmation)
rm -r dir100 - (ask for confirmation)
rmdir - empty dir
ln dir100/dir200/dir300 rum
>link the path to a file
Questions-
cut/paste- how
when root login - it can be without pass
visual editor-
using vi and vim editor we can create , view and edit the file
how to create a file using vi editor-
>vi file54
(window opens-file editor)
>modes-
1. command mode- vi cmds (create)
2. insert mode(edit - write)
3. execute mode(external command)
4. replace mode(char replace)
5. visual mode(visually seen)
i- switch to insert
Esc key- comout from insert(by default mode is cmd mode)
j-
h-
a-
l-
w-
o-next line with insert mode
O-above the line of cursor
:w - file save
:q - out from vi
:w!- forcefully save
:q!- forcefully exit
:wq - save and exit
:wq! - forcefullly out
:x- save and exit
:x!- force fully
:set nu- line number set
:set nonu
:10- goto line 10
ctrl + shift + ++
vimtutor
how to edit the file-
del the char-
x- one char
3x- three char
dw- to delete one word
3dw-- to delete 3 word
dd- del the line
3dd- del 4 lines
u- undo
how to copy-
yl- copy one char
3yl- 3 char
yw- copy one word
3yw- 3 words
yy- line
6yy- 6lines
p- paste
gg- top
G- bottom
vim-
visual improved
/search word
==================================
User administration and file permission-
User - User is something which performs a certain task.
User-
1. system user- system users are default users created during the linux installation time(root user)
2. normal user- user created by root user for system administration purpose.
3. sudo user- when the normal user is equivalent to root but not root(privilege user)
system user - user id range (0-999)[root user- 0(id)]
normal user - user id (1000-60000)
how to create user-
with useradd command
whenever u create a user with useradd cmd userdatabase file will be updated.
user database file-
/etc/passwd- this file contains user and user related info, havind 7 fields separated by colon.
/etc/shadow- this file contains users passwords and password aging information,having 9 fields separated by colon.
/etc/group- this file contains user's group info having 4 fields separated by colon.
/etc/gshadow- group password info
note:- whenever u create a user , your linux os will create a group and that user belongs to that grp.
bottom 5 lines-
tail -5 /etc/passwd
swapnil:x:1001:1001::/home/swapnil:/bin/bash
1. username
2. user pwd kept in /etc/shadow file in encripted this x link to /etc/passwd to /etc/shadow
3. user id
4. user Primary group id
5. comment field
6. user home directory
7. login shell.
shadow-
swapnil:!!:18871:0:99999:7:::
!!- no password(password stores in second field)
$6$___$ - password encrpted mechanism(rsl algo)
password and hash value combined
creating own id and grp-
> useradd -u 2002 web2
comment field-
> useradd -c developer web3
directory don't want to be the home -
>create a dir
> mkdir dir1
>useradd -d /dir1/user1 user1
changing the shell-
>useradd -s /bin/bourneshell user2
Q. /etc/shadow
fields meanings
user creation and modification -
useranme- ritesh
primary- japan
sec - london
comment- /newhome
loginshell- /bin/sh
useradd -u 2001 -g japan -G london -c student -d /myhome/ritesh -s /bin/sh ritesh
usermod - user updation
userdel- user deleted
delete user's home dir-
userdel -ritesh
-m - move used with directory
Default settings-
cat /etc/default/useradd
su root- switching user without home dir
su - root - switching user with home dir
chsh nisha5-
changing shell
chfn nisha5-
finger information will be stored
{comment}
shadow fields-
1.username
2.!! -password not set
3. last change.
(total no. days )
4. minimum days for change passwd
(validity)
5. maximumdays
6. 7 days earlier messaage before account expiring
7. account enable or disable
8. password expiry date
9. flag(how many chance - to block)
/var/spool/mail- user created (mail box created)
login definition-
ls /etc/login.defs
chage -l user_name
(password aging information)
chage user_name - to change the password aging
usermod -U nikita- unlocking nikita
user -L nikita- locking
(! in shadow file/encrpted password)
??
as we create a user mail is created inside /var/spool/mail
so if we delete the user and it is not there in /etc/passwd so why it is not deleted from /var/spool/mail
vim /etc/login.defs
==========================
USERS file and directory permissions-
file is created-
permissions-
owner | group owner | other user
rw- | r-- | r--
420 | 400 | 400
===========
6 4 4
r : read permission(4)
w : write ..(2)
x : execute permission(any programming language file execution)(1)
- : no permission(0)
when a file is creted the permission is by default 6 4 4
owner- all permission
all users - no permission
4 2 1 | - - - | ---
==============
7 0 0
chmod 700 file_name
chmod cmd is used to change the permissions.
chown user_name file_name
chgrp group_name file_name
write-
cat >> file_name
execute-
bash file_name
./file_name or /path/file_name
NOTE-
================================================================
USER 1 USER2
>file1
>file2
we created file1 and file2 inside USER1 and want to access from USER2
>what we gonna do??
owner grp owner others
- rw- | r-- | r-- 1 root root 40 date file_name
we will make user2 as Group owner of file1 then we can access file1 from user2
How to make user2 group admin of user1 -
usermod -g user2 user1(user_name)
if-
the user dir of user1 has all the permission (rwx) to enter
and then the file inside the dir will be given the permission you want to access from user2
================================================================
User file and dir permission-
default permissions for file 644
all permission for file 666
why is default permission is so?
umask is responsible for that.
umask is a numerical value which is used to decide the default permission.
Default permission = Full permission - umask
0666
- 0644
========
0022 -> this is the umask
0777
- 0755
===========
0022
vim /etc/bashrc
vim /etc/profile
umask 0044
changed
-umask value for root user 022
-full permission full-umask= default
-umask 0055- temporary set
/etc/profile or /etc/bashrc
-for user, umask is defined 077 in /etc/login.defs
File backup compression, decompression, searching
-searching using locate and find
create 10 files
example- file1, file2....file10
tar- backup
tar -cvf all.tar *
tar -tvf all.tar
cvf- create verbose(output) file
tvf- used for show the tar file
compress-
gzip all.tar
=========
becomes
all.tar.gz
uncompress-
gunzip all.tar
or
bzip2 all.tar(more compressed)
bunzip2 all.tar (uncompressed)
==========
xz all.tar(more compressed)
unxz all.tar(uncompressed)
tar -rvf all.tar india123- add new
tar -xvf all.tar india123- extract
delete from archive-
tar --delete -f new.tar file_name
Backup + Compression-
tar -cvzf my.tar.gz file* : gzip
tar -cvjf my.tar.bz2 file* : bzip2
tar -cvJf my.tar.xz file* : xz
searching a file-
locate file_name
locate command not able to search
find cmd-
find / -name file_name
find / -uid ---
find / -gid ---
find / -user user_name
find / -group group_name
find / -size +5M : above 5 mb
find / -size -10G : below 10G
find / -perm 000
---------------------------
updatedb - to update the database of os
locate file_name(redhat)- now it will locate
no permission files-
shadow
gshadow
shadow-
gshadow-
want oto search the string -
grep - content filter
grep word file_name
grep -i word file_name : ignoire case
grep -n word file_name :
starts from root-
grep -n ^root
ends with root-
grep -n root$
only root-
grep ^root$
package management using rpm and yum-
{Redhat linux services and management}
all commmands and configuration files are gonna work only if the package available
rpm - redhat package manager , wecan do pac=kage management using rpm
to search the package-
rpm -qf /etc/passwd
we have two utilities RPM and YUM-
yum remove tree
yum install tree
htttpd(web server package)
- web server commands
- web server configuration file
apache user will be created automatically
To manage the web server we need to start / stop/ restart/ reload the services
-----------------------------
yum remove httpd:- used to remove the package.
yum install httpd:- used to install the package.
yum list httpd:- used to show the package is installed or not.
cat > index.html
cp index.html /var/www/html
is a default location to start the website.
active vs enable
be active but not persistant be active even after rebooting.
all the services-
systemctl list-unit-files :- we can show all the services and their status.
specific services-
systemctl list-unit-files | grep sshd
(services related to sshd will be shown)
services related commands-
systemctl status httpd - used to check the status of service.
systemctl start httpd - to start the service(active)
systemctl stop httpd - to stop(inactive)
systemctl restart httpd- service go down for secs and then up
systemctl reload httpd- solution for service to go down.
systemctl is-active httpd - check the service is active or not.
systemctl enable httpd - service will be stayed after the system iks power off.
systemctl is-enable httpd - check wheather the service is enabled or not.
systemctl disable httpd - to disable the service.
systemctl list-machines
scp package_name root@mynameischitransh:/root
to install-
rpm -ivh package
rpm -q - to query
rpm -e ftp - to erase
rpm -qc package- config files
rpm -qi package - information
rpm -ql package - query list
rpm has dependency problem
yum repolist package
yum info package
Disk Management:-
IDE Controller-
connects with 4 hard disks
- primary master
- primary slave
- secondary master
- secondary slave
/dev/hda
/dev/hdb
/dev/hdc
/dev/hdd
virtual disks:-
/dev/vda
/dev/vdb
/dev/vdc
/dev/vdd
lets take one /dev/sda
MBR - master boot records
disk info
kind of partition:-
primary - max 4 primary
extended- max 1
inside extended partition create logical partition
sda1
sda2
sda3
sda4
we have file system
ext2,ext3,ext4,xfs,gfs
lsblk- lost block device file
/dev/fstab- mount file with disk.
blkid /dev/sdb7
lvm-
-logical volume manager
-disc combination technology
Multiple clubbing disks to create a big space
to create the pv(physical volume)
pvcreate /dev/sdb1 ..more
pvs to verify
vgcreate vg1 /dev/sdb1 /dev/sdb2 /dev/sdb3
vgdisplay
vgextend vg1 /dev/sdb5 - add new
lvcreate -L 500M -n /dev/vg1/lbm1
mkfs -t ext4 /dev/vg1/lvm1
mkdir /a
mount /dev/vg1/lvm1 /a
lsextend
/Linux-
Linux is an open source operating system.
In Linux, We use the command line interface to run the programs .
In Linux Open Source OS we can run an application without having hardware and software requirements.
AWS cloud - it provides all the services that we need a virtual machine or software to run in a local machine.
EC2(Elastic Computing Cloud) - EC2 is a web service where the computing can be resizable.
Cloud computing can be categorized into three groups-
1. Private Cloud.
2. Public Cloud.
3. Hybrid Cloud.
Servers-
1. mail server.
2. web server.
3. proxy server.
4. ftp(file transfer protocol)
Containerisation-
Docker
podman
skopeo
buildah
kubernetes
LINUX COMMANDS-
# - denotes root
$ - denote normal user
AWS cloud-
(instance launch)
sudo yum -y install httpd
cat > index.html(command)
sudo systemctl enable httpd
sudo systemctl start httpd
=================
-whoami
(root) - #
-hostname
your hostname will be displayed.
-pwd
present working directory
-useradd
to add a normal user root can add users.
-passwd user_name
to add the password
-su - user_name
we will switch from root to user
example-
useradd chitransh
passwd chitransh
1234
[root@server ~]# su - chitransh
[chitransh@server ~]$ exit
exit command is used to logout
-ls
this command is used to show all the files inside the root
-cat > chitransh
Hi! there mate
-cat chitransh
Hi! there mate(content will be shown)
-rm chitransh
file will be deleted.
-cp chitransh /sub
bin- cmds that all can access.
sbin- cmds only run by root.
=========================
ssh is used to remote access any server/Telnet
but telnet is not secured enough.
ssh root@
==========================
ls command --
Listing directory content
[root@servera ~]# - what does mean
>root- the user (whether root or normal user)
>servera- name of the host(computer)
~ - this represents that root is in its home
# - this represents the root user
In linux, everything is a file
> hardware
> components
>everything
/ - slash directory(super root)
which includes everything
[root@servera ~]# pwd
pwd- present working directory
> /root
[root@servera ~]# useradd chitransh
[root@servera ~]# passwd chitransh
1234
1234
[root@servera ~]# su - chitransh
[chitransh@servera ~]$ su - root
[root@servera ~]# cd /var
[root@servera var]# pwd
/var
here, instead ~ we have var dir specified after the machine name
which says that this is the home where the root user is.
[root@servera var]# cd
[root@servera ~]# touch file1
touch cmd is used to create an empty file
[root@servera ~]# ls
gives the contents insides the directory(/root)
but it doesnot include the hidden files.
Hidden files- starts with a period(.)
Blue color- Directory
White color- File
[root@servera ~]# ls -a
hidden files also be shown
[root@servera ~]# ls -l
longlisting of directory
[root@servera ~]# ls ll
do the same (long listing)
[root@servera ~]# ls --all
it also show all directory with hidden files(Alter:- ls -l)
[root@servera ~]# ls -r
Reverse order
==============================26/08/21
everything is a file
we need a dir to store a file
we have two user
root- /root
normal- /home
/bin - all cmds
/sbin- system binaries (super user authorisation)
/boot-
redhat linux kernel
(core of os)
> kernel related files
/dev
device files
(hardisk, processor, memory)
/etc
server configuration files
> ip address
> mail server file
/usr
>bin(copy)
>sbin(copy)
>tmp
>local
>unix system resource
>documentation
>help pages
/var
variable types of data
dynamic data
(log files)
/run
removabale devices
pan drive
/tmp
temporary mount point
du -hs cmd - file size
ctrl+c = kill the process
how to creatte a file-
cat > file100
this is my file(ctrl+d)
cat file_name
. current dir
cp file_from_copy file_to
mv - to rename
mv file100 file1009
create a dir-
mkdir dir100
mkdir -p dir100/dir200/dir300-> making a tree
-p is used to create parent dir as well
like-
[root@chitransh ~]# mkdir Videos/blow
error will be shown because Videos folder didnot spell correctly.
[root@chitransh ~]# mkdir -p Videos/blow
if you use this instead blow dir will be created inside the new Videos folder
tree dir100
cd - = previous working dir
cd.. = parent folder
cd ../.. = second parent
rm -rf dir100 - used to delete the filled dir(Without any confirmation)
rm -r dir100 - (ask for confirmation)
rmdir - empty dir
ln dir100/dir200/dir300 rum
>link the path to a file
Questions-
cut/paste- how
when root login - it can be without pass
visual editor-
using vi and vim editor we can create , view and edit the file
how to create a file using vi editor-
>vi file54
(window opens-file editor)
>modes-
1. command mode- vi cmds (create)
2. insert mode(edit - write)
3. execute mode(external command)
4. replace mode(char replace)
5. visual mode(visually seen)
i- switch to insert
Esc key- comout from insert(by default mode is cmd mode)
j-
h-
a-
l-
w-
o-next line with insert mode
O-above the line of cursor
:w - file save
:q - out from vi
:w!- forcefully save
:q!- forcefully exit
:wq - save and exit
:wq! - forcefullly out
:x- save and exit
:x!- force fully
:set nu- line number set
:set nonu
:10- goto line 10
ctrl + shift + ++
vimtutor
how to edit the file-
del the char-
x- one char
3x- three char
dw- to delete one word
3dw-- to delete 3 word
dd- del the line
3dd- del 4 lines
u- undo
how to copy-
yl- copy one char
3yl- 3 char
yw- copy one word
3yw- 3 words
yy- line
6yy- 6lines
p- paste
gg- top
G- bottom
vim-
visual improved
/search word
==================================
User administration and file permission-
User - User is something which performs a certain task.
User-
1. system user- system users are default users created during the linux installation time(root user)
2. normal user- user created by root user for system administration purpose.
3. sudo user- when the normal user is equivalent to root but not root(privilege user)
system user - user id range (0-999)[root user- 0(id)]
normal user - user id (1000-60000)
how to create user-
with useradd command
whenever u create a user with useradd cmd userdatabase file will be updated.
user database file-
/etc/passwd- this file contains user and user related info, havind 7 fields separated by colon.
/etc/shadow- this file contains users passwords and password aging information,having 9 fields separated by colon.
/etc/group- this file contains user's group info having 4 fields separated by colon.
/etc/gshadow- group password info
note:- whenever u create a user , your linux os will create a group and that user belongs to that grp.
bottom 5 lines-
tail -5 /etc/passwd
swapnil:x:1001:1001::/home/swapnil:/bin/bash
1. username
2. user pwd kept in /etc/shadow file in encripted this x link to /etc/passwd to /etc/shadow
3. user id
4. user Primary group id
5. comment field
6. user home directory
7. login shell.
shadow-
swapnil:!!:18871:0:99999:7:::
!!- no password(password stores in second field)
$6$___$ - password encrpted mechanism(rsl algo)
password and hash value combined
creating own id and grp-
> useradd -u 2002 web2
comment field-
> useradd -c developer web3
directory don't want to be the home -
>create a dir
> mkdir dir1
>useradd -d /dir1/user1 user1
changing the shell-
>useradd -s /bin/bourneshell user2
Q. /etc/shadow
fields meanings
user creation and modification -
useranme- ritesh
primary- japan
sec - london
comment- /newhome
loginshell- /bin/sh
useradd -u 2001 -g japan -G london -c student -d /myhome/ritesh -s /bin/sh ritesh
usermod - user updation
userdel- user deleted
delete user's home dir-
userdel -ritesh
-m - move used with directory
Default settings-
cat /etc/default/useradd
su root- switching user without home dir
su - root - switching user with home dir
chsh nisha5-
changing shell
chfn nisha5-
finger information will be stored
{comment}
shadow fields-
1.username
2.!! -password not set
3. last change.
(total no. days )
4. minimum days for change passwd
(validity)
5. maximumdays
6. 7 days earlier messaage before account expiring
7. account enable or disable
8. password expiry date
9. flag(how many chance - to block)
/var/spool/mail- user created (mail box created)
login definition-
ls /etc/login.defs
chage -l user_name
(password aging information)
chage user_name - to change the password aging
usermod -U nikita- unlocking nikita
user -L nikita- locking
(! in shadow file/encrpted password)
??
as we create a user mail is created inside /var/spool/mail
so if we delete the user and it is not there in /etc/passwd so why it is not deleted from /var/spool/mail
vim /etc/login.defs
==========================
USERS file and directory permissions-
file is created-
permissions-
owner | group owner | other user
rw- | r-- | r--
420 | 400 | 400
===========
6 4 4
r : read permission(4)
w : write ..(2)
x : execute permission(any programming language file execution)(1)
- : no permission(0)
when a file is creted the permission is by default 6 4 4
owner- all permission
all users - no permission
4 2 1 | - - - | ---
==============
7 0 0
chmod 700 file_name
chmod cmd is used to change the permissions.
chown user_name file_name
chgrp group_name file_name
write-
cat >> file_name
execute-
bash file_name
./file_name or /path/file_name
NOTE-
================================================================
USER 1 USER2
>file1
>file2
we created file1 and file2 inside USER1 and want to access from USER2
>what we gonna do??
owner grp owner others
- rw- | r-- | r-- 1 root root 40 date file_name
we will make user2 as Group owner of file1 then we can access file1 from user2
How to make user2 group admin of user1 -
usermod -g user2 user1(user_name)
if-
the user dir of user1 has all the permission (rwx) to enter
and then the file inside the dir will be given the permission you want to access from user2
================================================================
User file and dir permission-
default permissions for file 644
all permission for file 666
why is default permission is so?
umask is responsible for that.
umask is a numerical value which is used to decide the default permission.
Default permission = Full permission - umask
0666
- 0644
========
0022 -> this is the umask
0777
- 0755
===========
0022
vim /etc/bashrc
vim /etc/profile
umask 0044
changed
-umask value for root user 022
-full permission full-umask= default
-umask 0055- temporary set
/etc/profile or /etc/bashrc
-for user, umask is defined 077 in /etc/login.defs
File backup compression, decompression, searching
-searching using locate and find
create 10 files
example- file1, file2....file10
tar- backup
tar -cvf all.tar *
tar -tvf all.tar
cvf- create verbose(output) file
tvf- used for show the tar file
compress-
gzip all.tar
=========
becomes
all.tar.gz
uncompress-
gunzip all.tar
or
bzip2 all.tar(more compressed)
bunzip2 all.tar (uncompressed)
==========
xz all.tar(more compressed)
unxz all.tar(uncompressed)
tar -rvf all.tar india123- add new
tar -xvf all.tar india123- extract
delete from archive-
tar --delete -f new.tar file_name
Backup + Compression-
tar -cvzf my.tar.gz file* : gzip
tar -cvjf my.tar.bz2 file* : bzip2
tar -cvJf my.tar.xz file* : xz
searching a file-
locate file_name
locate command not able to search
find cmd-
find / -name file_name
find / -uid ---
find / -gid ---
find / -user user_name
find / -group group_name
find / -size +5M : above 5 mb
find / -size -10G : below 10G
find / -perm 000
---------------------------
updatedb - to update the database of os
locate file_name(redhat)- now it will locate
no permission files-
shadow
gshadow
shadow-
gshadow-
want oto search the string -
grep - content filter
grep word file_name
grep -i word file_name : ignoire case
grep -n word file_name :
starts from root-
grep -n ^root
ends with root-
grep -n root$
only root-
grep ^root$
package management using rpm and yum-
{Redhat linux services and management}
all commmands and configuration files are gonna work only if the package available
rpm - redhat package manager , wecan do pac=kage management using rpm
to search the package-
rpm -qf /etc/passwd
we have two utilities RPM and YUM-
yum remove tree
yum install tree
htttpd(web server package)
- web server commands
- web server configuration file
apache user will be created automatically
To manage the web server we need to start / stop/ restart/ reload the services
-----------------------------
yum remove httpd:- used to remove the package.
yum install httpd:- used to install the package.
yum list httpd:- used to show the package is installed or not.
cat > index.html
cp index.html /var/www/html
is a default location to start the website.
active vs enable
be active but not persistant be active even after rebooting.
all the services-
systemctl list-unit-files :- we can show all the services and their status.
specific services-
systemctl list-unit-files | grep sshd
(services related to sshd will be shown)
services related commands-
systemctl status httpd - used to check the status of service.
systemctl start httpd - to start the service(active)
systemctl stop httpd - to stop(inactive)
systemctl restart httpd- service go down for secs and then up
systemctl reload httpd- solution for service to go down.
systemctl is-active httpd - check the service is active or not.
systemctl enable httpd - service will be stayed after the system iks power off.
systemctl is-enable httpd - check wheather the service is enabled or not.
systemctl disable httpd - to disable the service.
systemctl list-machines
scp package_name root@mynameischitransh:/root
to install-
rpm -ivh package
rpm -q - to query
rpm -e ftp - to erase
rpm -qc package- config files
rpm -qi package - information
rpm -ql package - query list
rpm has dependency problem
yum repolist package
yum info package
Disk Management:-
IDE Controller-
connects with 4 hard disks
- primary master
- primary slave
- secondary master
- secondary slave
/dev/hda
/dev/hdb
/dev/hdc
/dev/hdd
virtual disks:-
/dev/vda
/dev/vdb
/dev/vdc
/dev/vdd
lets take one /dev/sda
MBR - master boot records
disk info
kind of partition:-
primary - max 4 primary
extended- max 1
inside extended partition create logical partition
sda1
sda2
sda3
sda4
we have file system
ext2,ext3,ext4,xfs,gfs
lsblk- lost block device file
/dev/fstab- mount file with disk.
blkid /dev/sdb7
lvm-
-logical volume manager
-disc combination technology
Multiple clubbing disks to create a big space
to create the pv(physical volume)
pvcreate /dev/sdb1 ..more
pvs to verify
vgcreate vg1 /dev/sdb1 /dev/sdb2 /dev/sdb3
vgdisplay
vgextend vg1 /dev/sdb5 - add new
lvcreate -L 500M -n /dev/vg1/lbm1
mkfs -t ext4 /dev/vg1/lvm1
mkdir /a
mount /dev/vg1/lvm1 /a
lsextend
/Linux-
Linux is an open source operating system.
In Linux, We use the command line interface to run the programs .
In Linux Open Source OS we can run an application without having hardware and software requirements.
AWS cloud - it provides all the services that we need a virtual machine or software to run in a local machine.
EC2(Elastic Computing Cloud) - EC2 is a web service where the computing can be resizable.
Cloud computing can be categorized into three groups-
1. Private Cloud.
2. Public Cloud.
3. Hybrid Cloud.
Servers-
1. mail server.
2. web server.
3. proxy server.
4. ftp(file transfer protocol)
Containerisation-
Docker
podman
skopeo
buildah
kubernetes
LINUX COMMANDS-
# - denotes root
$ - denote normal user
AWS cloud-
(instance launch)
sudo yum -y install httpd
cat > index.html(command)
sudo systemctl enable httpd
sudo systemctl start httpd
=================
-whoami
(root) - #
-hostname
your hostname will be displayed.
-pwd
present working directory
-useradd
to add a normal user root can add users.
-passwd user_name
to add the password
-su - user_name
we will switch from root to user
example-
useradd chitransh
passwd chitransh
1234
[root@server ~]# su - chitransh
[chitransh@server ~]$ exit
exit command is used to logout
-ls
this command is used to show all the files inside the root
-cat > chitransh
Hi! there mate
-cat chitransh
Hi! there mate(content will be shown)
-rm chitransh
file will be deleted.
-cp chitransh /sub
bin- cmds that all can access.
sbin- cmds only run by root.
=========================
ssh is used to remote access any server/Telnet
but telnet is not secured enough.
ssh root@
==========================
ls command --
Listing directory content
[root@servera ~]# - what does mean
>root- the user (whether root or normal user)
>servera- name of the host(computer)
~ - this represents that root is in its home
# - this represents the root user
In linux, everything is a file
> hardware
> components
>everything
/ - slash directory(super root)
which includes everything
[root@servera ~]# pwd
pwd- present working directory
> /root
[root@servera ~]# useradd chitransh
[root@servera ~]# passwd chitransh
1234
1234
[root@servera ~]# su - chitransh
[chitransh@servera ~]$ su - root
[root@servera ~]# cd /var
[root@servera var]# pwd
/var
here, instead ~ we have var dir specified after the machine name
which says that this is the home where the root user is.
[root@servera var]# cd
[root@servera ~]# touch file1
touch cmd is used to create an empty file
[root@servera ~]# ls
gives the contents insides the directory(/root)
but it doesnot include the hidden files.
Hidden files- starts with a period(.)
Blue color- Directory
White color- File
[root@servera ~]# ls -a
hidden files also be shown
[root@servera ~]# ls -l
longlisting of directory
[root@servera ~]# ls ll
do the same (long listing)
[root@servera ~]# ls --all
it also show all directory with hidden files(Alter:- ls -l)
[root@servera ~]# ls -r
Reverse order
==============================26/08/21
everything is a file
we need a dir to store a file
we have two user
root- /root
normal- /home
/bin - all cmds
/sbin- system binaries (super user authorisation)
/boot-
redhat linux kernel
(core of os)
> kernel related files
/dev
device files
(hardisk, processor, memory)
/etc
server configuration files
> ip address
> mail server file
/usr
>bin(copy)
>sbin(copy)
>tmp
>local
>unix system resource
>documentation
>help pages
/var
variable types of data
dynamic data
(log files)
/run
removabale devices
pan drive
/tmp
temporary mount point
du -hs cmd - file size
ctrl+c = kill the process
how to creatte a file-
cat > file100
this is my file(ctrl+d)
cat file_name
. current dir
cp file_from_copy file_to
mv - to rename
mv file100 file1009
create a dir-
mkdir dir100
mkdir -p dir100/dir200/dir300-> making a tree
-p is used to create parent dir as well
like-
[root@chitransh ~]# mkdir Videos/blow
error will be shown because Videos folder didnot spell correctly.
[root@chitransh ~]# mkdir -p Videos/blow
if you use this instead blow dir will be created inside the new Videos folder
tree dir100
cd - = previous working dir
cd.. = parent folder
cd ../.. = second parent
rm -rf dir100 - used to delete the filled dir(Without any confirmation)
rm -r dir100 - (ask for confirmation)
rmdir - empty dir
ln dir100/dir200/dir300 rum
>link the path to a file
Questions-
cut/paste- how
when root login - it can be without pass
visual editor-
using vi and vim editor we can create , view and edit the file
how to create a file using vi editor-
>vi file54
(window opens-file editor)
>modes-
1. command mode- vi cmds (create)
2. insert mode(edit - write)
3. execute mode(external command)
4. replace mode(char replace)
5. visual mode(visually seen)
i- switch to insert
Esc key- comout from insert(by default mode is cmd mode)
j-
h-
a-
l-
w-
o-next line with insert mode
O-above the line of cursor
:w - file save
:q - out from vi
:w!- forcefully save
:q!- forcefully exit
:wq - save and exit
:wq! - forcefullly out
:x- save and exit
:x!- force fully
:set nu- line number set
:set nonu
:10- goto line 10
ctrl + shift + ++
vimtutor
how to edit the file-
del the char-
x- one char
3x- three char
dw- to delete one word
3dw-- to delete 3 word
dd- del the line
3dd- del 4 lines
u- undo
how to copy-
yl- copy one char
3yl- 3 char
yw- copy one word
3yw- 3 words
yy- line
6yy- 6lines
p- paste
gg- top
G- bottom
vim-
visual improved
/search word
==================================
User administration and file permission-
User - User is something which performs a certain task.
User-
1. system user- system users are default users created during the linux installation time(root user)
2. normal user- user created by root user for system administration purpose.
3. sudo user- when the normal user is equivalent to root but not root(privilege user)
system user - user id range (0-999)[root user- 0(id)]
normal user - user id (1000-60000)
how to create user-
with useradd command
whenever u create a user with useradd cmd userdatabase file will be updated.
user database file-
/etc/passwd- this file contains user and user related info, havind 7 fields separated by colon.
/etc/shadow- this file contains users passwords and password aging information,having 9 fields separated by colon.
/etc/group- this file contains user's group info having 4 fields separated by colon.
/etc/gshadow- group password info
note:- whenever u create a user , your linux os will create a group and that user belongs to that grp.
bottom 5 lines-
tail -5 /etc/passwd
swapnil:x:1001:1001::/home/swapnil:/bin/bash
1. username
2. user pwd kept in /etc/shadow file in encripted this x link to /etc/passwd to /etc/shadow
3. user id
4. user Primary group id
5. comment field
6. user home directory
7. login shell.
shadow-
swapnil:!!:18871:0:99999:7:::
!!- no password(password stores in second field)
$6$___$ - password encrpted mechanism(rsl algo)
password and hash value combined
creating own id and grp-
> useradd -u 2002 web2
comment field-
> useradd -c developer web3
directory don't want to be the home -
>create a dir
> mkdir dir1
>useradd -d /dir1/user1 user1
changing the shell-
>useradd -s /bin/bourneshell user2
Q. /etc/shadow
fields meanings
user creation and modification -
useranme- ritesh
primary- japan
sec - london
comment- /newhome
loginshell- /bin/sh
useradd -u 2001 -g japan -G london -c student -d /myhome/ritesh -s /bin/sh ritesh
usermod - user updation
userdel- user deleted
delete user's home dir-
userdel -ritesh
-m - move used with directory
Default settings-
cat /etc/default/useradd
su root- switching user without home dir
su - root - switching user with home dir
chsh nisha5-
changing shell
chfn nisha5-
finger information will be stored
{comment}
shadow fields-
1.username
2.!! -password not set
3. last change.
(total no. days )
4. minimum days for change passwd
(validity)
5. maximumdays
6. 7 days earlier messaage before account expiring
7. account enable or disable
8. password expiry date
9. flag(how many chance - to block)
/var/spool/mail- user created (mail box created)
login definition-
ls /etc/login.defs
chage -l user_name
(password aging information)
chage user_name - to change the password aging
usermod -U nikita- unlocking nikita
user -L nikita- locking
(! in shadow file/encrpted password)
??
as we create a user mail is created inside /var/spool/mail
so if we delete the user and it is not there in /etc/passwd so why it is not deleted from /var/spool/mail
vim /etc/login.defs
==========================
USERS file and directory permissions-
file is created-
permissions-
owner | group owner | other user
rw- | r-- | r--
420 | 400 | 400
===========
6 4 4
r : read permission(4)
w : write ..(2)
x : execute permission(any programming language file execution)(1)
- : no permission(0)
when a file is creted the permission is by default 6 4 4
owner- all permission
all users - no permission
4 2 1 | - - - | ---
==============
7 0 0
chmod 700 file_name
chmod cmd is used to change the permissions.
chown user_name file_name
chgrp group_name file_name
write-
cat >> file_name
execute-
bash file_name
./file_name or /path/file_name
NOTE-
================================================================
USER 1 USER2
>file1
>file2
we created file1 and file2 inside USER1 and want to access from USER2
>what we gonna do??
owner grp owner others
- rw- | r-- | r-- 1 root root 40 date file_name
we will make user2 as Group owner of file1 then we can access file1 from user2
How to make user2 group admin of user1 -
usermod -g user2 user1(user_name)
if-
the user dir of user1 has all the permission (rwx) to enter
and then the file inside the dir will be given the permission you want to access from user2
================================================================
User file and dir permission-
default permissions for file 644
all permission for file 666
why is default permission is so?
umask is responsible for that.
umask is a numerical value which is used to decide the default permission.
Default permission = Full permission - umask
0666
- 0644
========
0022 -> this is the umask
0777
- 0755
===========
0022
vim /etc/bashrc
vim /etc/profile
umask 0044
changed
-umask value for root user 022
-full permission full-umask= default
-umask 0055- temporary set
/etc/profile or /etc/bashrc
-for user, umask is defined 077 in /etc/login.defs
File backup compression, decompression, searching
-searching using locate and find
create 10 files
example- file1, file2....file10
tar- backup
tar -cvf all.tar *
tar -tvf all.tar
cvf- create verbose(output) file
tvf- used for show the tar file
compress-
gzip all.tar
=========
becomes
all.tar.gz
uncompress-
gunzip all.tar
or
bzip2 all.tar(more compressed)
bunzip2 all.tar (uncompressed)
==========
xz all.tar(more compressed)
unxz all.tar(uncompressed)
tar -rvf all.tar india123- add new
tar -xvf all.tar india123- extract
delete from archive-
tar --delete -f new.tar file_name
Backup + Compression-
tar -cvzf my.tar.gz file* : gzip
tar -cvjf my.tar.bz2 file* : bzip2
tar -cvJf my.tar.xz file* : xz
searching a file-
locate file_name
locate command not able to search
find cmd-
find / -name file_name
find / -uid ---
find / -gid ---
find / -user user_name
find / -group group_name
find / -size +5M : above 5 mb
find / -size -10G : below 10G
find / -perm 000
---------------------------
updatedb - to update the database of os
locate file_name(redhat)- now it will locate
no permission files-
shadow
gshadow
shadow-
gshadow-
want oto search the string -
grep - content filter
grep word file_name
grep -i word file_name : ignoire case
grep -n word file_name :
starts from root-
grep -n ^root
ends with root-
grep -n root$
only root-
grep ^root$
package management using rpm and yum-
{Redhat linux services and management}
all commmands and configuration files are gonna work only if the package available
rpm - redhat package manager , wecan do pac=kage management using rpm
to search the package-
rpm -qf /etc/passwd
we have two utilities RPM and YUM-
yum remove tree
yum install tree
htttpd(web server package)
- web server commands
- web server configuration file
apache user will be created automatically
To manage the web server we need to start / stop/ restart/ reload the services
-----------------------------
yum remove httpd:- used to remove the package.
yum install httpd:- used to install the package.
yum list httpd:- used to show the package is installed or not.
cat > index.html
cp index.html /var/www/html
is a default location to start the website.
active vs enable
be active but not persistant be active even after rebooting.
all the services-
systemctl list-unit-files :- we can show all the services and their status.
specific services-
systemctl list-unit-files | grep sshd
(services related to sshd will be shown)
services related commands-
systemctl status httpd - used to check the status of service.
systemctl start httpd - to start the service(active)
systemctl stop httpd - to stop(inactive)
systemctl restart httpd- service go down for secs and then up
systemctl reload httpd- solution for service to go down.
systemctl is-active httpd - check the service is active or not.
systemctl enable httpd - service will be stayed after the system iks power off.
systemctl is-enable httpd - check wheather the service is enabled or not.
systemctl disable httpd - to disable the service.
systemctl list-machines
scp package_name root@mynameischitransh:/root
to install-
rpm -ivh package
rpm -q - to query
rpm -e ftp - to erase
rpm -qc package- config files
rpm -qi package - information
rpm -ql package - query list
rpm has dependency problem
yum repolist package
yum info package
Disk Management:-
IDE Controller-
connects with 4 hard disks
- primary master
- primary slave
- secondary master
- secondary slave
/dev/hda
/dev/hdb
/dev/hdc
/dev/hdd
virtual disks:-
/dev/vda
/dev/vdb
/dev/vdc
/dev/vdd
lets take one /dev/sda
MBR - master boot records
disk info
kind of partition:-
primary - max 4 primary
extended- max 1
inside extended partition create logical partition
sda1
sda2
sda3
sda4
we have file system
ext2,ext3,ext4,xfs,gfs
lsblk- lost block device file
/dev/fstab- mount file with disk.
blkid /dev/sdb7
lvm-
-logical volume manager
-disc combination technology
Multiple clubbing disks to create a big space
to create the pv(physical volume)
pvcreate /dev/sdb1 ..more
pvs to verify
vgcreate vg1 /dev/sdb1 /dev/sdb2 /dev/sdb3
vgdisplay
vgextend vg1 /dev/sdb5 - add new
lvcreate -L 500M -n /dev/vg1/lbm1
mkfs -t ext4 /dev/vg1/lvm1
mkdir /a
mount /dev/vg1/lvm1 /a
lsextend
Comments
Post a Comment