Linux Founder—Linus Torvalds
Linus Benedict Torvalds is a Finnish software engineer best known
for having initiated the development of the Linux kernel and git
revision control system.
History of LINUX
Linux came from a Unix family, Linux is free and open-source
software operating systems, which was developed by Linus
Torvalds in September 1991.
In 1991, When Linus Torvalds was a student at the University
of Helsinki, Finland, USA.
He developed the first code of Linux 0.01 and post it on Minix
newsgroup 17 Sep 1991, his code become so popular
people encourage him to develop new code and he was lead
to develop new code and release the first “official” version of
Linux, version 0.02 on October 5, 1991.
Today many year pass and Linux become one of the most
popular operating system.
Today 90% fastest Supercomputers out of 500 run on Linux
variant including top 10.
Linux File System Hierarchy
+ In Linux everything is represented as a file including a
hardware program, the files are stored in a directory, and every
directory contains a file with a tree structure. That is called File
System Hierarchy.
+ Linux uses single rooted, inverted tree-like structure.
+ Root Directory represents with / (forward slash) It is a top-level
directory in Linux.
+ The base of the Linux directory is the root. This is the starting
point of FSH. Every directory arises from the root directory. It is
represented by a forward slash (/).
+ If someone says to look into the slash directory, they refer to the
root directory.
/root
Itis the home directory for the root user (superuser).
/bin > User Binaries
Contains binary executable.
+Common Linux commands you need to use in single-user
modes are located under
this directory.
Commands used by all the users of the system are located here.
/sbin > System Binaries
Just like /bin, /sbin also contains binary executables.
But, the linux commands located under this directory are used
typically by system aministrator, for system maintenance
purpose.
For example: iptables, reboot, fdisk, ifconfig, swapon
/dev > Device Files
it contains hardware device files,
Contains device files.
These include terminal devices, usb, or any device attached to
the system.
For example: /dev/tty1, /dev/usbmon0
/var> Variable Files
The variable data files such as log files are located in the /var
directory.
File contents that tend to grow are located in this directory.
> This includes
» /var/log: System log files generated by OS and other applications.
» /var/lib: Contains database and packages files.
¢ /var/mail: Contains Emails.
° /var/tmp: Contains Temporary files needed for reboot.
/mnt> Mount Directory
This directory is used to mount a file system temporarily.
/media> Removable Media Devices
The /media directory contains subdirectories where removable
media devices inserted into the computer are mounted.
/usr> User Binaries
directory.
#uname > it shows the name of the kernel (OS)
#uname -r > it shows version of the kernel
#cd > it use for change directory
#clear > it use for clear screen
#whoami > it show currently login user name
#history > it show list of previously used commands
#date > it show time and date
Create file or directory
1. For create single directory
#mkdir /shubham
2. For create multiple directory
#mkdir dev qa test
3. For create directory path (directory inside directory)
#mkdir -p /dev/qa/test/devops
4. For create number of directory
#mkdir /student{1..10}
Create file
Touch:
Touch command is use for create empty file, we can’t write data in a
file, can’t edit or save file.
1. Create single file with touch command
#touch notes
2. Create multilpe file
#touch python java react
3.Create number of files
#touch books{1..10}
For copy and paste
cp:
cp command is used for copy and paste file or directory
Syntax:
#cp <option> <source> <destination>
Options
-t for recursive
-v for verbose
-f for forcefully
For copy file
#cp -rvf /root/anaconda-ks.cfg /home
For copy all data which start form D alphabet
#cp -rvf /root/D* /home
For remove file & directory
For delete file or directory
#rm -rvf /india/pune
For move or rename file & directory
For move file or directory
#mv /home/shub/root/Desktop
For rename file or directory
#mv dev devops
User Management
For create user account
#useradd shub
For check user account properties
#grep shub/etc/passwd
shub:1001:1001: :/home/shub:/bin/bash
For create user account password
#passwd shub
For check user password properties
#grep shub /etc/shadow
shub:@s$!1bce25f%:18002:0:99999:
For switch user account
#su shub
For logout from user account
#exit
Or
Press “ctrl+d” Key
For Delete user account
#userdel shub
For change user Login name
#usermod -l devops shub
Group Management
+ Group is collection of user accounts which is very use full to
administrator for manage and apply permission on number of
users.
For add Group account
#groupadd ibmgrp
For check group account property
#grep ibmgrp /etc/group
Ibmgrp:x:1001:ajay,vijay,sachin
For check group admin property
grep ibmgrp /etc/gshadow
Ibmgrp:!::
For Delete group Account
#groupdel ibmgrp
For add single member in group
#gpasswd -a ajay ibmgrp
For add multiple member in group
#gpasswd -M rahul virat,rohit ibmgrp
For remove group member
#gpasswd -d virat ibmgrp
For make group admin
#gpasswd -A sachin ibmgrp
Linux File System Permission
‘Type of File Permission
Basic Permission
Special Permission
Access Control List (ACL) Permission
For check file permission
#ls -1 /notes.txt
-rw-r—r—. 1 root root 0 Jan 4 14:59 /notes.txt
Permission
Link
Owner
Group owner
Size of file
Date & time of file creation
Name of file
For check directory permission
#ls -Id /dev
Permission in details
File type Permission classes
d user group other
rwx rwx rwx
r - read
w - write
x - execute
——————
Permission Group
Permission Description
Owner (u) > Permissions used for the owner of the file
Group (g) > Permissions used by members of the group
Other (0) > Permissions used by all other users
For change permission
For add read permission to owner
#chmod utr /notes.txt
For add read write permission to group
#chmod gtrw /notes.txt
For remove read permission to others
#chmod o-r /notes.txt
For change ownership
Syntax:
#chown <user name> <file/directory name>
eg.
#chown ajay /notes.txt
For change group ownership
Syntax:
#chgrp <group name> <file/directory name>
eg.
#chgrp ibmgrp /notes.txt
Set permission with numeric value
r (read) =4
w (write) =2
x (execute) = 1
For set permission with numeric value
#chmod 751 /shub
Access Control List (ACL)
+ Access control list (ACL) provides an additional, more
flexible permission mechanism for file systems.
+ Access control list is service which is use for providing
special permission to specific user and group to
particular directories and file
Use of ACL
Think of a scenario in which a particular user is not a member of
group created by you but still you want to give some read or write
access, how can you do it without making user a member of group,
here comes in picture Access Control Lists, ACL helps us to do this
trick.
For check ACL Permission
Syntax:
#getfacl <name of file or directory>
eg. #getfacl /devops
For set ACL permission to user
#setfacl -m u:shub:rwx /de
For remove ACL permission of user
#setfacl -x u:shub: /devops
For set ACL permission to Group
#setfacl -m g:shubgrp:rwx /devops
For remove ACL permisssion of group
#setfacl -x g:shubgrp: /devops
For remove all ACL permisssions
#setfacl -b /devops
Regular Expressions
What is Regular Expressions?
Regular expressions are special characters which
help search data, matching complex patterns.
GREP (Global Regular Expression Print)
The grep filter searches a file for a particular pattern
of characters, and displays all lines that contain that
pattern.
1. Search a word (string in a file)
#grep root /etc/passwd
2. Search a string in multiple files
#grep root /etc/passwd /etc/group
3. Search a string insensitive in file
#grep -i Root /etc/passwd
4, Search a string in all files recursively
#grep -r root /
5. Inverting the string match
#grep -v root /etc/passwd
6. Displaying the string match total line no
#grep -c root /etc/passwd
7. Display the file names that matches the string
#grep -I root /etc/passwd/etc/shadow
8. Display the file names that do not contain the string
#grep -L root /etc/passwad /etc/shadow
9. Displaying the string match line with number
#grep -n root /etc/passwd
10. Display the lines that start with a string
#grep “root /etc/passwd
11. Display the lines that end with a string
#grep /bin/bash$ /etc/passwd
12. Search and redirect output in a new file
#grep root /etc/passwd > /mnt/find.txt
Find
The Linux Find Command is one of the most important and
much used command in Linux systems.
Find command used to search and locate list of files and
directories based on conditions you specify for files that match
the arguments.
Find can be used in variety of conditions like you can find files
by permissions, users, groups, file type, date, size and other
possible criteria
1. Find files under Home directory
#find /home -name shub.txt
2. Find files with suid permission
#find /-perm 4755
3. Find files with guid permission
#find /-perm 2644
4. Find files with sticky bit permission
#find /-perm 1755
5. Using Find command based on users
#find /-user root
6. Using Find command based on groups
#find /-group shubgrp
7. Search the file with less than 10MB in a folder
#find /tmp -size -10M.
8. Search the file with more than 10MB in a folder
#find /tmp -size +10M.
WC (Word Count)
The we command is use for the count word and line numbers.
1. Count number of lines
#we -l /ete/passwd
2, Count number of words
#we -w /etc/passwd
head
Head command is used for to display top line of the file.
1. Display top 10 line of the file
#head /etc/passwd
2. Display top specific no line of the file
#head -n 15 /etc/passwd
tail
Tail command is used for to display the bottom
line of the file.
1. Display bottom 10 line of the file
#tail /etc/passwd
2. Display bottom specific line of the file
#tail -n 5 /etc/passwd
Archive File in Linux
Archiving is the process of combining multiple files and
directories (same or different sizes) into one file. Archive
process is very useful for backup and compression size of data
in Linux.
What is Tar
The Linux “tar” stands for tape archive, which is used by large
number of Linux/Unix system administrators to compress size
or drives backup.
For create archive tar used some compression algorithms Such
as gzip,bz2 and xz
Tar command syntax
#tar <options> <files>
Commonly used options
c-for create
x -for extract
v-for verbose
f -for forcefully
t -for test
z-for gzip
j-for bz2
J -for xz
C -for specific destination
For create a tar archive file
# tar -cvf /mnt/backup.tar /var
For show file size in human readable formate
#du-sh /var
#du -sh /mnt/backup.tar
For extract a tar archive file on default location
#tar -xvf /mnt/backup.tar
For extract a tar archive file on specific location
#tar -xvf /mnt/backup.tar -C /root/Desktop/
For create a tar archive file with compress in size (gzip)
# tar -cvzf /mnt/backup.tar.gz /var
For extract a tar archive file with compress in size (gzip)
#tar -xvjf /mnt/backup.tar.bz2
For create a tar archive file with compress in size (xz)
# tar -cvJf /mnt/backup.tar.xz /var
For extract a tar archive file with compress in size (xz)
#tar -xvjf /mnt/backup.tar.xz
Job Automation
+ Job automation allow us perform task automatically in OS by
using tools.
+ This feature is very useful for administrator to assign task to OS
whenever he is not present or perform daily basis work.
Two type of job automation
1. at—at command is used to execute job only one
time.
2. crontab—Crontab command is use for to execute job multiple
time.
For set job with at command
#date
#at 8:10 AM
at>useradd shub
at>
Ctrl+d (write & quit)
For show pending at job
#atq
For remove at job
#atrm 2
For restrict user from accessing at
#vim /etc/at.deny
Shub (add here user name)
:wq (write&quit)
For start crond service
# systemctl start crond
For enable crond service (Permanent on)
# systemctl enable crond
For set cron jobs
#crontab -e
//
For show cron jobs of current user
# crontab -1
For remove cron jobs
# crontab -r
Or
Go to the crontab file and remove job line
#crontab -e
For set cron job to other user
# crontab -u shub -e
For show cron job other user
# crontab -u shub -1
For restrict user from crond service
#vim /etc/cron.deny
For check crontab log file
#tail -f /var/log/cron
Sudo Command
What is sudo?
sudo (“superuser do”, or “switch user do”) allows a user with
proper permissions to execute a command as another user,
such as the superuser.
sudo allows a permitted user to execute a command as another
user, according to specifications in the /etc/sudoers file.
Provide sudo privilege to user
For edit configuration file:
# vim /etc/sudoers
root ALL=(ALL) ALL
amir ALL=(ALL) ALL (add this line appro. 101 line)
:wq
Provide sudo privilege to group
For edit configuration file:
# vim /etc/sudoers
%punegrp ALL=(ALL) ALL (line number 108)
:wq
By default all member of punegrp group got sudo privileges
Wheel group
Wheel is a system group which by default have sudo privileges,
if we add any member in that group then that user got sudo
privilege
#grep wheel /etc/group
#useradd shub
#passwd shub
#gpasswd -a shub wheel
By default all member of wheel group got sudo privileges
Sudo without password
For edit configuration file:
# vim /etc/sudoers
amir ALL=(ALL) NOPASSWD: ALL
%punegrp ALL=(ALL) NOPASSWD: ALL
:wq,
Managing networking based on Red Hat Enterprise
Linux
For show ip address
#ifconfig
Or
#ip addr
Configure networking with nmcli
Network Manager is a daemon that monitor and manages network
settings.
nmcli command used to manage networking
Manage IP configuration
For Show all list of connection
#nmcli_ con show
For show active connection
f#nmcli con show --active
For show specific connection
#nmcli con show “citynet”
For show device status
fnmcli dev status
For create new connection with nmcli
fnmcli con add con-name “citynet” ifname ens33 type ethernet
‘ipv4.add 192.168.0.2/24 gw4 192.168.0.1 ip4.dns 192.168.0.1
connection. autoconnect yes ipv4.method manual
For activate new connection
finmcli con up "citynet”
f#nmcli con show-active
For deactivate connection
#nmcli con down citynet
For start new connection and stop old connection
#nmcli connection modify “citynet” connection.autoconnect no
#nmcli connection modify “pune” connection. autoconnect yes
For remove existing connection
#nmcli con delete citynet
For set hostname
#hostnamectl set-hostname it.citynet.com
For show hostname
#hostname
Configuring networking with nmtui
IP address configuration files
All created connections with nmcli and nmtui by default store in
following file
cd /etc/NetworkManager/system-connections/
#ls
Note:
We can also modify connection using above connection file, but it
not
recommended.
If update file, restart NetworkManger service to update ip-
configuration
#systemctl restart NetworkManager
Comments
Post a Comment