24 Linux
24 Linux
Linux OS
=========
=============
What is OS ?
=============
===========
Windows OS
===========
=> Security features are less in windows os (anti virus s/w required)
==========
Linux OS
==========
==============
Linux History
==============
-> Linus Torvalds identified one OS which is matching with his ideas
i.e Minux os
-> Linus Torvalds used Minux OS code and made some changes and released into market
as new OS i.e Linux OS.
======================
Linux Distributions
======================
-> Linus Torvalds provided Linux OS source code for free of cost
-> So many companies downloaded Linux OS source code and modified according to
their requirement and released into market with their brand names
Ex: Amazon Linux, Ubuntu, Red HAT, suse, debian, kali, fedora....
=============================
How to setup Linux Machine ?
=============================
======================================================================
=============================================================================
================
Linux Commands
================
mkdir aws
mkdir devops
mkdir docker
rmdir devops
rm -rf devops
touch f1.txt
touch f2.txt f3.txt
cd : change directory
cd dir-name
cd ..
rm : to delete file
rm f1.txt
rm -rf <dir-name>
mv existing-name new-name
mv presention-location new-location
cat : create new file with data + append data to file + print file data
==============================
10-July-2024 (Linux Commands)
==============================
cp f1.txt f2.txt
Note: If we want to copy data from multiple files then we should use cat command
head f1.txt
head -n 20 f1.txt
head -n 50 f1.txt
tail f1.txt
tail -n 25 f1.txt
Note: To get latest log message from log file we will use tail command.
Note: Using grep command we can search for content in the file
wc : word count
=======================
Text Editors in Linux
=======================
=> Using 'vi' we can create new files and we can modify existing file data.
Ex: vi <filename>
2) insert mode (to edit the file ) ---> press 'i' in keyboard
3) esc mode (to comeout from insert mode) --> press 'esc' in keyboard
Note: vi command will open the file if it is avilable otherwise it will create new
file and it will open that file.
========================
file creation commands
=======================
====================
reading file data
===================
cat : print file data from top to bottom
tac : print file data from bottom to top
head : print first 10 lines of file data
tail : print last 10 lines of file data
vi : open the file
###############
11-July-2024
###############
=============
SED Command
=============
=> SED is used to process the data (substitute, delete, print, insert)
=> Using SED command we can perform operations on the file without opening the
file.
Note: n is a number
=================
User Management
=================
=> Multiple users can acces single linux machine and can perform multi tasking at
time.
Note: "ec2-user" is a default user in amazon linux vm. ec2-user having sudo
priviliges.
=> Within one linux machine we can create multiple user accounts
=> when we create user account, for user one home directory will be created.
# create user
sudo useradd <uname>
# Delete user
$ sudo userdel <uname>
===================================
Working with user groups in linux
===================================
=> When we create user in linux, for every user one user group also will be created
with the given username.
# delete group
$ sudo groupdel <group-name>
===================================================================================
====
Assignment : create new user and connect with linux vm using newly created user
account
===================================================================================
====
###############
12-July-2024
###############
1) sudoers
2) sshd_config
=================================
What is sudoers file in Linux
=================================
=> Using this file we can control which user can run command as a superuser.
Note: We should be very careful while working with sudoers file. If we do any
mistakes in sudoers file then system will be crashed.
=> After making changes to close sudoers file => ( CTRL + X + Y + Enter)
========================================================
How to enable password based authentication for users ?
========================================================
=> If we want to connect with linux vm using username and password then we need to
set that value as yes.
# Open file
$ sudo vi /etc/ssh/sshd_config
Note : Now we can connect with linux vm using username and pwd
$ ssh username@public-ip
==========================
File Permissions in Linux
==========================
=> Using file permissions we can secure our files and we can protect our file data.
r => read
w => write
x => execute
rwxrwxrwx f1.txt
r--r-xr-- f2.txt
user : read
group : read + execute
others : read
r-xrw--w- f3.txt
+ => add
- => remove
====================================
File Permissions in Numeric Format
====================================
0 => no permissions
1 => Execute
2 => Write
4 => Read
# ugo+x
$ chmod 111 f1.txt
# ugo+w
$ chmod 222 f1.txt
###############
15-July-2024
###############
===============
chown command
===============
# change owner
sudo chown new-owner file/directory
# change owner-group
sudo chown :new-group file/directory
============================================
Q) What is the diff between chmod & chown ?
============================================
=================================
Working with Zip files in linux
=================================
======================
Networking commands
======================
curl https://type.fit/api/quotes
###############################################################################
Date : 16-July-2024
###############################################################################
==========================
Package Managers in Linux
==========================
=> Package Managers are used to install / update / manage software packages in
linux machines.
# install java
sudo yum install java
======================================================
Assignment : Remove git and java from linux machine
======================================================
=============================
Webserver Setup in Linux VM
============================
ex: login page, register page, dashboard page, about us page ....
1) Static website
2) Dynamic website
=> The website which gives same response for every user is called as static
website.
=> The website which gives response based on logged in user is called as dynamic
website.
Note: To access our webserver we need to enable http protocol in ec2 vm security
group inbound rules.
=> Once http protocol enabled we can access our webserver using ec2-linux-vm public
ip
================================
Static website hostig in linux
================================
# install webserver
$ sudo yum install httpd
# start webserver
$ sudo service httpd start
=> To access our webserver we need to enable 80 port number in security group
inbound rules.
a) start a service
b) stop a service
c) restart a service
d) enable/disable service
# reload service
sudo systemctl reload http
====================================================
###############################################################################
Date : 18-July-2024
###############################################################################
===========================
Working with Link Files
===========================
=> In linux we can create link files ( similar to shorcut files in windows )
1) Hard link
2) Soft link (symbolic link)
--------------------------------
Syntax To create Hard Link
--------------------------------
$ ln <orginal-file> <link-file>
$ touch f1.txt
Note: If we write some data to original file, it is reflecting in link file also.
Note: when we delete original file, link file is not effected (hard link).
------------------------------
Syntax To create Soft Link
------------------------------
$ ln -s <orginal-file> <soft-link-file>
Ex:
$ touch s1.txt
$ ln -s s1.txt s100.txt
$ ls -li
Note: Original file and link file having diff inode numbes
$ rm s1.txt
Note: When we remove original file then soft link file will become dangling file.
We can't access that file.
=====================
process management
=====================
$ kill PID
# set hostname
$ sudo hostname <new-name>
# re-start session
$ exit
===================================
How to set hostname permanentley
===================================
# restart the vm
=========
Summary
=========
1) What is Linux OS
2) Windows Vs Linux
3) Linux VM Setup in AWS cloud
4) Connecting with Linux VM using SSH client
5) Directories & Files Based Operations
6) Text Editors
7) Text filters
8) User & Group Management
9) File Permissions
10) File Ownership
11) Archieves
12) Networking
13) suderos file
14) sshd_config
15) package managers
16) static website hosting (httpd)
17) Service Management (systemctl)
18) Process management
19) Working with link files
20) Changing Hostname