SlideShare a Scribd company logo
1 of 81
Centos login: ssh bahmni@20.25.123.56
Password: Training@emr123
for
EMR System
Implementation
FMOH- HITD
Apr 2022
Linux Training
Fundamentals of Linux
The History of Linux
ā— Linux began life in 1991
ā— Linus Torvalds wrote the original Linux operating system as a hobbyist
exercise in exploiting the new Intel 386 memory architecture
ā— Inļ¬‚uenced by Minix, an operating system written by Torvald's professor
Andy Tanenbaum as a teaching aid, which was in turn based on UNIX
ā— Not derived from UNIX source code but deliberately UNIX-compatible
ā— Contributions come from many other developers
ā— Free Software Foundation wrote bash shell, gcc compiler, many other
command line tools, distributed under the GNU 'brand name'
ā— Like UNIX before it, linux was not originally conceived as a 'product'
Linux distributions
ā— The Linux kernel is the core or the heart of the operating system.
ā— However to have a useful operating system,
ā—‹ It need other components in addition to the kernel.
ā—‹ These components can include
ā–  system libraries,
ā–  graphical user interfaces,(Optional),
ā–  web browsers and other programs,(Optional)
ā–  And other stuffs
Linux intro
The Linux kernel is the core or the heart of the operating system.
However to have a useful operating system,It need other components in addition
to the kernel.
These components can include
ā— system libraries,
ā— graphical user interfaces,(Optional),
ā— web browsers and other programs,(Optional)
ā— And other stuffs
Linux intro
ā–ø Linux is open source software, - this means that anyone can use,copy, study and
change the software in any way they choose,
ā–ø Linux being free and open source software,
ā–¹ it has led to the rise of Linux distributions.
ā–¹ In every case the source code is free
ā–ø but in some cases the distribution is not free.
ā–¹ RedHat releases
Linux Package Manager
Method of installing, updating, removing, and keeping track of software updates from
specific repositories (repos) in the Linux system
ā–ø YUM ā€“ CentOS, RedHat
ā–ø RPM - Fedora Linux, AlmaLinux, CentOS, openSUSE, ā€¦
ā–ø ZYPPER - OpenSuse. ...
ā–ø APT-GET & APT-CACHE ā€“, Ubuntu
ā–ø DPKG - Debian
ā–ø PACMAN ā€“ ArchLinux, Manjaro
ā–ø APT(Advanced Packaging Tool) ā€“ Ubuntu and related flavors,.
ā–ø DNF (Fork of YUM) Command. ...
Linux Distro
ā–ø There are distributions that are commercial.
ā–ø These commercial Linux distributions are backed by corporations
and you can buy support from them.
ā–ø There are non commercial Linux distributions,
ā–ø these are maintained by community volunteers.
ā–ø You have Linux distributions that are designed for server use,
others that are designed for desktop use.
ā–ø There are literally hundreds of Linux distributions.
Linux Distro
ā–ø Each Linux distribution has a different goal in a slightly different focus.
ā–ø Your choice of distribution will be driven by the goal you're trying to
accomplish.
ā–¹ Ubuntu-
ā–¹ Mint Linux - Multimedia
ā–¹ Kali - penetration testing and conducting digital forensics.
ā–¹ CentOS - Enterprise-class Linux Distribution derived from Red Hat
Enterprise Linux sources
ā–¹ Android - Linux without any GNU. can be found in the wild in phones,
tablets and other devices.
CentOS
Community Enterprise Operating System
ā–ø The best Linux distro of enterprise level production deployment
ā–ø It is lightweight, reliable and fast.
ā–ø Best Alternative for Red Hat Enterprise Linux (RHEL)
ā–ø Security ā€“ CentOS supports
ā–¹ SELinux- is a security architecture for Linux systems that allows administrators to
have more control over who can access the system
ā–¹ NSS (Network Security Services) - means Confidentiality, Integrity, Authentication, Non-
repudiation or Entity authentication. these are related to the message exchange using a network
while entity authentication service provides identification
ā–¹ Linux PAM (Pluggable Authentication Modules ) is a suite of libraries that allows a Linux system
administrator to configure methods to authenticate users.
ā–¹ Firewalld - provides a dynamically managed firewall with support for network/firewall zones that
define the trust level of network connections or interfaces.
CentOS
Pros
ā–ø It is based on a Linux framework
ā–ø It is very secured and less prone to any cyber threats
ā–ø It also provides administrative from the system admin support perspective
Cons
ā–ø It is not user friendly
ā–ø From the gaming and entertainment support perspective, itā€™s less compatible.
ā–ø It normally doesnā€™t have that much support from the driver creation and storage management
perspective.
ā–ø From the technical support perspective, it is also a little bit on a lesser side than that of Ubuntuā€™s
support.
Server Virtualization
Server virtualization is the process of creating multiple server instances from one physical server. Each server instance represents an
isolated virtual environment.
Within each virtual environment, you can run a separate operating system.
Hypervisors create a virtualization layer that separates CPU/ processors, RAM and other physical resources from the virtual machines
you create.
VirtualBox is a virtualization software solution that allows you to create and run virtual machines on a single hardware machine.
By using a type 2 hypervisor, like VirtualBox, your existing operating system stays unaffected by the virtual environment.
Type 2 hypervisor runs inside of an operating system of a physical host machine.
Example:-
ā— VMware
ā— Oracle virtual box
Virtualbox installation guide
ā— Download the VirtualBox installer - Go to the official website to download the VirtualBox installer for your
operating system (Windows in this case). https://www.virtualbox.org/wiki/Downloads
ā— Run the installer and define the installation options.
Deploying a New VM
Once you have installed VirtualBox, open the application. You can see the graphical user interface of VirtualBox
which is unified for all supported host operating systems.
ā— Creating a Virtual Machine
Click Machine > New or hit the icon with the blue star to create a new virtual machine in VirtualBox GUI.
ā— Creating a Virtual Hard Disk
Installation guide link
https://www.nakivo.com/blog/use-virtualbox-quick-overview/
Centos installation on virtualbox
Installation Guide links
ā— https://vitux.com/install-centos-with-virtualbox-on-windows/
ā— https://phoenixnap.com/kb/how-to-install-centos-7
ā—
The 'shell' is the linux command interpreter
ā—
The shell operates in a command processing loop:
ā—
Displays a 'prompt' and reads a command line
Performs various substitutions and expansions on the command
line Executes the resulting command and waits for it to ļ¬nish
Loops back and prompts for another command
ā—
Several shells have been written for UNIX and
Linux
Bourne shell (sh), Korn Shell, C Shell, Bourne Again Shell
(bash) The core feature set of all these shells is very similar
We will focus on bash, the most popular shell on Linux
The Shell
Shell
A shell is a computer program that presents a command line interface which allows
you to control your computer using commands entered with a keyboard instead of
controlling graphical user interfaces (GUIs) with a mouse/keyboard/touchscreen
combination.
ā—
Try these simple commands:
$ hostname
thehostname
$ date
Fri Apr 16 11:48:33 BST 2004
$ id
uid=500(chris) gid=100(users)
groups=100(users),14(uucp)
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30
Reports the name
of this machine
$ cal
April 2022
Simple commands
ā—
Command options modify the behaviour of a
command
ā€“ Usually, an option is a single letter preļ¬xed
by '-'
$ cal -y
... calendar for the entire year ...
$ date -I 2022-
04-16
ā—
Some commands also have 'long' options
ā€“ Begin with '--'
ā€“ Supplement or replace the traditional single
character options
$ date --iso-8601
2022-04-14
Options are case sensitive
Same as '-
I'
The date in ISO
format
Command options
ā—
Managing ļ¬les
The current directory
Creating and deleting directories Listing
directory contents Copying ļ¬les
Renaming ļ¬les Deleting
ļ¬les Updating ļ¬les
Links and the inode table Creating
links to a ļ¬le
File and directory permissions revisited
Managing ļ¬les
Setting and querying the current directory
Every process (including the shell) has a current directory
ā€“
ā€“
ā€“ Where it will look for 1relative path names
The cd command changes the current directory.
The pwd command displays the name of the current directory
$ cd
$ pwd
/home/tux
$ cd pics
$ pwd
/home/tux/pics
$ cd /etc
$ pwd
/etc
$ cd -
/home/tux/pics
cd with no arguments takes you
to your home directory
Descend into a subdirectory
Change directory using an
absolute pathname
'-' takes you back to your
previous directory
'..' takes you up one level
Creating and deleting directories
ā—
ā—
The mkdir command creates new directories
ā€“ -p option creates additional directories, if required, along the path
The rmdir command deletes directories
ā€“ Only if they are empty
$ mkdir proposals/january
mkdir: cannot create directory `proposals/january':
No such file or directory
$ mkdir -p proposals/january
$ rmdir proposals
rmdir: `proposals': Directory not empty
$ rmdir proposals/january
$ rmdir proposals
$
Listing directory contents with the ls
command
ā—
The ls command lists ļ¬les in a directory
ā€“ If a directory name is given, the contents of the directory are shown
ā€“ With no arguments, the current directory is listed
ā—
ls has many options. Here are a few:
Option Meaning
None Display ļ¬lenames only, in a multi-column listing
-l Display a 'long' listing, including ļ¬le type, permissions, modiļ¬cation time, and size, in addition to the
name
-a Display 'hidden' ļ¬les (ones whose names begin with a '.')
-F After each name, append a character to indicate the ļ¬le type: '/' indicates a directory, '*' indicates
an executable ļ¬le, '@' indicates a symbolic link
-i Display inode numbers (discussed later)
-t Sort by time of last alteration (by default, sort is alphabetic on ļ¬le name)
-u Sort by time of last access
-R Recursive: descend into any subdirectories
-d When listing a directory, list just the directory entry, not the contents
Hidden ļ¬les
ā—Where the bash shell stores its command history
Startup ļ¬le for the X window system
ā—Startup ļ¬le for the bash shell
Startup ļ¬le for all shells
ā—
Files whose names begin with a '.' are ā€œhiddenā€
ā€“
ā€“ They do not show up on a normal directory listing
Most of them are conļ¬guration and startup ļ¬les, for example:
ā€“ .bash_history:
.xinitrc:
.bashrc:
.profile:
ā€“
ā€“
ā€“
ā—
Use ls -a to show hidden
ļ¬les
Copying ļ¬les with the cp command
ā—
The cp command copies ļ¬les
$ cp file1 file2
ā€“ This form makes a copy of file1 under the name
file2
$ cp file1 file2 ... dir
ā€“ This form makes copies of file1 file2 ... in (existing) directory dir
Beware: the destination ļ¬les will be replaced if they already exist
Options include:
ā—
ā—
Option Meaning
-i Interactive mode: ask for conļ¬rmation before replacing an existing ļ¬le
-u If the destination ļ¬le already exists, perform the operation only if the source ļ¬le is
newer than the destination ļ¬le
-l Create links instead of making copies
-s Create symbolic links instead of making copies
-r, -R Copy directories recursively
Renaming ļ¬les with the mv command
ā—
The mv command renames or moves ļ¬les
$ mv file1 file2
This form renames file1 as file2.
$ mv file1 file2 ... dir
This form moves file1 file2 ... into (existing) directory dir Beware:
the destination ļ¬les will be replaced if they already exist Options
include:
ā—
ā—
Option Meaning
-i Interactive mode: ask for conļ¬rmation before replacing an existing ļ¬le
-u If the destination ļ¬le already exists, perform the operation only if the source ļ¬le is
newer than the destination ļ¬le
Deleting ļ¬les with the rm command
ā—
The rm command deletes ļ¬les
$ rm file1 file2 ...
ā—
Beware: there is no 'undelete' command!
Options include:
ā—
Option Meaning
-i Interactive mode: ask for conļ¬rmation before deleting
-f
Normally rm will prompt for conļ¬rmation before deleting a ļ¬le on which you do not
have write permission. The -f ļ¬‚ag suppresses this prompt and forces rm to delete
the ļ¬le
-r Recursive mode: delete all subdirectories and contents (Use with caution!)
Updating ļ¬les with the touch command
ā—
The command touch updates the access and modiļ¬cation
timestamps on a ļ¬le to the current time
ā€“ Makes it appear that the ļ¬le has just been modiļ¬ed
ā€“ If the ļ¬le does not exist it is created with zero length
$ touch file1 file 2 ...
ā—
Options for touch include:
Option Meaning
-a Update only the access timestamp
-m Update only the modiļ¬cation timestamp
-r file Update the timestamps to match those of ļ¬le, not the current time
-t time Update the timestamps to the speciļ¬ed time, in the format
[[CC]YY]MMDDhhmm[.ss]
Creating links to a ļ¬le with ln
ā—
Creating additional links to a ļ¬le allows the ļ¬le to be referenced by
more than one name
ā—
General form of ln command is:
$ ln existing_name new_name
ā—
Example:
$ cd /home/dilbert
$ ln ../tux/shopping mylist
inode table
Name inum
. 55
.. 93
foo 7
shopping 10
Directory /home/tux
1
2
3
4
5
6
7
8
9
10
11
12
13
Name inum
. 1236
.. 93
bar 12
mylist 10
Directory /home/dilbert
The system keeps count (in
the inode) of the number of
links. When the last link is
removed, the inode and the
data blocks are freed.
Symbolic links
ā—
A symbolic link is a special type of ļ¬le that simply contains the
pathname of a ā€œtargetā€ ļ¬le
ā€“ Any references to the symbolic link are automatically translated into
references to the target
ā—
The '-s' ļ¬‚ag tells ln to create symbolic links
$ ln -s shopping mylist
$ ls -l shopping mylist
ā—
lrwxrwxrwx 1 chris users 8 2004-04-23 11:43 mylist -> shopping
-rw-r--r-- 1 chris users 491 2004-04-23 09:24 shopping
ā—
Deleting the target ļ¬le breaks the symbolic link and causes confusing
behaviour:
$ rm shopping
$ less mylist
mylist: No such file or directory
File and directory permissions revisited
ā— To access the data in a ļ¬le, you need read permission on the ļ¬le
To modify the data in a ļ¬le, you need write permission on the ļ¬le
ā—To list the names (only) of the ļ¬les in a directory, you need read
permission on the directory
ā—To list the attributes of the ļ¬les in a directory (e.g. to perform an ls -l), or to
use the directory in a pathname, or to make it your current directory, you
need execute permission on the directory
ā—(You need both read and execute permission to have useful access to a
directory)
ā—To add a link to a directory, or to remove a link from a directory, you
need write permission on the directory
ā—
The ways in which ļ¬le access permissions control what you can do
derive from a few simple rules
ā€“
ā€“
ā€“
ā€“
ā€“
File permission examples
Operation Situation Required permissions
cp file1 file2 file2 doesnā€™t exist r permission on file1
w permission on file2ā€™s directory
cp file1 file2 file2 already
exists
r permission on file1 w permission
on file2
mv file1 file2 w permission on file1ā€™s directory w permission
on file2ā€™s directory
rm file1 w permission on file1ā€™s directory
ln file1 file2 rx permission on file2ā€™s directory; w permission on
file2ā€™s directory
File permission quiz
ā—
Using the ls command, and your knowledge of ļ¬le permissions,
predict which of the following operations would be allowed if you
were logged in as tux
Operation Allowed? Why or why not?
Make a copy of
/etc/at.deny in your
home directory
Make a copy of
/etc/group in your home
directory
Make a copy of your
shopping ļ¬le in the
/etc directory
Delete your own home
directory
Exercise: Managing ļ¬les
1. Log in as root
2. Copy the ļ¬les passwd,group, hosts and fstab from /etc to your
home directory
3. In your home directory, rename the ļ¬le fstab to table
4. Create a directory called private in your home directory
5. Change the permissions on private so that only you can access it
ā€“ Hint: the permissions should be rwx------
6. Move the ļ¬les passwd and group into private
7. Change directory into the private directory and list the ļ¬les there
8. Log out and log back in as lpiuser with password XXX
Exercise: Managing ļ¬les (continued)
9. Log out as lpiuser and log back in as root
10. Create a hard link called mygroup in your home directory to the ļ¬le
group in the private directory
ā€“ What is the inode number associated with this link?
11. Create a symbolic link called mypasswd in your home directory to the ļ¬le
passwd in the private directory
12.Delete the private directory and its contents
13.Try to access the ļ¬les mygroup and mypasswd in your home directory
ā€“ What happens?
ā€“ Can you explain why?
14.Delete the symbolic link mypasswd
Filename expansion using wildcards
ā—
The shell uses several meta-characters for matching patterns in ļ¬le
names
ā€“ Commonly known as wildcards
$ ls -l
*.c
alias.pl
edges.c
edges.o
main.c
main.o
wireframe
$ ls -l edges.c
main.c
The command as
typed
The shell looks
in the current
directory for
matching ļ¬le
names
ā€¦ and substitutes
them back into the
command line
The command as
executed
Filename expansion using wildcards (continued)
* Matches zero or more characters
? Matches exactly one character
[ ] Matches any one of the enclosed characters, e.g. [AaTt]
[x-y] Matches any character in range
e.g. [a-m] [A-Z] [0-9]
ā—
Linux has no notion of ļ¬lename ā€œextensionsā€
ā€“ * matches all names, like *.* in DOS
Multiple wildcards can be used
ā€“ E.g. rm [A-Z]*.html
Wildcards can be used in multiple components of a pathname
ā€“ E.g. rm backups/*.199[7-9]/expenses??
ā—
ā—
Wildcard quiz
410-chap1.doc
410-chap2.doc
410-chap3.doc
410-chap4.doc
410-chap5.doc
410-CHAPS.doc
display
display.c
display.h
display.object
ideas
ideas.old
ideas.older
index
intro
intro.old
meetings.June
meetings.July
meetings.Aug
oldstuff
opensource
openwindows
project6
project45
project46
project346
training
venues
windows
x-windows
Given these ļ¬les in the current directory What do these commands do?
A directory
rm *.old
ls -l 410-chap?.doc
less 410-chap[2-5].doc
mv ideas* training
mv ideas.* training
rm *old*
rm *
cp [v-z]* training
cp [a-z]* training
ls display.?
rm proj*6
Exercise: Wildcards
ā—
Do a long listing of all the ļ¬les in /usr/bin whose names contain a
digit
ā€“ How many such ļ¬les are there?
Create a subdirectory called config in your home directory
Copy all the ļ¬les whose name ends in .conf from /etc to your
config directory
ā€“ Can you ļ¬nd a way to supress the error messages due to unreadable ļ¬les?
ā—
ā—
ā—
Change the access permissions of all ļ¬les in your config directory to be
ā€œrw ā€
ā—
Are there any ļ¬les in your config directory whose name begins with a
vowel?
ā—
Delete any ļ¬les in your config directory whose name begins with a
vowel
Editing with vi
ā—
The editor vi is the 'standard' editor on UNIX and Linux systems
Advantages:
ā—
ā€“
ā€“
ā€“ It is available on every UNIX and Linux system
It works on character terminals, without a graphical user interface It is
fast and powerful once you know it well
ā—
Disadvantages:
ā€“ It is a 'moded' editor which makes it diļ¬ƒcult to learn initially
ā€“ There are a lot of commands to remember
ā—
Professional linux users and administrators beneļ¬t in the long term by
learning vi
ā€“ Budget several hours of learning time, over a period of time
Working modes in vi
ā—
vi has three major operating modes
Start
Command Mode
Most editing operations such as
deleting and searching are
done in command mode.
Most use single character
commands
Insert Mode
The characters you
type are entered into
the edit buļ¬€er
ā€œBottom Lineā€ Mode
Most commands that require arguments use this mode.
e.g. global search and replace, write buļ¬€er to ļ¬le, go to given
line number. The command is terminated by a newline
':' Newline
i = insert before cursor
A = append to line
others ...
ESC
Command mode in vi
ā—
In command mode, most 'ordinary' characters invoke a command
ā€“ This table shows a minimal command set to survive with vi. It is nowhere near
complete and does not show the full power of the command set.
dd Delete the current line (and put in the paste buļ¬€er)
dd Delete to end of line
/string Search for string, forwards from current cursor position
?string Search for string, backwards from current cursor position
n Repeat the search in the same direction
N Repeat the search in the opposite direction
yy Yank' (copy) the current line into the paste buļ¬€er
p Insert the paste buļ¬€er before the current cursor position
ZZ Save the ļ¬le and exit (this is the normal way to exit vi)
. Repeat the last change at the current cursor position
v start selecting
y copy
d cut
u undo
ctrl+ r redo
ā€œBottom lineā€ mode in vi
ā—
The table below shows some important 'bottom line' commands
ā€“ There are also powerful global 'search and replace' commands that are not
shown here
Command Meaning
:q Quit the editor (only works if no changes have been made)
:q! Quit the editor, abandoning any changes that have been made
:wq Write the ļ¬le out and exit (same as 'ZZ' in command mode)
:w file
Write the edit buļ¬€er out to the speciļ¬ed ļ¬le (instead of the original ļ¬le)
:41 Go to line 41
:%s/host/hostname replace host with hostname
:%s/host/hostname/g replace all host with hostname
x delete a single character
dw delete a single word
Exercise: Using vi
ā—
Using vi, enter the text:
A linux sysadmin called Pete
Typed all his commands with his feet
After ā€œrm -rā€, his toe hit a star,
A sysadmin no longer is Pete
ā—
Save the text to the ļ¬le limerick in your home directory
ā—
Make the following changes:
ā€“
ā€“
ā€“ Change 'Pete' to 'Joe', (twice) and 'feet' to 'toe'
Swap the ļ¬rst line with the last line. (Use cut-and-paste, don't retype!)
Delete the third line
ā—
Save the result in the ļ¬le junk (not to the limerick ļ¬le)
Finding ļ¬les with the find command
ā—
The find command searches for ļ¬les meeting speciļ¬ed criteria
ā€“ Name, owner, group, timestamps, permissions, size, etc.
find has a complicated syntax; the general framework is:
ā—
find Where to look What to look for What to do with it
List of directories to
start looking in. find
will search recursively
down through the ļ¬le
system from here
Set of criteria
which ļ¬les must
match. Can be
used in AND and
OR combinations
The action to take when
a matching ļ¬le is found.
The default is to print
the pathname to the ļ¬le
Search criteria for find
ā—
Search criteria for find include:
ā—
The default action for find is simply to display the names of the
matching ļ¬les
Syntax Description Example
-name 'string' File name matches ā€˜stringā€™. Wildcards
are allowed
-name '*.old'
-iname 'string' Same as -name but not case sensitive -name 'greet*'
-user username File is owned by username -user dilbert
-group groupname File belongs to groupname -group root
-type d, f, or l File is a directory, regular ļ¬le, or symbolic
link
-type f
-size +N File is bigger than N blocks suļ¬ƒx c =
bytes, k = kbytes
-size +1000k
-size -N File is smaller than N blocks -size -50c
Some examples of using find
ā—
Show all ļ¬les ending in '.c' in (and below) the current directory
$ find . -name '*.c'
ā—
Find all ļ¬les under /home owned by tux
$ find /home -user tux
ā—
Find ordinary ļ¬les in /usr/bin which are bigger than 1 Mbyte
$ find /usr/bin -type f-size +1000k
Find all ordinary ļ¬les owned by root which have zero length
$ find / -type f -user root -size 0 2> /dev/null
ā—
More search criteria for find
Syntax Description Example
-perm xxx File permissions exactly match octal
digits xxx
-perm 644
-perm +xxx File has at least one of the
permissions xxx
-perm +222
-perm -xxx File has all of the permissions xxx -perm -001
-mtime +n File last modiļ¬ed more than n days ago -mtime +14
-mtime -n File last modiļ¬ed less than n days ago -mtime -2
-atime +n File last accessed more than n days ago -atime +7
-atime -n File last accessed less than n days ago -atime -1
Actions for find
ā—
ā—
An action speciļ¬es what to do with each matching ļ¬le
-print (also the default) just writes out the pathname of the ļ¬le
-ls writes output similar to ls -li for the ļ¬le
Any arbitrary command may be executed using -exec
ā€“ The syntax is messy; here's an example:
-exec rm {} ;
The command you
want to execute
Marks the end of the
-exec command
The name of the
matching ļ¬le is
substituted in here
More examples of using find
ā—
Find all ļ¬les in /home/tux or /home/dilbert which are world-writable
and give a detailed listing
$ find /home/tux /home/dilbert -perm +002 -ls
ā—
Delete ļ¬les under /home with names ending '.bak' which have not
been accessed for two weeks
$ find /home -name '*.bak' -atime +14 -exec rm {} ;
ā—
Find all ļ¬les which are not symbolic links but have mode 777
$ find / ! -type l -perm 777 2> /dev/null
'!' negates the sense
of the following test
Discard reports of
unreadable directories, etc.
Exercise: Using find
ā—
List all the directories under /home that belong to root
ā—
How many symbolic links are there under /usr/bin?
ā—
Does root own any zero-length regular ļ¬les? How
many?
ā€“ Hint: don't count them yourself!
ā—
What is the largest ļ¬le in the ļ¬lesystem?
ā€“ Hint: it is bigger than 10 Mbytes
Manual pages
ā—
The traditional way of providing online help is the ā€œmanual pageā€
ā€“ accessed via the man command
tux@earth:~> man mount
MOUNT(8) Linux Programmer's Manual
MOUNT(8)
NAME
mount - mount a file system
SYNOPSIS
mount [-lhV]
mount -a [-fFnrsvw] [-t vfstype] [-O optlist] mount [-
fnrsvw] [-o options [,...]] device | dir
mount [-fnrsvw] [-t vfstype] [-o options] device dir
DESCRIPTION
All files accessible in a Unix system are arranged in one big tree,
the file hierarchy, rooted at /. These files can be spread out over
several devices. The mount command serves to attach the file system
How a manual page is organised
ā—
Each manual page is divided up into a number of sections
ā€“ Not all sections are present for all commands
Section Contents
NAME Name and short description of the command
SYNOPSIS Description of the syntax
DESCRIPTION Detailed description of the command
OPTIONS Description of all available options
COMMANDS Instructions that can be given to the program while it is running
FILES Files referenced by the command
SEE ALSO List of related commands
DIAGNOSTICS Possible error messages and what they mean
EXAMPLE Examples of usage
AUTHOR Who wrote it
BUGS or WARNINGS Known errors and problems
Manual page section numbering
ā—
Each manual page is allocated a 'section number' depending on what
kind of thing it describes:
ā—
The output of man is piped through less for ease of browsing
Section Contents Used by
1 Commands for end users End users
2 System Calls Developers
3 Functions and Library Routines Developers
4 Device Files Administrators / developers
5 Conļ¬guration ļ¬les and ļ¬le formats Administrators
6 Games ?
7 Macro packages and ļ¬le formats ?
8 System Administration Commands Administrators
Manual page section numbering (continued)
ā—
By default the man command ļ¬nds the requested page in the lowest-
numbered section
ā€“ If the same name appears in more than one section, you may have to
specify the section number explicitly to get the right man page
$ man crontab
... man page for crontab command in section 1 ...
$ man 5 crontab
... man page for crontab file format in section 5 ...
$ man uname
... man page for uname command in section 1 ...
$ man 2 uname
Searching the manual pages by keyword
ā—
You can search for manual pages by keyword
ā€“ man -k keyword or apropos keyword
ā€“ keyword must appear in NAME section of man page
$ apropos partition
mpartition (1)
sfdisk (8)
gpart (8)
- partition an MSDOS hard disk
- Partition table manipulator for Linux
- guess PC-type hard disk partitions
ntfsfix (8) - tool for fixing NTFS partitions altered by ...
mkfs.jfs (8)
lvmdiskscan (8)
jfs_mkfs (8)
pvcreate (8)
cfdisk (8)
partprobe (8)
fdisk (8)
parted (8)
- create a JFS formatted partition
- scan for all disks / multiple devices ...
- create a JFS formatted partition
- initialize a disk or partition for use by LVM
- Curses based disk partition table manipulator
- inform the OS of partition table changes
- Partition table manipulator for Linux
- a partition manipulation program
Exercises: Using the manual pages
1. For this exercise, log in as tux
2. Look up the man page for the ls command
ā€“ What option gives a 'long' listing?
ā€“ What option gives a color listing?
3. Look up the man page for the write command
What command did you use?
4. Look up the man page for the write system call
What command did you use?
5. Find the name of the command for formatting ļ¬‚oppy disks
ā€“ Hint: Use apropos (and maybe grep)
6. Find the name of (a) the command and (b) the system call for changing
Built-in Help
ā—
Most of the GNU command line tools have built-in help, using the
--help option
tux@earth:~> cat --help Usage: cat
[OPTION] [FILE]...
Concatenate FILE(s), or standard input, to standard output.
-A, --show-all equivalent to -vET
-b,
-e
-E,
--number-nonblank
--show-ends
number nonblank output lines
equivalent to -vE
display $ at end of each line
-n, --number number all output lines
-s,
-t
-T,
-u
--squeeze-blank
--show-tabs
never more than one single blank line
equivalent to -vT
display TAB characters as ^I (ignored)
-v, --show-nonprinting
--help display
use ^ and M- notation, except for LFD and TAB
this help and exit
--version output version information and exit
With no FILE, or when FILE is -, read standard input.
quiz
ā—
What command would you use to:
Browse through a text ļ¬le
Display the ļ¬rst 5 lines of a ļ¬le
List a directory
Display the name of your current
directory
Count the number of lines in a ļ¬le
Create a symbolic link
Create a directory
Copy a ļ¬le
Delete a ļ¬le
Find a ļ¬le based on its size and owner
Look up on-line documentation Display
your user ID
Search a ļ¬le for a string Delete
an (empty) directory Delete a
non-empty directory
Linux User Management
Linux user management
awk -F':' '{ print $1}' /etc/passwd
ā— Add a user: useradd
ā— Modify a user: usermod
ā— Delete a user: userdel
User accounts are stored in the /etc/passwd file
To list out all the users in Linux, use the awk command with -F option. Here, we are
accessing a file and printing only first column with the help of print $1 and awk.
Add User
ā— create a new user account using the adduser command,
followed by the username you want to create.
ā— For example, to create a new user account named ā€œlinuxuserā€ you would run:
sudo adduser linuxuser
ā— On success, the command doesnā€™t produce any output.
ā— It creates the user and the userā€™s home directory (/home/linuxuser) and copies
files from /etc/skel directory to the userā€™s home directory.
ā— Within the home directory, the user can write, edit, and delete files and
directories.
Set Password
ā— To set a password for the new user invoke the passwd command
followed by the username:
sudo passwd linuxuser
Copy
ā— You will be prompted to enter and confirm the password
Changing password for user linuxuser.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
Make sure always you use a strong password that contains capital and lowe
case letters, numbers, and special characters.
Delete a User
ā— To delete a user account using the userdel command, followed
by the username you want to delete.
To delete the user, without deleting the user files, run:
sudo userdel username
To delete a user, the userā€™s home directory and mail spool use
the -r flag:
sudo userdel -r username
On success deletion, the userdel command doesnā€™t produce any
output.
Linux network connectivity
Basic commands
List network interfaces: ip a
Ping: Ping is used to troubleshoot connectivity. Most commonly, it's used to verify the connection between two
machines.
Eg: ping google.com
Traceroute: The traceroute command is used to determine the path between two connections
Eg. Traceroute www.moh.gov.et
Change network settings
Change dns settings:
DNS configuration file is found on : /etc/resolv.conf
View the content of the configuration file: cat /etc/resolv.conf
Output:
search v1vh5wtedphunk1ubv5u3gtejd.bx.internal.cloudapp.net internal.cloudapp.net
nameserver 168.63.129.16
Change network settings
set dhcp/dynamic IP address:
Open configuration file: /etc/sysconfig/network-scripts/ifcfg-eth0
Sudo vim /etc/sysconfig/network-scripts/ifcfg-eth0
Change the value for BOOTPROTO directive to dhcp:
BOOTPROTO=dhcp
Save and exit the file
Change network settings
set static IP address:
Open file /etc/sysconfig/network-scripts/ifcfg-eth0
Sudo vim /etc/sysconfig/network-scripts/ifcfg-eth0
Change the value for BOOTPROTO directive to static:
BOOTPROTO=static
IP Address: 192.168.1.10
Netmask: 255.255.255.0
Gateway (Router): 192.168.1.1
DNS Server 1: 192.168.1.1
DNS Server 2: 8.8.8.8
Remote login
ssh to remote server:
First check if ssh service is available on the machine:
Which sshd
output: /usr/sbin/sshd
sudo systemctl status sshd.service
Output:
sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-04-13 13:14:51 UTC; 1h 18min ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 2241 (sshd)
Remote login
ssh to remote server:
If itā€™s not installed use the following steps to install it.
sudo yum ā€“y install openssh-server openssh-clients
sudo systemctl start sshd
Connect to the server
ssh username@<server-ip-address>
Example: ssh bahmni@20.25.123.56
Once logged in check version of OS by: cat /etc/centos-release
Remote login: using remote desktop
The Remote Desktop Protocol allows remote users to see and use Windows on a device in another location.
Using anydesk software:
https://anydesk.com/en
AnyDesk is used legitimately by millions of IT professionals worldwide, to remotely connect to their clients'
devices to help with technical issues.
Download the software from: https://anydesk.com/en/downloads/linux
Select Centos 7 and download: https://anydesk.com/en/downloads/thank-you?dv=centos7_64
wget https://download.anydesk.com/linux/anydesk-6.1.1-1.el7.x86_64.rpm
Install using yum package manager:
sudo yum install ./anydesk-6.1.1-1.el7.x86_64.rpm
Disk and Memory Management
SWAP memory management
Swapping is a memory management scheme in which any process can be temporarily swapped from main memory to secondary
memory so that the main memory can be made available for other processes. It is used to improve main memory utilization.
# sudo swapon --show
ā— Make all swap off
ā—‹ sudo swapoff -a
ā— Resize the swapfile
ā—‹ sudo dd if=/dev/zero of=/swapfile bs=1G count=16 ---this creates 16GB swapspace
ā— Make swapfile usable
ā— sudo mkswap /swapfile
ā— Make swapon again
ā—‹ sudo swapon /swapfile
ā— Making the change permanent
ā— Back up the /etc/fstab file:
ā—‹ sudo cp /etc/fstab /etc/fstab.bak
ā— add the swap file information:
ā—‹ echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Mount and Unmount Disk
Mounting a filesystem simply means making the particular file system accessible at a certain point in the Linux directory tree. When
mounting a filesystem it does not matter if the filesystem is a hard disk partition, CD-ROM, floppy, or USB storage device.
Mount Disk
ā— Get disk or partition name that you want to mount.
ā—‹ # sudo lsblk
ā— Create a directory for mount point if it doesn't already exist.
ā—‹ # mkdir disk
ā— Manually mount partition using mount.
ā—‹ # sudo mount -t ext4 /dev/sdb1 disk
ā— Check if the drive was successfully mounted
ā—‹ # df -h
Unmount disk
ā— Unmount previously mounted drive.
ā—‹ # sudo umount /dev/sdb1
ā— Open /etc/fstab using your preferred text editor.
ā—‹ # sudo vi /etc/fstab
ā— Add an entry for a new mount point.
ā— Mount all filesystems in /etc/fstab.
ā—‹ # sudo mount -a
Disk management commands
Linux disk management includes several important tasks such as adding or removing storage devices, creating and
deleting partitions, mounting partitions on appropriate directories and making file system in partitions.
On Linux and Unix operating systems, you can use the df command to get a detailed report on the systemā€™s disk space
usage.
ā— The general syntax for the df command is as follows:
ā—‹ # df [OPTIONS]... FILESYSTEMā€¦
ā— Show Disk Space Usage in Human Readable Format
ā—‹ # df -h
ā— File System Types
ā—‹ # df -t
ā— To limit the output to file systems
ā—‹ # df -x filesystem
Setup Nginx
ā— NGINX is open source software for web serving, reverse
proxying, caching, load balancing, media streaming, and
more.
ā— It started out as a web server designed for maximum
performance and stability. In addition to its HTTP server
capabilities, NGINX can also function as a proxy server for
email (IMAP, POP3, and SMTP) and a reverse proxy and
load balancer for HTTP, TCP, and UDP servers.
ā— To setup Nginx you need root user privilege or non root
privilege with sudo command.
Setup Nginx
ā— First add / install epel repository on the server.
ā—‹ EPEL (Extra Packages for Enterprise Linux) is an open-source and free community-based
repository project from the Fedora team which provides 100% high-quality add-on software
packages for Linux distribution including RHEL (Red Hat Enterprise Linux), CentOS, and
Scientific Linux.
ā—‹ sudo yum install epel-release
ā— After EPEL repository is installed on your server, install Nginx using the following ā€œyumā€ command:
ā—‹ sudo yum install nginx
ā— If you are running a firewall, run the following commands to allow HTTP and HTTPS traffic:
ā—‹ sudo firewall-cmd --permanent --zone=public --add-service=http
ā—‹ sudo firewall-cmd --permanent --zone=public --add-service=https
ā—‹ sudo firewall-cmd --reload
ā— Nginx will not start automatically after it is installed. To get Nginx running and check the status,
use the systemctl command:
ā—‹ sudo systemctl start nginx
ā—‹ sudo systemctl status nginx
Setup Tomcat
ā— Tomcat is an open-source Java servlet and Java Server Page container that lets developers
implement an array of enterprise Java applications. Tomcat also runs a HTTP web server
environment in which Java code can run.
ā—‹ Tomcat relies on an existing Java installation. Check to see if your system has Java installed.
Enter the following into a terminal window:
ā–  java -version
ā—‹ You should be running at least JDK 1.8.0. If the system reports an older version or no Java
installed, install Java by entering:
ā–  sudo yum install java-1.8.0-openjdk-devel
ā—‹ Create Tomcat User and Group
ā–  sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat
ā—‹ Download Tomcat 9
ā–  cd /tmp
ā–  wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.56/bin/apache-tomcat-
9.0.56.tar.gz
Setup Tomcat
ā—‹ Extract the .tar.gz File
ā–  sudo tar xzvf apache-tomcat-9*tar.gz -C /opt/tomcat --strip-components=1
ā—‹ Modify Tomcat User Permissions
ā–  sudo chown -R tomcat:tomcat /opt/tomcat
ā–  sudo sh -c 'chmod +x /opt/tomcat/bin/*.sh'
ā— Create a System Unit File
ā—‹ Find the Java location
ā–  readlink -f $(which java)
ā—‹ Copy the parent folder of /jre/bin/java for the following step.
ā–  sudo nano /etc/systemd/system/tomcat.service
ā—‹ Paste the path from the previous step in the Environment="JAVA_HOME=<path>" line.
ā—‹ Save and close the file.
ā—‹ Refresh the system:
ā–  sudo systemctl daemon-reload
ā—‹ Set the Tomcat service to start on boot, start and check the status
ā–  sudo systemctl enable tomcat
ā–  sudo systemctl start tomcat
Setup Mysql
MySQL is a popular open-source relational database management application. It forms part of the LAMP
Stack (Linux, Apache, MySQL, PHP), a software stack that powers web servers.
ā— Download, Prepare and check the MySQL Repository
ā—‹ sudo yum update
ā—‹ sudo wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
ā—‹ sudo rpm -Uvh mysql80-community-release-el7-3.noarch.rpm
ā— Install MySQL - The script will return with a list of packages and ask you for confirmation to
download and install them. Type y and press ENTER for each of the requests.
ā— Start MySQL and Check its Status
ā—‹ sudo systemctl start mysqld
ā—‹ sudo systemctl status mysqld
ā— Login by using the following command - # mysql -u root -p
Changing MySQL Root User Password
ā— sudo mysql_secure_installation
ā— Type in a new strong password.
Setup Postgresql
Postgresql is a highly stable database management system, backed by more than 20 years of community
development which has contributed to its high levels of resilience, integrity, and correctness.
ā— Install PostgreSQL from CentOS 7 repositories
ā—‹ sudo yum install postgresql-server postgresql-contrib
ā— Once the installation is done, you can initialize the database using the below command:
ā—‹ sudo postgresql-setup initdb
ā— After initializing the database, you can start the database using:
ā—‹ sudo systemctl start postgresql
ā— Login and change password
Linux Log Monitoring and basic troubleshooting

More Related Content

Similar to LinuxTraining_3.pptx

cisco
ciscocisco
ciscoedomaldo
Ā 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to LinuxPRIYATHAMDARISI
Ā 
Red Hat Linux Certified Professional step by step guide Tech Arkit
Red Hat Linux Certified Professional step by step guide Tech ArkitRed Hat Linux Certified Professional step by step guide Tech Arkit
Red Hat Linux Certified Professional step by step guide Tech ArkitRavi Kumar
Ā 
Adhocr T-dose 2012
Adhocr T-dose 2012Adhocr T-dose 2012
Adhocr T-dose 2012Gratien D'haese
Ā 
Linux Desktop Operation - Session 1
Linux Desktop Operation - Session 1Linux Desktop Operation - Session 1
Linux Desktop Operation - Session 1Arash Foroughi
Ā 
Building distribution packages with Docker
Building distribution packages with DockerBuilding distribution packages with Docker
Building distribution packages with DockerBruno Cornec
Ā 
17 Linux Basics #burningkeyboards
17 Linux Basics #burningkeyboards17 Linux Basics #burningkeyboards
17 Linux Basics #burningkeyboardsDenis Ristic
Ā 
Linux: Everyting-as-a-service
Linux: Everyting-as-a-serviceLinux: Everyting-as-a-service
Linux: Everyting-as-a-serviceRohit Sansiya
Ā 
Linux systems - Getting started with setting up and embedded platform
Linux systems - Getting started with setting up and embedded platformLinux systems - Getting started with setting up and embedded platform
Linux systems - Getting started with setting up and embedded platformEmertxe Information Technologies Pvt Ltd
Ā 
Docker-v3.pdf
Docker-v3.pdfDocker-v3.pdf
Docker-v3.pdfBruno Cornec
Ā 
Linuxtraining 130710022121-phpapp01
Linuxtraining 130710022121-phpapp01Linuxtraining 130710022121-phpapp01
Linuxtraining 130710022121-phpapp01Chander Pandey
Ā 
Introduction-to-Linux.pptx
Introduction-to-Linux.pptxIntroduction-to-Linux.pptx
Introduction-to-Linux.pptxSharanShrinivasan1
Ā 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linuxrowiebornia
Ā 
Introduction-to-Linux.pptx
Introduction-to-Linux.pptxIntroduction-to-Linux.pptx
Introduction-to-Linux.pptxDavidMaina47
Ā 

Similar to LinuxTraining_3.pptx (20)

Linux
LinuxLinux
Linux
Ā 
Linux Systems: Getting started with setting up an Embedded platform
Linux Systems: Getting started with setting up an Embedded platformLinux Systems: Getting started with setting up an Embedded platform
Linux Systems: Getting started with setting up an Embedded platform
Ā 
Linux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell ScriptingLinux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell Scripting
Ā 
3. intro
3. intro3. intro
3. intro
Ā 
cisco
ciscocisco
cisco
Ā 
Intro to linux
Intro to linuxIntro to linux
Intro to linux
Ā 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
Ā 
Red Hat Linux Certified Professional step by step guide Tech Arkit
Red Hat Linux Certified Professional step by step guide Tech ArkitRed Hat Linux Certified Professional step by step guide Tech Arkit
Red Hat Linux Certified Professional step by step guide Tech Arkit
Ā 
Adhocr T-dose 2012
Adhocr T-dose 2012Adhocr T-dose 2012
Adhocr T-dose 2012
Ā 
Linux Desktop Operation - Session 1
Linux Desktop Operation - Session 1Linux Desktop Operation - Session 1
Linux Desktop Operation - Session 1
Ā 
Building distribution packages with Docker
Building distribution packages with DockerBuilding distribution packages with Docker
Building distribution packages with Docker
Ā 
17 Linux Basics #burningkeyboards
17 Linux Basics #burningkeyboards17 Linux Basics #burningkeyboards
17 Linux Basics #burningkeyboards
Ā 
Linux: Everyting-as-a-service
Linux: Everyting-as-a-serviceLinux: Everyting-as-a-service
Linux: Everyting-as-a-service
Ā 
Linux systems - Getting started with setting up and embedded platform
Linux systems - Getting started with setting up and embedded platformLinux systems - Getting started with setting up and embedded platform
Linux systems - Getting started with setting up and embedded platform
Ā 
Docker-v3.pdf
Docker-v3.pdfDocker-v3.pdf
Docker-v3.pdf
Ā 
Before begining linux
Before begining linuxBefore begining linux
Before begining linux
Ā 
Linuxtraining 130710022121-phpapp01
Linuxtraining 130710022121-phpapp01Linuxtraining 130710022121-phpapp01
Linuxtraining 130710022121-phpapp01
Ā 
Introduction-to-Linux.pptx
Introduction-to-Linux.pptxIntroduction-to-Linux.pptx
Introduction-to-Linux.pptx
Ā 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linux
Ā 
Introduction-to-Linux.pptx
Introduction-to-Linux.pptxIntroduction-to-Linux.pptx
Introduction-to-Linux.pptx
Ā 

Recently uploaded

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
Ā 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
Ā 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
Ā 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
Ā 
Scaling API-first ā€“ The story of a global engineering organization
Scaling API-first ā€“ The story of a global engineering organizationScaling API-first ā€“ The story of a global engineering organization
Scaling API-first ā€“ The story of a global engineering organizationRadu Cotescu
Ā 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
Ā 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
Ā 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
Ā 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
Ā 
šŸ¬ The future of MySQL is Postgres šŸ˜
šŸ¬  The future of MySQL is Postgres   šŸ˜šŸ¬  The future of MySQL is Postgres   šŸ˜
šŸ¬ The future of MySQL is Postgres šŸ˜RTylerCroy
Ā 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
Ā 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
Ā 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
Ā 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
Ā 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
Ā 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
Ā 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
Ā 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
Ā 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
Ā 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
Ā 

Recently uploaded (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Ā 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Ā 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Ā 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
Ā 
Scaling API-first ā€“ The story of a global engineering organization
Scaling API-first ā€“ The story of a global engineering organizationScaling API-first ā€“ The story of a global engineering organization
Scaling API-first ā€“ The story of a global engineering organization
Ā 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
Ā 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Ā 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Ā 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Ā 
šŸ¬ The future of MySQL is Postgres šŸ˜
šŸ¬  The future of MySQL is Postgres   šŸ˜šŸ¬  The future of MySQL is Postgres   šŸ˜
šŸ¬ The future of MySQL is Postgres šŸ˜
Ā 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
Ā 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Ā 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
Ā 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Ā 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
Ā 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
Ā 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
Ā 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
Ā 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
Ā 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
Ā 

LinuxTraining_3.pptx

  • 1. Centos login: ssh bahmni@20.25.123.56 Password: Training@emr123
  • 4. The History of Linux ā— Linux began life in 1991 ā— Linus Torvalds wrote the original Linux operating system as a hobbyist exercise in exploiting the new Intel 386 memory architecture ā— Inļ¬‚uenced by Minix, an operating system written by Torvald's professor Andy Tanenbaum as a teaching aid, which was in turn based on UNIX ā— Not derived from UNIX source code but deliberately UNIX-compatible ā— Contributions come from many other developers ā— Free Software Foundation wrote bash shell, gcc compiler, many other command line tools, distributed under the GNU 'brand name' ā— Like UNIX before it, linux was not originally conceived as a 'product'
  • 5. Linux distributions ā— The Linux kernel is the core or the heart of the operating system. ā— However to have a useful operating system, ā—‹ It need other components in addition to the kernel. ā—‹ These components can include ā–  system libraries, ā–  graphical user interfaces,(Optional), ā–  web browsers and other programs,(Optional) ā–  And other stuffs
  • 6. Linux intro The Linux kernel is the core or the heart of the operating system. However to have a useful operating system,It need other components in addition to the kernel. These components can include ā— system libraries, ā— graphical user interfaces,(Optional), ā— web browsers and other programs,(Optional) ā— And other stuffs
  • 7. Linux intro ā–ø Linux is open source software, - this means that anyone can use,copy, study and change the software in any way they choose, ā–ø Linux being free and open source software, ā–¹ it has led to the rise of Linux distributions. ā–¹ In every case the source code is free ā–ø but in some cases the distribution is not free. ā–¹ RedHat releases
  • 8. Linux Package Manager Method of installing, updating, removing, and keeping track of software updates from specific repositories (repos) in the Linux system ā–ø YUM ā€“ CentOS, RedHat ā–ø RPM - Fedora Linux, AlmaLinux, CentOS, openSUSE, ā€¦ ā–ø ZYPPER - OpenSuse. ... ā–ø APT-GET & APT-CACHE ā€“, Ubuntu ā–ø DPKG - Debian ā–ø PACMAN ā€“ ArchLinux, Manjaro ā–ø APT(Advanced Packaging Tool) ā€“ Ubuntu and related flavors,. ā–ø DNF (Fork of YUM) Command. ...
  • 9. Linux Distro ā–ø There are distributions that are commercial. ā–ø These commercial Linux distributions are backed by corporations and you can buy support from them. ā–ø There are non commercial Linux distributions, ā–ø these are maintained by community volunteers. ā–ø You have Linux distributions that are designed for server use, others that are designed for desktop use. ā–ø There are literally hundreds of Linux distributions.
  • 10. Linux Distro ā–ø Each Linux distribution has a different goal in a slightly different focus. ā–ø Your choice of distribution will be driven by the goal you're trying to accomplish. ā–¹ Ubuntu- ā–¹ Mint Linux - Multimedia ā–¹ Kali - penetration testing and conducting digital forensics. ā–¹ CentOS - Enterprise-class Linux Distribution derived from Red Hat Enterprise Linux sources ā–¹ Android - Linux without any GNU. can be found in the wild in phones, tablets and other devices.
  • 11. CentOS Community Enterprise Operating System ā–ø The best Linux distro of enterprise level production deployment ā–ø It is lightweight, reliable and fast. ā–ø Best Alternative for Red Hat Enterprise Linux (RHEL) ā–ø Security ā€“ CentOS supports ā–¹ SELinux- is a security architecture for Linux systems that allows administrators to have more control over who can access the system ā–¹ NSS (Network Security Services) - means Confidentiality, Integrity, Authentication, Non- repudiation or Entity authentication. these are related to the message exchange using a network while entity authentication service provides identification ā–¹ Linux PAM (Pluggable Authentication Modules ) is a suite of libraries that allows a Linux system administrator to configure methods to authenticate users. ā–¹ Firewalld - provides a dynamically managed firewall with support for network/firewall zones that define the trust level of network connections or interfaces.
  • 12. CentOS Pros ā–ø It is based on a Linux framework ā–ø It is very secured and less prone to any cyber threats ā–ø It also provides administrative from the system admin support perspective Cons ā–ø It is not user friendly ā–ø From the gaming and entertainment support perspective, itā€™s less compatible. ā–ø It normally doesnā€™t have that much support from the driver creation and storage management perspective. ā–ø From the technical support perspective, it is also a little bit on a lesser side than that of Ubuntuā€™s support.
  • 13. Server Virtualization Server virtualization is the process of creating multiple server instances from one physical server. Each server instance represents an isolated virtual environment. Within each virtual environment, you can run a separate operating system. Hypervisors create a virtualization layer that separates CPU/ processors, RAM and other physical resources from the virtual machines you create. VirtualBox is a virtualization software solution that allows you to create and run virtual machines on a single hardware machine. By using a type 2 hypervisor, like VirtualBox, your existing operating system stays unaffected by the virtual environment. Type 2 hypervisor runs inside of an operating system of a physical host machine. Example:- ā— VMware ā— Oracle virtual box
  • 14. Virtualbox installation guide ā— Download the VirtualBox installer - Go to the official website to download the VirtualBox installer for your operating system (Windows in this case). https://www.virtualbox.org/wiki/Downloads ā— Run the installer and define the installation options. Deploying a New VM Once you have installed VirtualBox, open the application. You can see the graphical user interface of VirtualBox which is unified for all supported host operating systems. ā— Creating a Virtual Machine Click Machine > New or hit the icon with the blue star to create a new virtual machine in VirtualBox GUI. ā— Creating a Virtual Hard Disk Installation guide link https://www.nakivo.com/blog/use-virtualbox-quick-overview/
  • 15. Centos installation on virtualbox Installation Guide links ā— https://vitux.com/install-centos-with-virtualbox-on-windows/ ā— https://phoenixnap.com/kb/how-to-install-centos-7
  • 16. ā— The 'shell' is the linux command interpreter ā— The shell operates in a command processing loop: ā— Displays a 'prompt' and reads a command line Performs various substitutions and expansions on the command line Executes the resulting command and waits for it to ļ¬nish Loops back and prompts for another command ā— Several shells have been written for UNIX and Linux Bourne shell (sh), Korn Shell, C Shell, Bourne Again Shell (bash) The core feature set of all these shells is very similar We will focus on bash, the most popular shell on Linux The Shell
  • 17. Shell A shell is a computer program that presents a command line interface which allows you to control your computer using commands entered with a keyboard instead of controlling graphical user interfaces (GUIs) with a mouse/keyboard/touchscreen combination.
  • 18. ā— Try these simple commands: $ hostname thehostname $ date Fri Apr 16 11:48:33 BST 2004 $ id uid=500(chris) gid=100(users) groups=100(users),14(uucp) Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Reports the name of this machine $ cal April 2022 Simple commands
  • 19. ā— Command options modify the behaviour of a command ā€“ Usually, an option is a single letter preļ¬xed by '-' $ cal -y ... calendar for the entire year ... $ date -I 2022- 04-16 ā— Some commands also have 'long' options ā€“ Begin with '--' ā€“ Supplement or replace the traditional single character options $ date --iso-8601 2022-04-14 Options are case sensitive Same as '- I' The date in ISO format Command options
  • 20. ā— Managing ļ¬les The current directory Creating and deleting directories Listing directory contents Copying ļ¬les Renaming ļ¬les Deleting ļ¬les Updating ļ¬les Links and the inode table Creating links to a ļ¬le File and directory permissions revisited Managing ļ¬les
  • 21. Setting and querying the current directory Every process (including the shell) has a current directory ā€“ ā€“ ā€“ Where it will look for 1relative path names The cd command changes the current directory. The pwd command displays the name of the current directory $ cd $ pwd /home/tux $ cd pics $ pwd /home/tux/pics $ cd /etc $ pwd /etc $ cd - /home/tux/pics cd with no arguments takes you to your home directory Descend into a subdirectory Change directory using an absolute pathname '-' takes you back to your previous directory '..' takes you up one level
  • 22. Creating and deleting directories ā— ā— The mkdir command creates new directories ā€“ -p option creates additional directories, if required, along the path The rmdir command deletes directories ā€“ Only if they are empty $ mkdir proposals/january mkdir: cannot create directory `proposals/january': No such file or directory $ mkdir -p proposals/january $ rmdir proposals rmdir: `proposals': Directory not empty $ rmdir proposals/january $ rmdir proposals $
  • 23. Listing directory contents with the ls command ā— The ls command lists ļ¬les in a directory ā€“ If a directory name is given, the contents of the directory are shown ā€“ With no arguments, the current directory is listed ā— ls has many options. Here are a few: Option Meaning None Display ļ¬lenames only, in a multi-column listing -l Display a 'long' listing, including ļ¬le type, permissions, modiļ¬cation time, and size, in addition to the name -a Display 'hidden' ļ¬les (ones whose names begin with a '.') -F After each name, append a character to indicate the ļ¬le type: '/' indicates a directory, '*' indicates an executable ļ¬le, '@' indicates a symbolic link -i Display inode numbers (discussed later) -t Sort by time of last alteration (by default, sort is alphabetic on ļ¬le name) -u Sort by time of last access -R Recursive: descend into any subdirectories -d When listing a directory, list just the directory entry, not the contents
  • 24. Hidden ļ¬les ā—Where the bash shell stores its command history Startup ļ¬le for the X window system ā—Startup ļ¬le for the bash shell Startup ļ¬le for all shells ā— Files whose names begin with a '.' are ā€œhiddenā€ ā€“ ā€“ They do not show up on a normal directory listing Most of them are conļ¬guration and startup ļ¬les, for example: ā€“ .bash_history: .xinitrc: .bashrc: .profile: ā€“ ā€“ ā€“ ā— Use ls -a to show hidden ļ¬les
  • 25. Copying ļ¬les with the cp command ā— The cp command copies ļ¬les $ cp file1 file2 ā€“ This form makes a copy of file1 under the name file2 $ cp file1 file2 ... dir ā€“ This form makes copies of file1 file2 ... in (existing) directory dir Beware: the destination ļ¬les will be replaced if they already exist Options include: ā— ā— Option Meaning -i Interactive mode: ask for conļ¬rmation before replacing an existing ļ¬le -u If the destination ļ¬le already exists, perform the operation only if the source ļ¬le is newer than the destination ļ¬le -l Create links instead of making copies -s Create symbolic links instead of making copies -r, -R Copy directories recursively
  • 26. Renaming ļ¬les with the mv command ā— The mv command renames or moves ļ¬les $ mv file1 file2 This form renames file1 as file2. $ mv file1 file2 ... dir This form moves file1 file2 ... into (existing) directory dir Beware: the destination ļ¬les will be replaced if they already exist Options include: ā— ā— Option Meaning -i Interactive mode: ask for conļ¬rmation before replacing an existing ļ¬le -u If the destination ļ¬le already exists, perform the operation only if the source ļ¬le is newer than the destination ļ¬le
  • 27. Deleting ļ¬les with the rm command ā— The rm command deletes ļ¬les $ rm file1 file2 ... ā— Beware: there is no 'undelete' command! Options include: ā— Option Meaning -i Interactive mode: ask for conļ¬rmation before deleting -f Normally rm will prompt for conļ¬rmation before deleting a ļ¬le on which you do not have write permission. The -f ļ¬‚ag suppresses this prompt and forces rm to delete the ļ¬le -r Recursive mode: delete all subdirectories and contents (Use with caution!)
  • 28. Updating ļ¬les with the touch command ā— The command touch updates the access and modiļ¬cation timestamps on a ļ¬le to the current time ā€“ Makes it appear that the ļ¬le has just been modiļ¬ed ā€“ If the ļ¬le does not exist it is created with zero length $ touch file1 file 2 ... ā— Options for touch include: Option Meaning -a Update only the access timestamp -m Update only the modiļ¬cation timestamp -r file Update the timestamps to match those of ļ¬le, not the current time -t time Update the timestamps to the speciļ¬ed time, in the format [[CC]YY]MMDDhhmm[.ss]
  • 29. Creating links to a ļ¬le with ln ā— Creating additional links to a ļ¬le allows the ļ¬le to be referenced by more than one name ā— General form of ln command is: $ ln existing_name new_name ā— Example: $ cd /home/dilbert $ ln ../tux/shopping mylist inode table Name inum . 55 .. 93 foo 7 shopping 10 Directory /home/tux 1 2 3 4 5 6 7 8 9 10 11 12 13 Name inum . 1236 .. 93 bar 12 mylist 10 Directory /home/dilbert The system keeps count (in the inode) of the number of links. When the last link is removed, the inode and the data blocks are freed.
  • 30. Symbolic links ā— A symbolic link is a special type of ļ¬le that simply contains the pathname of a ā€œtargetā€ ļ¬le ā€“ Any references to the symbolic link are automatically translated into references to the target ā— The '-s' ļ¬‚ag tells ln to create symbolic links $ ln -s shopping mylist $ ls -l shopping mylist ā— lrwxrwxrwx 1 chris users 8 2004-04-23 11:43 mylist -> shopping -rw-r--r-- 1 chris users 491 2004-04-23 09:24 shopping ā— Deleting the target ļ¬le breaks the symbolic link and causes confusing behaviour: $ rm shopping $ less mylist mylist: No such file or directory
  • 31. File and directory permissions revisited ā— To access the data in a ļ¬le, you need read permission on the ļ¬le To modify the data in a ļ¬le, you need write permission on the ļ¬le ā—To list the names (only) of the ļ¬les in a directory, you need read permission on the directory ā—To list the attributes of the ļ¬les in a directory (e.g. to perform an ls -l), or to use the directory in a pathname, or to make it your current directory, you need execute permission on the directory ā—(You need both read and execute permission to have useful access to a directory) ā—To add a link to a directory, or to remove a link from a directory, you need write permission on the directory ā— The ways in which ļ¬le access permissions control what you can do derive from a few simple rules ā€“ ā€“ ā€“ ā€“ ā€“
  • 32. File permission examples Operation Situation Required permissions cp file1 file2 file2 doesnā€™t exist r permission on file1 w permission on file2ā€™s directory cp file1 file2 file2 already exists r permission on file1 w permission on file2 mv file1 file2 w permission on file1ā€™s directory w permission on file2ā€™s directory rm file1 w permission on file1ā€™s directory ln file1 file2 rx permission on file2ā€™s directory; w permission on file2ā€™s directory
  • 33. File permission quiz ā— Using the ls command, and your knowledge of ļ¬le permissions, predict which of the following operations would be allowed if you were logged in as tux Operation Allowed? Why or why not? Make a copy of /etc/at.deny in your home directory Make a copy of /etc/group in your home directory Make a copy of your shopping ļ¬le in the /etc directory Delete your own home directory
  • 34. Exercise: Managing ļ¬les 1. Log in as root 2. Copy the ļ¬les passwd,group, hosts and fstab from /etc to your home directory 3. In your home directory, rename the ļ¬le fstab to table 4. Create a directory called private in your home directory 5. Change the permissions on private so that only you can access it ā€“ Hint: the permissions should be rwx------ 6. Move the ļ¬les passwd and group into private 7. Change directory into the private directory and list the ļ¬les there 8. Log out and log back in as lpiuser with password XXX
  • 35. Exercise: Managing ļ¬les (continued) 9. Log out as lpiuser and log back in as root 10. Create a hard link called mygroup in your home directory to the ļ¬le group in the private directory ā€“ What is the inode number associated with this link? 11. Create a symbolic link called mypasswd in your home directory to the ļ¬le passwd in the private directory 12.Delete the private directory and its contents 13.Try to access the ļ¬les mygroup and mypasswd in your home directory ā€“ What happens? ā€“ Can you explain why? 14.Delete the symbolic link mypasswd
  • 36. Filename expansion using wildcards ā— The shell uses several meta-characters for matching patterns in ļ¬le names ā€“ Commonly known as wildcards $ ls -l *.c alias.pl edges.c edges.o main.c main.o wireframe $ ls -l edges.c main.c The command as typed The shell looks in the current directory for matching ļ¬le names ā€¦ and substitutes them back into the command line The command as executed
  • 37. Filename expansion using wildcards (continued) * Matches zero or more characters ? Matches exactly one character [ ] Matches any one of the enclosed characters, e.g. [AaTt] [x-y] Matches any character in range e.g. [a-m] [A-Z] [0-9] ā— Linux has no notion of ļ¬lename ā€œextensionsā€ ā€“ * matches all names, like *.* in DOS Multiple wildcards can be used ā€“ E.g. rm [A-Z]*.html Wildcards can be used in multiple components of a pathname ā€“ E.g. rm backups/*.199[7-9]/expenses?? ā— ā—
  • 38. Wildcard quiz 410-chap1.doc 410-chap2.doc 410-chap3.doc 410-chap4.doc 410-chap5.doc 410-CHAPS.doc display display.c display.h display.object ideas ideas.old ideas.older index intro intro.old meetings.June meetings.July meetings.Aug oldstuff opensource openwindows project6 project45 project46 project346 training venues windows x-windows Given these ļ¬les in the current directory What do these commands do? A directory rm *.old ls -l 410-chap?.doc less 410-chap[2-5].doc mv ideas* training mv ideas.* training rm *old* rm * cp [v-z]* training cp [a-z]* training ls display.? rm proj*6
  • 39. Exercise: Wildcards ā— Do a long listing of all the ļ¬les in /usr/bin whose names contain a digit ā€“ How many such ļ¬les are there? Create a subdirectory called config in your home directory Copy all the ļ¬les whose name ends in .conf from /etc to your config directory ā€“ Can you ļ¬nd a way to supress the error messages due to unreadable ļ¬les? ā— ā— ā— Change the access permissions of all ļ¬les in your config directory to be ā€œrw ā€ ā— Are there any ļ¬les in your config directory whose name begins with a vowel? ā— Delete any ļ¬les in your config directory whose name begins with a vowel
  • 40. Editing with vi ā— The editor vi is the 'standard' editor on UNIX and Linux systems Advantages: ā— ā€“ ā€“ ā€“ It is available on every UNIX and Linux system It works on character terminals, without a graphical user interface It is fast and powerful once you know it well ā— Disadvantages: ā€“ It is a 'moded' editor which makes it diļ¬ƒcult to learn initially ā€“ There are a lot of commands to remember ā— Professional linux users and administrators beneļ¬t in the long term by learning vi ā€“ Budget several hours of learning time, over a period of time
  • 41. Working modes in vi ā— vi has three major operating modes Start Command Mode Most editing operations such as deleting and searching are done in command mode. Most use single character commands Insert Mode The characters you type are entered into the edit buļ¬€er ā€œBottom Lineā€ Mode Most commands that require arguments use this mode. e.g. global search and replace, write buļ¬€er to ļ¬le, go to given line number. The command is terminated by a newline ':' Newline i = insert before cursor A = append to line others ... ESC
  • 42. Command mode in vi ā— In command mode, most 'ordinary' characters invoke a command ā€“ This table shows a minimal command set to survive with vi. It is nowhere near complete and does not show the full power of the command set. dd Delete the current line (and put in the paste buļ¬€er) dd Delete to end of line /string Search for string, forwards from current cursor position ?string Search for string, backwards from current cursor position n Repeat the search in the same direction N Repeat the search in the opposite direction yy Yank' (copy) the current line into the paste buļ¬€er p Insert the paste buļ¬€er before the current cursor position ZZ Save the ļ¬le and exit (this is the normal way to exit vi) . Repeat the last change at the current cursor position v start selecting y copy d cut u undo ctrl+ r redo
  • 43. ā€œBottom lineā€ mode in vi ā— The table below shows some important 'bottom line' commands ā€“ There are also powerful global 'search and replace' commands that are not shown here Command Meaning :q Quit the editor (only works if no changes have been made) :q! Quit the editor, abandoning any changes that have been made :wq Write the ļ¬le out and exit (same as 'ZZ' in command mode) :w file Write the edit buļ¬€er out to the speciļ¬ed ļ¬le (instead of the original ļ¬le) :41 Go to line 41 :%s/host/hostname replace host with hostname :%s/host/hostname/g replace all host with hostname x delete a single character dw delete a single word
  • 44. Exercise: Using vi ā— Using vi, enter the text: A linux sysadmin called Pete Typed all his commands with his feet After ā€œrm -rā€, his toe hit a star, A sysadmin no longer is Pete ā— Save the text to the ļ¬le limerick in your home directory ā— Make the following changes: ā€“ ā€“ ā€“ Change 'Pete' to 'Joe', (twice) and 'feet' to 'toe' Swap the ļ¬rst line with the last line. (Use cut-and-paste, don't retype!) Delete the third line ā— Save the result in the ļ¬le junk (not to the limerick ļ¬le)
  • 45. Finding ļ¬les with the find command ā— The find command searches for ļ¬les meeting speciļ¬ed criteria ā€“ Name, owner, group, timestamps, permissions, size, etc. find has a complicated syntax; the general framework is: ā— find Where to look What to look for What to do with it List of directories to start looking in. find will search recursively down through the ļ¬le system from here Set of criteria which ļ¬les must match. Can be used in AND and OR combinations The action to take when a matching ļ¬le is found. The default is to print the pathname to the ļ¬le
  • 46. Search criteria for find ā— Search criteria for find include: ā— The default action for find is simply to display the names of the matching ļ¬les Syntax Description Example -name 'string' File name matches ā€˜stringā€™. Wildcards are allowed -name '*.old' -iname 'string' Same as -name but not case sensitive -name 'greet*' -user username File is owned by username -user dilbert -group groupname File belongs to groupname -group root -type d, f, or l File is a directory, regular ļ¬le, or symbolic link -type f -size +N File is bigger than N blocks suļ¬ƒx c = bytes, k = kbytes -size +1000k -size -N File is smaller than N blocks -size -50c
  • 47. Some examples of using find ā— Show all ļ¬les ending in '.c' in (and below) the current directory $ find . -name '*.c' ā— Find all ļ¬les under /home owned by tux $ find /home -user tux ā— Find ordinary ļ¬les in /usr/bin which are bigger than 1 Mbyte $ find /usr/bin -type f-size +1000k Find all ordinary ļ¬les owned by root which have zero length $ find / -type f -user root -size 0 2> /dev/null ā—
  • 48. More search criteria for find Syntax Description Example -perm xxx File permissions exactly match octal digits xxx -perm 644 -perm +xxx File has at least one of the permissions xxx -perm +222 -perm -xxx File has all of the permissions xxx -perm -001 -mtime +n File last modiļ¬ed more than n days ago -mtime +14 -mtime -n File last modiļ¬ed less than n days ago -mtime -2 -atime +n File last accessed more than n days ago -atime +7 -atime -n File last accessed less than n days ago -atime -1
  • 49. Actions for find ā— ā— An action speciļ¬es what to do with each matching ļ¬le -print (also the default) just writes out the pathname of the ļ¬le -ls writes output similar to ls -li for the ļ¬le Any arbitrary command may be executed using -exec ā€“ The syntax is messy; here's an example: -exec rm {} ; The command you want to execute Marks the end of the -exec command The name of the matching ļ¬le is substituted in here
  • 50. More examples of using find ā— Find all ļ¬les in /home/tux or /home/dilbert which are world-writable and give a detailed listing $ find /home/tux /home/dilbert -perm +002 -ls ā— Delete ļ¬les under /home with names ending '.bak' which have not been accessed for two weeks $ find /home -name '*.bak' -atime +14 -exec rm {} ; ā— Find all ļ¬les which are not symbolic links but have mode 777 $ find / ! -type l -perm 777 2> /dev/null '!' negates the sense of the following test Discard reports of unreadable directories, etc.
  • 51. Exercise: Using find ā— List all the directories under /home that belong to root ā— How many symbolic links are there under /usr/bin? ā— Does root own any zero-length regular ļ¬les? How many? ā€“ Hint: don't count them yourself! ā— What is the largest ļ¬le in the ļ¬lesystem? ā€“ Hint: it is bigger than 10 Mbytes
  • 52. Manual pages ā— The traditional way of providing online help is the ā€œmanual pageā€ ā€“ accessed via the man command tux@earth:~> man mount MOUNT(8) Linux Programmer's Manual MOUNT(8) NAME mount - mount a file system SYNOPSIS mount [-lhV] mount -a [-fFnrsvw] [-t vfstype] [-O optlist] mount [- fnrsvw] [-o options [,...]] device | dir mount [-fnrsvw] [-t vfstype] [-o options] device dir DESCRIPTION All files accessible in a Unix system are arranged in one big tree, the file hierarchy, rooted at /. These files can be spread out over several devices. The mount command serves to attach the file system
  • 53. How a manual page is organised ā— Each manual page is divided up into a number of sections ā€“ Not all sections are present for all commands Section Contents NAME Name and short description of the command SYNOPSIS Description of the syntax DESCRIPTION Detailed description of the command OPTIONS Description of all available options COMMANDS Instructions that can be given to the program while it is running FILES Files referenced by the command SEE ALSO List of related commands DIAGNOSTICS Possible error messages and what they mean EXAMPLE Examples of usage AUTHOR Who wrote it BUGS or WARNINGS Known errors and problems
  • 54. Manual page section numbering ā— Each manual page is allocated a 'section number' depending on what kind of thing it describes: ā— The output of man is piped through less for ease of browsing Section Contents Used by 1 Commands for end users End users 2 System Calls Developers 3 Functions and Library Routines Developers 4 Device Files Administrators / developers 5 Conļ¬guration ļ¬les and ļ¬le formats Administrators 6 Games ? 7 Macro packages and ļ¬le formats ? 8 System Administration Commands Administrators
  • 55. Manual page section numbering (continued) ā— By default the man command ļ¬nds the requested page in the lowest- numbered section ā€“ If the same name appears in more than one section, you may have to specify the section number explicitly to get the right man page $ man crontab ... man page for crontab command in section 1 ... $ man 5 crontab ... man page for crontab file format in section 5 ... $ man uname ... man page for uname command in section 1 ... $ man 2 uname
  • 56. Searching the manual pages by keyword ā— You can search for manual pages by keyword ā€“ man -k keyword or apropos keyword ā€“ keyword must appear in NAME section of man page $ apropos partition mpartition (1) sfdisk (8) gpart (8) - partition an MSDOS hard disk - Partition table manipulator for Linux - guess PC-type hard disk partitions ntfsfix (8) - tool for fixing NTFS partitions altered by ... mkfs.jfs (8) lvmdiskscan (8) jfs_mkfs (8) pvcreate (8) cfdisk (8) partprobe (8) fdisk (8) parted (8) - create a JFS formatted partition - scan for all disks / multiple devices ... - create a JFS formatted partition - initialize a disk or partition for use by LVM - Curses based disk partition table manipulator - inform the OS of partition table changes - Partition table manipulator for Linux - a partition manipulation program
  • 57. Exercises: Using the manual pages 1. For this exercise, log in as tux 2. Look up the man page for the ls command ā€“ What option gives a 'long' listing? ā€“ What option gives a color listing? 3. Look up the man page for the write command What command did you use? 4. Look up the man page for the write system call What command did you use? 5. Find the name of the command for formatting ļ¬‚oppy disks ā€“ Hint: Use apropos (and maybe grep) 6. Find the name of (a) the command and (b) the system call for changing
  • 58. Built-in Help ā— Most of the GNU command line tools have built-in help, using the --help option tux@earth:~> cat --help Usage: cat [OPTION] [FILE]... Concatenate FILE(s), or standard input, to standard output. -A, --show-all equivalent to -vET -b, -e -E, --number-nonblank --show-ends number nonblank output lines equivalent to -vE display $ at end of each line -n, --number number all output lines -s, -t -T, -u --squeeze-blank --show-tabs never more than one single blank line equivalent to -vT display TAB characters as ^I (ignored) -v, --show-nonprinting --help display use ^ and M- notation, except for LFD and TAB this help and exit --version output version information and exit With no FILE, or when FILE is -, read standard input.
  • 59. quiz ā— What command would you use to: Browse through a text ļ¬le Display the ļ¬rst 5 lines of a ļ¬le List a directory Display the name of your current directory Count the number of lines in a ļ¬le Create a symbolic link Create a directory Copy a ļ¬le Delete a ļ¬le Find a ļ¬le based on its size and owner Look up on-line documentation Display your user ID Search a ļ¬le for a string Delete an (empty) directory Delete a non-empty directory
  • 61. Linux user management awk -F':' '{ print $1}' /etc/passwd ā— Add a user: useradd ā— Modify a user: usermod ā— Delete a user: userdel User accounts are stored in the /etc/passwd file To list out all the users in Linux, use the awk command with -F option. Here, we are accessing a file and printing only first column with the help of print $1 and awk.
  • 62. Add User ā— create a new user account using the adduser command, followed by the username you want to create. ā— For example, to create a new user account named ā€œlinuxuserā€ you would run: sudo adduser linuxuser ā— On success, the command doesnā€™t produce any output. ā— It creates the user and the userā€™s home directory (/home/linuxuser) and copies files from /etc/skel directory to the userā€™s home directory. ā— Within the home directory, the user can write, edit, and delete files and directories.
  • 63. Set Password ā— To set a password for the new user invoke the passwd command followed by the username: sudo passwd linuxuser Copy ā— You will be prompted to enter and confirm the password Changing password for user linuxuser. New password: Retype new password: passwd: all authentication tokens updated successfully. Make sure always you use a strong password that contains capital and lowe case letters, numbers, and special characters.
  • 64. Delete a User ā— To delete a user account using the userdel command, followed by the username you want to delete. To delete the user, without deleting the user files, run: sudo userdel username To delete a user, the userā€™s home directory and mail spool use the -r flag: sudo userdel -r username On success deletion, the userdel command doesnā€™t produce any output.
  • 65. Linux network connectivity Basic commands List network interfaces: ip a Ping: Ping is used to troubleshoot connectivity. Most commonly, it's used to verify the connection between two machines. Eg: ping google.com Traceroute: The traceroute command is used to determine the path between two connections Eg. Traceroute www.moh.gov.et
  • 66. Change network settings Change dns settings: DNS configuration file is found on : /etc/resolv.conf View the content of the configuration file: cat /etc/resolv.conf Output: search v1vh5wtedphunk1ubv5u3gtejd.bx.internal.cloudapp.net internal.cloudapp.net nameserver 168.63.129.16
  • 67. Change network settings set dhcp/dynamic IP address: Open configuration file: /etc/sysconfig/network-scripts/ifcfg-eth0 Sudo vim /etc/sysconfig/network-scripts/ifcfg-eth0 Change the value for BOOTPROTO directive to dhcp: BOOTPROTO=dhcp Save and exit the file
  • 68. Change network settings set static IP address: Open file /etc/sysconfig/network-scripts/ifcfg-eth0 Sudo vim /etc/sysconfig/network-scripts/ifcfg-eth0 Change the value for BOOTPROTO directive to static: BOOTPROTO=static IP Address: 192.168.1.10 Netmask: 255.255.255.0 Gateway (Router): 192.168.1.1 DNS Server 1: 192.168.1.1 DNS Server 2: 8.8.8.8
  • 69. Remote login ssh to remote server: First check if ssh service is available on the machine: Which sshd output: /usr/sbin/sshd sudo systemctl status sshd.service Output: sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2022-04-13 13:14:51 UTC; 1h 18min ago Docs: man:sshd(8) man:sshd_config(5) Main PID: 2241 (sshd)
  • 70. Remote login ssh to remote server: If itā€™s not installed use the following steps to install it. sudo yum ā€“y install openssh-server openssh-clients sudo systemctl start sshd Connect to the server ssh username@<server-ip-address> Example: ssh bahmni@20.25.123.56 Once logged in check version of OS by: cat /etc/centos-release
  • 71. Remote login: using remote desktop The Remote Desktop Protocol allows remote users to see and use Windows on a device in another location. Using anydesk software: https://anydesk.com/en AnyDesk is used legitimately by millions of IT professionals worldwide, to remotely connect to their clients' devices to help with technical issues. Download the software from: https://anydesk.com/en/downloads/linux Select Centos 7 and download: https://anydesk.com/en/downloads/thank-you?dv=centos7_64 wget https://download.anydesk.com/linux/anydesk-6.1.1-1.el7.x86_64.rpm Install using yum package manager: sudo yum install ./anydesk-6.1.1-1.el7.x86_64.rpm
  • 72. Disk and Memory Management SWAP memory management Swapping is a memory management scheme in which any process can be temporarily swapped from main memory to secondary memory so that the main memory can be made available for other processes. It is used to improve main memory utilization. # sudo swapon --show ā— Make all swap off ā—‹ sudo swapoff -a ā— Resize the swapfile ā—‹ sudo dd if=/dev/zero of=/swapfile bs=1G count=16 ---this creates 16GB swapspace ā— Make swapfile usable ā— sudo mkswap /swapfile ā— Make swapon again ā—‹ sudo swapon /swapfile ā— Making the change permanent ā— Back up the /etc/fstab file: ā—‹ sudo cp /etc/fstab /etc/fstab.bak ā— add the swap file information: ā—‹ echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
  • 73. Mount and Unmount Disk Mounting a filesystem simply means making the particular file system accessible at a certain point in the Linux directory tree. When mounting a filesystem it does not matter if the filesystem is a hard disk partition, CD-ROM, floppy, or USB storage device. Mount Disk ā— Get disk or partition name that you want to mount. ā—‹ # sudo lsblk ā— Create a directory for mount point if it doesn't already exist. ā—‹ # mkdir disk ā— Manually mount partition using mount. ā—‹ # sudo mount -t ext4 /dev/sdb1 disk ā— Check if the drive was successfully mounted ā—‹ # df -h Unmount disk ā— Unmount previously mounted drive. ā—‹ # sudo umount /dev/sdb1 ā— Open /etc/fstab using your preferred text editor. ā—‹ # sudo vi /etc/fstab ā— Add an entry for a new mount point. ā— Mount all filesystems in /etc/fstab. ā—‹ # sudo mount -a
  • 74. Disk management commands Linux disk management includes several important tasks such as adding or removing storage devices, creating and deleting partitions, mounting partitions on appropriate directories and making file system in partitions. On Linux and Unix operating systems, you can use the df command to get a detailed report on the systemā€™s disk space usage. ā— The general syntax for the df command is as follows: ā—‹ # df [OPTIONS]... FILESYSTEMā€¦ ā— Show Disk Space Usage in Human Readable Format ā—‹ # df -h ā— File System Types ā—‹ # df -t ā— To limit the output to file systems ā—‹ # df -x filesystem
  • 75. Setup Nginx ā— NGINX is open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. ā— It started out as a web server designed for maximum performance and stability. In addition to its HTTP server capabilities, NGINX can also function as a proxy server for email (IMAP, POP3, and SMTP) and a reverse proxy and load balancer for HTTP, TCP, and UDP servers. ā— To setup Nginx you need root user privilege or non root privilege with sudo command.
  • 76. Setup Nginx ā— First add / install epel repository on the server. ā—‹ EPEL (Extra Packages for Enterprise Linux) is an open-source and free community-based repository project from the Fedora team which provides 100% high-quality add-on software packages for Linux distribution including RHEL (Red Hat Enterprise Linux), CentOS, and Scientific Linux. ā—‹ sudo yum install epel-release ā— After EPEL repository is installed on your server, install Nginx using the following ā€œyumā€ command: ā—‹ sudo yum install nginx ā— If you are running a firewall, run the following commands to allow HTTP and HTTPS traffic: ā—‹ sudo firewall-cmd --permanent --zone=public --add-service=http ā—‹ sudo firewall-cmd --permanent --zone=public --add-service=https ā—‹ sudo firewall-cmd --reload ā— Nginx will not start automatically after it is installed. To get Nginx running and check the status, use the systemctl command: ā—‹ sudo systemctl start nginx ā—‹ sudo systemctl status nginx
  • 77. Setup Tomcat ā— Tomcat is an open-source Java servlet and Java Server Page container that lets developers implement an array of enterprise Java applications. Tomcat also runs a HTTP web server environment in which Java code can run. ā—‹ Tomcat relies on an existing Java installation. Check to see if your system has Java installed. Enter the following into a terminal window: ā–  java -version ā—‹ You should be running at least JDK 1.8.0. If the system reports an older version or no Java installed, install Java by entering: ā–  sudo yum install java-1.8.0-openjdk-devel ā—‹ Create Tomcat User and Group ā–  sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat ā—‹ Download Tomcat 9 ā–  cd /tmp ā–  wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.56/bin/apache-tomcat- 9.0.56.tar.gz
  • 78. Setup Tomcat ā—‹ Extract the .tar.gz File ā–  sudo tar xzvf apache-tomcat-9*tar.gz -C /opt/tomcat --strip-components=1 ā—‹ Modify Tomcat User Permissions ā–  sudo chown -R tomcat:tomcat /opt/tomcat ā–  sudo sh -c 'chmod +x /opt/tomcat/bin/*.sh' ā— Create a System Unit File ā—‹ Find the Java location ā–  readlink -f $(which java) ā—‹ Copy the parent folder of /jre/bin/java for the following step. ā–  sudo nano /etc/systemd/system/tomcat.service ā—‹ Paste the path from the previous step in the Environment="JAVA_HOME=<path>" line. ā—‹ Save and close the file. ā—‹ Refresh the system: ā–  sudo systemctl daemon-reload ā—‹ Set the Tomcat service to start on boot, start and check the status ā–  sudo systemctl enable tomcat ā–  sudo systemctl start tomcat
  • 79. Setup Mysql MySQL is a popular open-source relational database management application. It forms part of the LAMP Stack (Linux, Apache, MySQL, PHP), a software stack that powers web servers. ā— Download, Prepare and check the MySQL Repository ā—‹ sudo yum update ā—‹ sudo wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm ā—‹ sudo rpm -Uvh mysql80-community-release-el7-3.noarch.rpm ā— Install MySQL - The script will return with a list of packages and ask you for confirmation to download and install them. Type y and press ENTER for each of the requests. ā— Start MySQL and Check its Status ā—‹ sudo systemctl start mysqld ā—‹ sudo systemctl status mysqld ā— Login by using the following command - # mysql -u root -p Changing MySQL Root User Password ā— sudo mysql_secure_installation ā— Type in a new strong password.
  • 80. Setup Postgresql Postgresql is a highly stable database management system, backed by more than 20 years of community development which has contributed to its high levels of resilience, integrity, and correctness. ā— Install PostgreSQL from CentOS 7 repositories ā—‹ sudo yum install postgresql-server postgresql-contrib ā— Once the installation is done, you can initialize the database using the below command: ā—‹ sudo postgresql-setup initdb ā— After initializing the database, you can start the database using: ā—‹ sudo systemctl start postgresql ā— Login and change password
  • 81. Linux Log Monitoring and basic troubleshooting