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
● Influenced 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 finish
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 prefixed
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 files
The current directory
Creating and deleting directories Listing
directory contents Copying files
Renaming files Deleting
files Updating files
Links and the inode table Creating
links to a file
File and directory permissions revisited
Managing files
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 files 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 filenames only, in a multi-column listing
-l Display a 'long' listing, including file type, permissions, modification time, and size, in addition to the
name
-a Display 'hidden' files (ones whose names begin with a '.')
-F After each name, append a character to indicate the file type: '/' indicates a directory, '*' indicates
an executable file, '@' indicates a symbolic link
-i Display inode numbers (discussed later)
-t Sort by time of last alteration (by default, sort is alphabetic on file 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 files
●Where the bash shell stores its command history
Startup file for the X window system
●Startup file for the bash shell
Startup file 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 configuration and startup files, for example:
– .bash_history:
.xinitrc:
.bashrc:
.profile:
–
–
–
●
Use ls -a to show hidden
files
Copying files with the cp command
●
The cp command copies files
$ 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 files will be replaced if they already exist
Options include:
●
●
Option Meaning
-i Interactive mode: ask for confirmation before replacing an existing file
-u If the destination file already exists, perform the operation only if the source file is
newer than the destination file
-l Create links instead of making copies
-s Create symbolic links instead of making copies
-r, -R Copy directories recursively
Renaming files with the mv command
●
The mv command renames or moves files
$ 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 files will be replaced if they already exist Options
include:
●
●
Option Meaning
-i Interactive mode: ask for confirmation before replacing an existing file
-u If the destination file already exists, perform the operation only if the source file is
newer than the destination file
Deleting files with the rm command
●
The rm command deletes files
$ rm file1 file2 ...
●
Beware: there is no 'undelete' command!
Options include:
●
Option Meaning
-i Interactive mode: ask for confirmation before deleting
-f
Normally rm will prompt for confirmation before deleting a file on which you do not
have write permission. The -f flag suppresses this prompt and forces rm to delete
the file
-r Recursive mode: delete all subdirectories and contents (Use with caution!)
Updating files with the touch command
●
The command touch updates the access and modification
timestamps on a file to the current time
– Makes it appear that the file has just been modified
– If the file 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 modification timestamp
-r file Update the timestamps to match those of file, not the current time
-t time Update the timestamps to the specified time, in the format
[[CC]YY]MMDDhhmm[.ss]
Creating links to a file with ln
●
Creating additional links to a file allows the file 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 file that simply contains the
pathname of a “target” file
– Any references to the symbolic link are automatically translated into
references to the target
●
The '-s' flag 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 file 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 file, you need read permission on the file
To modify the data in a file, you need write permission on the file
●To list the names (only) of the files in a directory, you need read
permission on the directory
●To list the attributes of the files 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 file 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 file 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 file in the
/etc directory
Delete your own home
directory
Exercise: Managing files
1. Log in as root
2. Copy the files passwd,group, hosts and fstab from /etc to your
home directory
3. In your home directory, rename the file 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 files passwd and group into private
7. Change directory into the private directory and list the files there
8. Log out and log back in as lpiuser with password XXX
Exercise: Managing files (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 file
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 file
passwd in the private directory
12.Delete the private directory and its contents
13.Try to access the files 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 file
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 file
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 filename “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 files 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 files in /usr/bin whose names contain a
digit
– How many such files are there?
Create a subdirectory called config in your home directory
Copy all the files whose name ends in .conf from /etc to your
config directory
– Can you find a way to supress the error messages due to unreadable files?
●
●
●
Change the access permissions of all files in your config directory to be
“rw ”
●
Are there any files in your config directory whose name begins with a
vowel?
●
Delete any files 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 difficult to learn initially
– There are a lot of commands to remember
●
Professional linux users and administrators benefit 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 buffer
“Bottom Line” Mode
Most commands that require arguments use this mode.
e.g. global search and replace, write buffer to file, 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 buffer)
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 buffer
p Insert the paste buffer before the current cursor position
ZZ Save the file 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 file out and exit (same as 'ZZ' in command mode)
:w file
Write the edit buffer out to the specified file (instead of the original file)
: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 file limerick in your home directory
●
Make the following changes:
–
–
– Change 'Pete' to 'Joe', (twice) and 'feet' to 'toe'
Swap the first line with the last line. (Use cut-and-paste, don't retype!)
Delete the third line
●
Save the result in the file junk (not to the limerick file)
Finding files with the find command
●
The find command searches for files meeting specified 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 file
system from here
Set of criteria
which files must
match. Can be
used in AND and
OR combinations
The action to take when
a matching file is found.
The default is to print
the pathname to the file
Search criteria for find
●
Search criteria for find include:
●
The default action for find is simply to display the names of the
matching files
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 file, or symbolic
link
-type f
-size +N File is bigger than N blocks suffix c =
bytes, k = kbytes
-size +1000k
-size -N File is smaller than N blocks -size -50c
Some examples of using find
●
Show all files ending in '.c' in (and below) the current directory
$ find . -name '*.c'
●
Find all files under /home owned by tux
$ find /home -user tux
●
Find ordinary files in /usr/bin which are bigger than 1 Mbyte
$ find /usr/bin -type f-size +1000k
Find all ordinary files 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 modified more than n days ago -mtime +14
-mtime -n File last modified 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 specifies what to do with each matching file
-print (also the default) just writes out the pathname of the file
-ls writes output similar to ls -li for the file
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 file is
substituted in here
More examples of using find
●
Find all files in /home/tux or /home/dilbert which are world-writable
and give a detailed listing
$ find /home/tux /home/dilbert -perm +002 -ls
●
Delete files under /home with names ending '.bak' which have not
been accessed for two weeks
$ find /home -name '*.bak' -atime +14 -exec rm {} ;
●
Find all files 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 files? How
many?
– Hint: don't count them yourself!
●
What is the largest file in the filesystem?
– 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 Configuration files and file formats Administrators
6 Games ?
7 Macro packages and file formats ?
8 System Administration Commands Administrators
Manual page section numbering (continued)
●
By default the man command finds 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 floppy 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 file
Display the first 5 lines of a file
List a directory
Display the name of your current
directory
Count the number of lines in a file
Create a symbolic link
Create a directory
Copy a file
Delete a file
Find a file based on its size and owner
Look up on-line documentation Display
your user ID
Search a file 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

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
 
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
 
Linuxtraining 130710022121-phpapp01
Linuxtraining 130710022121-phpapp01Linuxtraining 130710022121-phpapp01
Linuxtraining 130710022121-phpapp01Chander Pandey
 
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

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 

Recently uploaded (20)

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 

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 ● Influenced 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 finish 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 prefixed 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 files The current directory Creating and deleting directories Listing directory contents Copying files Renaming files Deleting files Updating files Links and the inode table Creating links to a file File and directory permissions revisited Managing files
  • 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 files 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 filenames only, in a multi-column listing -l Display a 'long' listing, including file type, permissions, modification time, and size, in addition to the name -a Display 'hidden' files (ones whose names begin with a '.') -F After each name, append a character to indicate the file type: '/' indicates a directory, '*' indicates an executable file, '@' indicates a symbolic link -i Display inode numbers (discussed later) -t Sort by time of last alteration (by default, sort is alphabetic on file 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 files ●Where the bash shell stores its command history Startup file for the X window system ●Startup file for the bash shell Startup file 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 configuration and startup files, for example: – .bash_history: .xinitrc: .bashrc: .profile: – – – ● Use ls -a to show hidden files
  • 25. Copying files with the cp command ● The cp command copies files $ 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 files will be replaced if they already exist Options include: ● ● Option Meaning -i Interactive mode: ask for confirmation before replacing an existing file -u If the destination file already exists, perform the operation only if the source file is newer than the destination file -l Create links instead of making copies -s Create symbolic links instead of making copies -r, -R Copy directories recursively
  • 26. Renaming files with the mv command ● The mv command renames or moves files $ 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 files will be replaced if they already exist Options include: ● ● Option Meaning -i Interactive mode: ask for confirmation before replacing an existing file -u If the destination file already exists, perform the operation only if the source file is newer than the destination file
  • 27. Deleting files with the rm command ● The rm command deletes files $ rm file1 file2 ... ● Beware: there is no 'undelete' command! Options include: ● Option Meaning -i Interactive mode: ask for confirmation before deleting -f Normally rm will prompt for confirmation before deleting a file on which you do not have write permission. The -f flag suppresses this prompt and forces rm to delete the file -r Recursive mode: delete all subdirectories and contents (Use with caution!)
  • 28. Updating files with the touch command ● The command touch updates the access and modification timestamps on a file to the current time – Makes it appear that the file has just been modified – If the file 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 modification timestamp -r file Update the timestamps to match those of file, not the current time -t time Update the timestamps to the specified time, in the format [[CC]YY]MMDDhhmm[.ss]
  • 29. Creating links to a file with ln ● Creating additional links to a file allows the file 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 file that simply contains the pathname of a “target” file – Any references to the symbolic link are automatically translated into references to the target ● The '-s' flag 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 file 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 file, you need read permission on the file To modify the data in a file, you need write permission on the file ●To list the names (only) of the files in a directory, you need read permission on the directory ●To list the attributes of the files 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 file 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 file 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 file in the /etc directory Delete your own home directory
  • 34. Exercise: Managing files 1. Log in as root 2. Copy the files passwd,group, hosts and fstab from /etc to your home directory 3. In your home directory, rename the file 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 files passwd and group into private 7. Change directory into the private directory and list the files there 8. Log out and log back in as lpiuser with password XXX
  • 35. Exercise: Managing files (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 file 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 file passwd in the private directory 12.Delete the private directory and its contents 13.Try to access the files 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 file 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 file 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 filename “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 files 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 files in /usr/bin whose names contain a digit – How many such files are there? Create a subdirectory called config in your home directory Copy all the files whose name ends in .conf from /etc to your config directory – Can you find a way to supress the error messages due to unreadable files? ● ● ● Change the access permissions of all files in your config directory to be “rw ” ● Are there any files in your config directory whose name begins with a vowel? ● Delete any files 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 difficult to learn initially – There are a lot of commands to remember ● Professional linux users and administrators benefit 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 buffer “Bottom Line” Mode Most commands that require arguments use this mode. e.g. global search and replace, write buffer to file, 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 buffer) 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 buffer p Insert the paste buffer before the current cursor position ZZ Save the file 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 file out and exit (same as 'ZZ' in command mode) :w file Write the edit buffer out to the specified file (instead of the original file) :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 file limerick in your home directory ● Make the following changes: – – – Change 'Pete' to 'Joe', (twice) and 'feet' to 'toe' Swap the first line with the last line. (Use cut-and-paste, don't retype!) Delete the third line ● Save the result in the file junk (not to the limerick file)
  • 45. Finding files with the find command ● The find command searches for files meeting specified 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 file system from here Set of criteria which files must match. Can be used in AND and OR combinations The action to take when a matching file is found. The default is to print the pathname to the file
  • 46. Search criteria for find ● Search criteria for find include: ● The default action for find is simply to display the names of the matching files 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 file, or symbolic link -type f -size +N File is bigger than N blocks suffix c = bytes, k = kbytes -size +1000k -size -N File is smaller than N blocks -size -50c
  • 47. Some examples of using find ● Show all files ending in '.c' in (and below) the current directory $ find . -name '*.c' ● Find all files under /home owned by tux $ find /home -user tux ● Find ordinary files in /usr/bin which are bigger than 1 Mbyte $ find /usr/bin -type f-size +1000k Find all ordinary files 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 modified more than n days ago -mtime +14 -mtime -n File last modified 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 specifies what to do with each matching file -print (also the default) just writes out the pathname of the file -ls writes output similar to ls -li for the file 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 file is substituted in here
  • 50. More examples of using find ● Find all files in /home/tux or /home/dilbert which are world-writable and give a detailed listing $ find /home/tux /home/dilbert -perm +002 -ls ● Delete files under /home with names ending '.bak' which have not been accessed for two weeks $ find /home -name '*.bak' -atime +14 -exec rm {} ; ● Find all files 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 files? How many? – Hint: don't count them yourself! ● What is the largest file in the filesystem? – 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 Configuration files and file formats Administrators 6 Games ? 7 Macro packages and file formats ? 8 System Administration Commands Administrators
  • 55. Manual page section numbering (continued) ● By default the man command finds 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 floppy 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 file Display the first 5 lines of a file List a directory Display the name of your current directory Count the number of lines in a file Create a symbolic link Create a directory Copy a file Delete a file Find a file based on its size and owner Look up on-line documentation Display your user ID Search a file 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