You are on page 1of 175

SYSTEM ADMINISTRATION AND

MAINTENANCE
Schedule

Course Schedule

The course has two theory sessions per week and


one lab session of 3 hours.
Lectures : Every Tuesday, 9:00 AM - 9:55 AM and
Wednesday, 8:00 AM – 8:55 AM
Labs : Every Monday, 1:30 – 4:30 PM
Grading

Grading Guidelines
30% Mid-Sem exam (with 15% online 60 minutes +15%
remote 60 minutes)

45% End-Sem exam (with 20% online 80 minutes + 25%


remote 100 minutes)

25% rest (includes quizzes, lab assignments, projects, viva etc.).


Course References

References

Unix and Linux System Administration Handbook,


E. Nemeth, G. Snyder et al
Red Hat Linux, O'Reilly
Linux System Administration Full Course by
Geek's Lesson (Youtube)
System Administration Full Course by Geek's
Lesson (Youtube)
Linux System Admin course at IITK
Introduction to Linux

UNIX/LINUX OPERATING SYSTEM


Introduction to Unix
History of UNIX
What is LINUX?
LINUX Distributions
Unix OS Structure
Unix File System
Unix Directories, Files and Inodes
Users, Groups and Permissions
Introduction to Linux

UNIX

Unix is a multi-user, multi-tasking operating


system.
You can have many users logged into a system
simultaneously, each running many programs.
It's the kernel's job to keep each process and user
separate and to regulate access to system
hardware, including cpu, memory, disk and other
I/O devices.
Unix philosophy - “small, precise tools chained
together simplifying larger tasks”
Introduction to Linux

History of UNIX

First Version was created in Bell Labs in 1969.


Some of the Bell Labs programmers who had
worked on this project, Ken Thompson, Dennis
R i t c h i e , R u d d C a n a d a y, a n d D o u g M c I l r o y
designed and implemented the first version of the
Unix File System on a PDP-7 along with a few
utilities. It was given the name UNIX by Brian
Kernighan.
00:00:00 Hours, Jan 1, 1970 is time zero for UNIX. It
is also called as epoch.
Introduction to Linux

History of UNIX

1973 Unix is re-written mostly in C, a new language


developed by Dennis Ritchie.
Being written in this high-level language greatly
decreased the effort needed to port it to new
machines.
Introduction to Linux

History of UNIX

1977 There were about 500 Unix sites world-wide.


1980 BSD 4.1 (Berkeley Software Development)
1983 SunOS, BSD 4.2, System V
1988 AT&T and Sun Microsystems jointly develop
System V Release 4 (SVR4). This later developed
into UnixWare and Solaris 2.
1991 Linux was originated.
Introduction to Linux

What is LINUX

Linux is a free Unix-type operating system


originally created by Linus Torvalds with the
assistance of developers around the world.
It originated in 1991 as a personal project of Linus
Torvalds, a Finnish graduate student.
The Kernel version 1.0 was released in 1994 and
today the most recent stable version is 5.4.8
Developed under the GNU General Public License ,
the source code for Linux is freely available to
everyone.
Introduction to Linux

LINUX Distributions
Mandrake: http://www.mandrakesoft.com/
RedHat: http://www.redhat.com/
Fedora: http://fedora.redhat.com/
SuSE/Novell: http://www.suse.com/
Debian: http://www.debian.org/
Red Hat Enterprise Linux is a Enterprise targeted Operating
System. It based on mature Open Source technology and available
at a cost with one year Red Hat Network subscription for upgrade
and support contract.
Refer https://www.howtogeek.com/191207/10-of-the-most-popular-linux-distributions-
compared/ for comparison of various linux distros.
Introduction to Linux

UNIX Structure
Introduction to Linux

UNIX Structure
Kernel − The kernel is the heart of the operating system. It interacts
with the hardware and most of the tasks like memory management, task
scheduling and file management.
Shell − The shell is the utility that processes your requests. When you
type in a command at your terminal, the shell interprets the command
and calls the program that you want. C Shell, Bourne Shell and Korn
Shell are the most famous shells
Commands and Utilities − There are various commands and utilities
which you can make use of in your day to day activities. cp, mv, cat and
grep, etc. are few examples of commands and utilities. There are over
250 standard commands plus numerous others provided through 3rd
party software. All the commands come along with various options.
Files and Directories − All the data of Unix is organized into files. All
files are then organized into directories. These directories are further
organized into a tree-like structure called the filesystem.
Introduction to Linux

UNIX File System


Introduction to Linux

File System

The Unix file system looks like an inverted tree


structure.
You start with the root directory, denoted by /, at
the top and work down through sub-directories
underneath it.
Introduction to Linux

File System
Each node is either a file or a directory of files,
where the latter can contain other files and
directories.
You specify a file or directory by its path name,
either the full, or absolute path name or the one
relative to a location.
The full path name starts with the root, /, and
follows the branches of the file system, each
separated by /, until you reach the desired file, e.g.:
/home/vijay/source/xntp
Introduction to Linux

File System

A relative path name specifies the path relative to


another, usually the current working directory that
you are at. Two special directories :
. the current directory
.. the parent of the current directory
So if I'm at /home/vishal and wish to specify the
path above in a relative fashion I could use:
../vijay/source/xntp
This indicates that I should f i r s t g o u p o n e
directory level, then come down through the vijay
directory, followed by the source directory and
then to xntp.
Introduction to Linux

Structure of Standard Directories


in Unix/Linux
/ The ancestor of all directories on the system; all
other directories are subdirectories o f t h i s
d i r e c t o r y, e i t h e r d i r e c t l y o r t h r o u g h o t h e r
subdirectories.
/bin Essential tools and other programs (or
binaries).
/dev Files representing the system's various
hardware devices. For example, you use the file
`/dev/cdrom' to access the CD−ROM drive.
/etc Miscellaneous system configuration files,
startup files, etc.
Introduction to Linux
Structure of Standard Directories
in Unix/Linux
/home The home directories for all of the system's
users.
/lib Essential system library files used by tools in
`/bin'.
/proc Files that give information about current
system processes.
/root The superuser's home directory, whose
username is root. (In the past, the home directory
for the superuser was simply `/'; later, `/root' was
adopted for this purpose to reduce clutter in `/'.)
Introduction to Linux
Structure of Standard Directories
in Unix/Linux
/sbin Essential system administrator tools, or
system binaries.
/tmp Temporary files.
/usr Subdirectories with files related to user tools
and applications.
Introduction to Linux

Directories, Files and Inodes


Every directory and file is listed in its parent
directory.
In the case of the root directory, that parent is itself.
A directory is a file that contains a table listing the
files contained within it, giving file names to the
inode numbers in the list.
The information about all the files and directories is
maintained in INODE TABLE
An Inode (Index Nodes) is an entry in the table
containing information about a file (metadata)
including file permissions, UID, GID, size, time
stamp, pointers to files data blocks on the disk etc.
Introduction to Linux
Users, Groups and Access
Permissions
In UNIX/LINUX, there is a concept of user and an
associated group

The system determines whether or not a user or


group can access a file or program based on the
permissions assigned to them.

Apart from all the users, there is a special user


called Super User or the root which has permission
to access any file and directory
Introduction to Linux

Access Permissions
There are three permissions for any file, directory
or application program.

The following lists the symbols used to denote


each, along with a brief description:

r — Indicates that a given category of user can


read a file.

w — Indicates that a given category of user can


write to a file.

x — Indicates that a given category of user can


execute the file.
Introduction to Linux

Access Permissions
Each of the three permissions are assigned to three
defined categories of users.
The categories are:

owner — The owner of the file or application.


group — The group that owns the file or application.
others — All users with access to the system.
Introduction to Linux

Access Permissions
One can easily view the permissions for a file by
invoking a long format listing using the command
ls -l.

For instance, if the user juan creates an executable


file named test, the output of the command ls -l
test would look like this:

-rwxrwxr-x 1 juan student 0 Sep 26 12:25 test


Introduction to Linux

Access Permissions
The permissions for this file are listed at the start
of the line, starting with rwx.

This first set of symbols define owner access.

The next set of rwx symbols define group access

The last set of symbols defining access permitted


for all other users.
Introduction to Linux

Access Permissions
This listing indicates that the file is readable,
writable, and executable by the user who owns the
file (user juan) as well as the group owning the file
(which is a group named student).

The file is also world-readable and world-


executable, but not world-writable.
Introduction to Linux

Listing the Content of a Directory

ls is used to list the contents of a directory.

If the command ls is written with parameter –l then


the command lists contents of the working
directory with details. Example:

$ ls –l
Introduction to Linux

Moving in Directories
cd try_it
Changes the directory to try_it
pwd
Prints present working directory
(e.g./home/smith/try_it)
cd .. Move to superior directory
pwd : Prints /home/smith
cd /home The absolute path
pwd : Prints /home
cd: The system is returned to the user home directory
pwd : Prints /home/smith
Introduction to Linux

Make Directory

The command mkdir my_dir

makes new directory my_dir (the path is given


relative) as a subdirectory of the current directory.
Introduction to Linux

Remove Directory

The command rmdir your_dir


removes directory your_dir if it is empty.
Introduction to Linux

Copy File

The command cp file_1 file_2

copies file_1 to file_2. The both files must be in the


same working directory. If they are in different
directories, the path must be given.
Introduction to Linux

Rename and/or Move the File

The command mv file_1 file_2

moves file_1 to file_2

The both files must be in the same working


directory.

If they are in different directories, the path must be


given.

The file_1 is removed from the disk.


Introduction to Linux

Remove File
The command rm file_a
removes the file_a from the system
If you use wildcard. For example
rm h*c
you will remove all files beginning with h and
ending with c which are in working directory.
If you write
rm *
you will erase all files from your working directory.
Introduction to Linux

Access Permission of File/Directory


The ownership of the file or directory can be
changed using the command
chown <owner> <file/directory name>
The group of the file or directory can be changed
using the command
chgrp <group> <file/directory name>
The permissions of the file can be changed using
chmod command
chmod -R ### <filename or directory>
-R is optional and when used with directories will
traverse all the sub-directories of the target
directory changing ALL the permissions to ###.
Introduction to Linux
Access Permission of
File/Directory
The #'s can be:
0 = Nothing
1 = Execute
2 = Write
3 = Execute & Write (2 + 1)
4 = Read
5 = Execute & Read (4 + 1)
6 = Read & Write (4 + 2)
7 = Execute & Read & Write (4 + 2 + 1)
Introduction to Linux

Assignment
Login as guest (password is guest)
Find the present Directory
Write the root directory structure
Write a few commands available in /bin and /sbin directory
Find the guest directory
Write the permissions of guest directory
Create a new Directory test in guest directory
Copy the file /etc/resolv.conf in test directory
Rename the test directory to testing
Delete the testing directory
Change the permissions of guest directory to 700
Change the permissions of /tmp directory to 700
Linux Installation

LINUX INSTALLATION
(Ubuntu)
Vijay Ukani
Linux Installation

Download LINUX

Ubuntu 18.04 LTS


Ubuntu 18.04 LTS only comes in a 64-bit edition
Download ISO from
https://www.ubuntu.com/download/desktop
Linux Installation

Create bootable Disk


Burn the downloaded ISO image into the USB/DVD or
flash drive to boot the computer from that drive
change the boot sequence so that system boots using
the bootable CD/DVD or flash drive.
Linux Installation

Boot from Flash drive


Linux Installation

Boot from Flash drive


Linux Installation

Choose your Keyboard layout


Linux Installation
Preparing to Install Ubuntu and other Software
Linux Installation

Installation Type
• Erase Disk and Install Ubuntu
• Encrypt the new Ubuntu installation for
security
• Use LVM with the new Ubuntu installation
• Something Else
– /boot 2 GB (ext4 files system)
– /home 18 GB (ext4 file system)
–/ 12 GB (ext4 file system)
– /var 6 GB (ext4 file system)
– Swap 4 GB
Linux Installation

Installation Type
Linux Installation

Installation Type
Linux Installation

Installation Type
Linux Installation

Installation Type
Linux Installation

Installation Type
Linux Installation

Installation Type
Linux Installation

Installation Type
Linux Installation

Installation Type
Linux Installation

Time Zone
Linux Installation

User Credentials
Linux Installation

Continue Install
Linux Installation

Restart
Linux Installation

Login and Use


Linux Installation

Dual Boot Windows+Linux Install


• Create bootable DVD/CD/Flash drive for
Windows and Ubuntu
• First install Windows
• Then install Ubuntu
Linux Installation

Install Windows
Linux Installation

Install Windows
Linux Installation

Install Windows
Linux Installation

Install Windows
Linux Installation

Install Windows
Linux Installation

Install Windows
Linux Installation

Create Partition
Linux Installation

Create Partition
Linux Installation

Select Partition to Install


Linux Installation

Install Windows
Linux Installation

Windows Installed
Linux Installation

Boot from Ubuntu Flash


Linux Installation

Install Ubuntu
Linux Installation

Select Install Type


Linux Installation

Select Install Type


Linux Installation

Select Partition
Linux Installation

Confirm Partition
Linux Installation

User Creation
Linux Installation

Restart and Select


Linux Installation

References
• https://www.linuxtechi.com/ubuntu-18-04-
lts-desktop-installation-guide-screenshots/
• https://opensource.com/article/18/5/dual-
boot-linux
Linux Commands

LINUX COMMANDS
Linux Commands

UNIX Commands
A command is a program which interacts with the
kernel to provide the environment and perform the
functions called for by the user.

A command can be: a built-in shell command; an


executable shell file, known as a shell script; or a
source compiled, object code file.

The shell is a command line interpreter. The user


interacts with the kernel through the shell. You can
write ASCII (text) scripts to be acted upon by a
shell.
Linux Commands

UNIX Shell
The shell sits between you and the operating
system, acting as a command interpreter.

It reads your terminal input and translates the


commands into actions taken by the system. The
shell is analogous to command.com in DOS.

When you log into the system you are given a


default shell.

When the shell starts up it reads its startup files


and may set environment variables, command
search paths, and command aliases, and executes
any commands specified in these files.
Linux Commands

UNIX Shell
The original shell was the Bourne shell, sh.
Every Unix platform will either have the Bourne shell,
or a Bourne compatible shell available.
The default prompt for the Bourne shell is $ (or #,
for the root user).
Another popular shell is C Shell. The default prompt
for the C shell is %.
Linux Commands

UNIX Shell
Numerous other shells are available from the
network. Almost all of them are based on either sh
or csh with extensions to provide job control to sh,
allow in-line editing of commands, page through
previously executed commands, provide command
name completion and custom prompt, etc.
Some of the more well known of these may be on
your favorite Unix system: the Korn shell, ksh, by
David Korn and the Bourne Again SHell, bash, from
the Free Software Foundations GNU project, both
based on sh, the T-C shell, tcsh, and the extended C
shell, cshe, both based on csh.
Linux Commands

Shell Programming
You can write shell programs by creating scripts
containing a series of shell commands.

The first line of the script should start with #! which


indicates to the kernel that the script is directly
executable.

You immediately follow this with the name of the


shell, or program (spaces are allowed), to execute,
using the full path name. So to set up a Bourne
shell script the first line would be: #! /bin/sh
Linux Commands

Shell Programming
The first line is followed by commands
Within the scripts # indicates a comment from that
point until the end of the line, with #! being a
special case if found as the first characters of the
file.
#!/bin/bash
cd /tmp
mkdir t
Yo u a l s o n e e d t o s p e c i f y t h a t t h e s c r i p t i s
executable by setting the proper bits on the file
with chmod, e.g.:
$ chmod +x shell_script
Linux Commands

LINUX COMMANDS
File Management and Viewing
Filesystem Mangement
Help, Job and Process Management
Network Management
System Management
User Management
Printing and Programming
Document Preparation
Miscellaneous
Linux Commands

Command Structure
Command <Options> <Arguments>
Multiple commands separated by ; can be executed
one after the other
Linux Commands

Help Facilities for Commands

To understand the working of the command and


possible options use (man command)
Using the GNU Info System (info, info command)
Listing a Description of a Program (whatis command)
Many tools have a long−style option, `−−help', that
outputs usage information about the tool, including
the options and arguments the tool takes. Ex:
whoami --help
Linux Commands

Pipes
An important early development in Unix was the
invention of "pipes," a way to pass the output of
one tool to the input of another.
eg. $ who | wc −l
By combining these two tools, giving the wc
command the output of who, you can build a new
command to list the number of users currently on
the system
Linux Commands

Linux File Management and Viewing

cd Change the current directory. With no arguments


" c d " c h a n g e s t o t h e u s e r s h o m e d i re c t o r y. ( c d
<directory path>)
chmod Change the file permissions.
Ex: chmod 751 myfile : change the file permissions to
rwx for owner, rx for group and x for others
Ex: chmod go=+r myfile : Add read permission for the
group and others (character meanings u-user, g-group,
o-other, + add permission,-remove,r-read,w-write,x-
exe)

Ex: chmod +s myfile - Setuid bit on the file which


allows the program to run with user or group privileges
of the file. #the file runs with previledges of owner rather then
Linux Commands

Linux File Management and Viewing


There are three such special permissions within Linux. They are:
setuid — used only for applications, this permission indicates that
the application is to run as the owner of the file and not as the user
executing the application. It is indicated by the character s in place
of the x in the owner category. If the owner of the file does not
have execute permissions, the S is capitalized to reflect this fact.
setgid — used primarily for applications, this permission indicates
that the application is to run as the group owning the file and not
as the group of the user executing the application. The setgid
permission is indicated by the character s in place of the x in the
group category. If the group owner of the file or directory does not
have execute permissions, the S is capitalized to reflect this fact.
sticky bit — used primarily on directories, this bit dictates that a
file created in the directory can be removed only by the user that
created the file. It is indicated by the character t in place of the x in
the everyone category. If the everyone category does not have
execute permissions, the T is capitalized to reflect this fact.
Linux Commands

Linux File Management and Viewing

chown Change owner.


Ex: chown <owner1> <filename> : Change
ownership of a file to owner1.
chgrp Change group.
Ex: chgrp <group1> <filename> : Change group
of a file to group1.
cp Copy a file from one location to another.
Ex: cp file1 file2 : Copy file1 to file2
Ex: cp –R dir1 dir2 : Copy dir1 to dir2
md5sum Prints the MD5 Checksum
Linux Commands

Linux File Management and Viewing

ls List contents of a directory.


Ex: ls, ls –l , ls –al, ls –ld, ls –R
(-rwxrwxr-x 1 vijay vijay 0 Jul 26 12:25 test.txt )
|more will list page wise
mkdir Make a directory.
Ex: mkdir <directory name> : Makes a directory
Ex mkdir –p /www/iiit/vadodara/ac/in will create
all the directories starting from www.
mv Move or rename a file or directory.
Ex: mv <source> <destination>
Linux Commands

Linux File Management and Viewing

find Find files (find <start directory> -name <file


name> -print)

Ex: find /home –name readme -print


(Search for readme starting at home and output full path.)
“/home" = Search starting at the home directory and proceed
through all its subdirectories
"-name readme" = Search for a file named readme
"-print" = Output the full path to that file

locate File locating program that uses the slocate


database.
Ex: updatedb to update the database,
locate <file/directory> to find file/directory
Linux Commands

Linux File Management and Viewing

pwd Print or list the present working directory


with full path.
r m D e l e t e f i l e s ( Re m o v e f i l e s ) . ( rm – r f
<directory/file>)
rmdir Remove a directory. The directory must be
empty. (rmdir <directory>)
touch Change file timestamps to the current
time. Make the file if it doesn't exist. (touch
<filename>)
whereis Locate the binary and man page files for
a command. (whereis <program/command>)
which Show full path of commands where given
commands reside. (which <command>)
Linux Commands

Linux File Management and Viewing

File viewing and editing


emacs Full screen editor.
pico Simple text editor.
vi Editor with a command mode and text mode.
Starts in command mode.
gedit GUI Text Editor
tail Look at the last 10 lines of a file.
Ex: tail -100 <filename>
head Look at the first 10 lines of a file. (head
<filename>)
Linux Commands

Linux File Management and Viewing

File compression, backing up and restoring


compress Compress data.
uncompress Expand data.
cpio Can store files on tapes. to/from archives.
gzip - zip a file to a gz file.
gunzip - unzip a gz file.
tar Archives files and directories. Can store files
and directories on tapes.
Ex: tar -zcvf <destination> <files/directories> -
Archive copy groups of files. tar –zxvf
<compressed file> to uncompress
zip – Compresses a file to a .zip file.
unzip – Uncompresses a file with .zip extension.
Linux Commands

Linux File Management and Viewing

cat View a file


Ex: cat filename
cmp Compare two files.
cut Remove sections from each line of files.
diff Show the differences between files.
Ex: diff file1 file2 : Find differences between file1
& file2.
echo Display a line of text.
Linux Commands

Linux File Management and Viewing

grep List all files with the specified expression.


(grep pattern <filename/directorypath>)
Ex: ls –l |grep Do : List all lines with a Do in them.
Ex: grep " R " : Search for R with a space on each
side
sleep Delay for a specified amount of time.
sort Sort a file alphabetically.
uniq Remove duplicate lines from a sorted file.
wc Count lines, words, characters in a file. (wc
–c/w/l <filename>).
Linux Commands

Linux Filesystem Management

badblocks Used to search a disk or partition for


badblocks. (badblocks device) (badblocks hda)

df Shows the disk free space on one or more


filesystems. (df –k, df -h)

du Shows how much disk space a directory and all


its files contain. (du <directory>, du –sk
<directory>, du –sh <directory>)

fsck Filesystem check. Must not be run on a


mounted file system. (fsck <filesystem>)
Linux Commands

Linux Filesystem Management

sync Synchronize data on disk with memory.


`sync' writes any data buffered in memory out to
disk.

mount Used to mount a filesystem. Complement


is umount. (mount <filesystem>, mount –a)

umount Unmounts a filesystem. Complement is


mount. (umount <filesystem>)
Linux Commands

Network Management Commands

dnsdomainname Show the systems DNS domain


name

hostname Used to show or set the name of your


machine for networking

nisdomainname Show or set systems NIS/YP


domain name

ypdomainname Show or set the system's NIS/YP


domain name
Linux Commands

Network Management Commands


arp This program lets the user read or modify their arp cache.
dig Send domain name query packets to name servers for
debugging or testing.
finger Display information about the system users. Ex: finger
Deepak
ftp File transfer program. (ftp <remote system name/ip)
ifconfig Configure a network interface. Ex:
ifconfig eth0 address 172.31.2.2 netmask 255.255.0.0
ifdown Shutdown a network interface. Ex: ifdown eth0
ifup Brings a network interface up. Ex: ifup eth0
Linux Commands

Network Management Commands

netconf A GUI interactive program to let you


configure a network on Redhat systems.
netconfig Another GUI step by step network
configuration program.
netstat Displays information about the systems
network connections, including port connections,
routing tables, and more. The command "netstar -r"
will display the routing table. (netsat –rn)
nslookup Used to query DNS servers for
information about hosts.
Linux Commands

Network Management Commands

ping Send ICMP ECHO_REQUEST packets to


network hosts. (ping <remote-host-name/ip)

route Show or manipulate the IP routing table.


(route, route add, route del)

showmount Show mount information for an NFS


server.

ssh Secure Login (ssh <remote system


name/ip>)
Linux Commands

Network Management Commands

tcpdump Dump traffic on a network. Prints out


h e a d e r s o f p a c ke t s t h a t m a t c h t h e b o o l e a n
expression. (tcpdump eth0)

telnet User interface to the TELNET protocol,


setting up a remote console session. (telnet
<remote system name/ip>)

traceroute Print the route that packets take to the


specified network host. (traceroute <remote
system name/ip>)
Linux Commands

Network Management Commands

Communications commands (includes mail)

elm Electronic mail.

pine Program for internet news and e-mail, Can


send documents, graphics, local & remote
messages.

talk Lets two parties talk simultaneously.

mail To send a mail


Linux Commands

System Management Commands

Runtime level management


exit Terminates the shell.
halt Stop the system.
init Process control initialization. (init 3)
logout Log the user off the system.
poweroff Brings the system down.
reboot Reboot the system.
runlevel List the current and previous runlevel.
Linux Commands

System Management Commands

shutdown If your system has many users, use


the command shutdown -h +time ‘<message>`,
where time is the time in minutes until the
system is halted, and message is a short
explanation of why the system is shutting down.
Ex: # shutdown -h +10 'We will install a new
disk. System should be back on-line in three
hours.‘
Linux Commands

System Management Commands

passwd Set a user's pass word. (passwd, passwd


<username>)

quota Display users' limits and current disk


usage. (quota, quota <username>)

quotaoff Turns filesystem quotas off.

quotaon Turns filesystem quotas on.

quotacheck Used to check a filesystem for


usage, and update the quota.user file.

edquota Used to edit user or group quotas.


(edquota <username>)
Linux Commands

System Management Commands


su Single user login. (su -)
groupadd Creates a new group
useradd Create a new user or update default new
user information. (useradd –g <group> -s <shell> -c
<comment> –d <home directory> <username>
userdel Delete a user account and related files.
(userdel <user name>)
usermod Modify a user account.
users Print the user names of users currently logged
in.
wall Send a message to everybody's terminal. (wall
“text message”)
who Display the users logged in.
whoami Print effective user id.
Linux Commands

Group Management Commands


Groups let you create categories of users with pre-
set permissions. Instead of managing permissions for
each user account, you can simply add a user to a
group to grant the appropriate permissions.
Two types of groups
Primary Group (-g) - The primary group is set to the
logged-in user. User can only be in one primary group at a
time. A primary group with the same name as the user is
created, and any files created by the user are included in
that group.
Secondary Group (-G) - A user can belong to any number
of secondary groups.
Linux Commands

Group Management Commands


How to Create a User Group
sudo groupadd new_group

How to Add User to Group


sudo adduser user_name new_group
sudo useradd –G new_group user_name #Can be used to create
and add new user to group
sudo usermod –a –G group_name user_name
s u d o u s e rm o d – a – G n e w _ g ro u p , n e w _ g ro u p 2 , n e w _ g ro u p 3
user_name #Add user to multi group
sudo usermod –g new_group user_name #Change primary group

How to Remove a User From a Group


sudo gpasswd –d user_name new_group
Linux Commands

System Management Commands

System Time

cal Calendar. (cal, cal 2005)

date Print or set the system date and time. (date,


date MMDDhhmm[[CC]YY][.ss])

hwclock Set or read the hardware CMOS clock.

uptime Reports how long the system has been


running.
Linux Commands

Linux Job & Process Management


● ps Get the status of one or more processes.
PPID-parent process ID ; PID-process ID
E g : p s a x | m o re t o s e e a l l p ro c e s s e s i n c l u d i n g
daemons
Eg : ps –ef | grep <process>
pstree Display the tree of running processes.
pgrep looks through the currently running processes
and lists the process IDs which matches the selection
criteria to stdout.All the criteria have to match.
top The top program provides a dynamic real-time
view of a running system. It can display system
summary information as well as a list of tasks
currently being managed by the Linux kernel
Linux Commands

Linux Job & Process Management

Linux Process Management

bg Starts a suspended process in the background

fg Starts a suspended process in the foreground

kill Ex: "kill 34" - Effect: Kill or stop the process


with the process ID number 34.

killall Kill processes by name. Can check for and


restart processes.

pid Find the process ID of a running program


Linux File System
&
Application
Software
File System

File System
Each OS needs to store data/files on secondary storage like HDD
as it is not possible to store everything on volatile storage like
RAM as it is costly and can not maintain the contents after being
powered down.
A filesystem is designed to manage space for non-volatile storage
of data.
File system is a method for storing and organizing computer files
and the data they contain to make it easy to find and access
them.
Most file systems make use of an underlying data storage device
such as Hard Disks that offers access to an array of fixed-size
blocks which is the smallest logical amount of disk space that can
be allocated to hold a file.
File System

File System
Other important features of file systems:
A namespace—that is, a naming and organizational
methodology includes length and set characters that can
be used
A metadata structure - data structure to support directory
hierarchy, memory block, name of file, size, timestamp.
An API - provides access to system function calls which
manipulate filesystem objects like files and directories,
creating, deleting, and moving files.
Security model - access rights to files/directories
Software required to implement these functions
File System

File System

1. This virtual filesystem provides a single set of commands


for the kernel, and developers, to access all types of
filesystems. It supports specific device driver required to
interface to the various types of filesystems.
2. The device driver interprets the standard set of filesystem
commands to ones specific to the type of filesystem on the
partition or logical volume.
File System

Directory Structure
File System

Directory Structure
Directory Description
/ (root fs) The root filesystem is the top-level directory of the filesystem.
/bin The /bin directory contains user executable files.
/boot Contains the static bootloader and kernel executable and
configuration files required to boot
/dev device files for every hardware device.
/etc local system configuration files for the host computer
/home Each user has a subdirectory in /home.
/lib shared library files that are required to boot the system.
/media place to mount external removable media devices such as
USB thumb drives that may be connected to the host.
/mnt A temporary mountpoint for regular filesystems
/opt Optional files such as vendor supplied application programs
should be located here
/root not the root (/) filesystem but home directory for root user
/var Variable data files are stored here
File System

Types of File System


File system types can be classified into disk file
systems, network file systems and flash file systems.
A disk file system is a file system designed for the
storage of files on a data storage device, most
commonly used disk drives e.g. FAT, NTFS, etx2, ext3,
ext4 etc.
A network file system is a file system that acts as a
client for a remote file access protocol, providing
access to files on a server e.g. NFS, SMB etc.
A flash file system is a file system designed for storing
files on flash memory devices.
File System

File System and OS


Operating systems provide a file system, as a file
system is an integral part of any modern operating
system.
Windows Operating system supports FAT and NTFS
File Systems
Linux popularly supports ext2, ext3 and ext4 File
Systems
Other flavors of Operating Systems may support
other File Systems like UFS in many UNIX Operating
Systems and HFS in MAC OS X.
All Operating Systems provide a user interface like
Command Line (CLI) or File Browser to access and
manage File System information.
DOS/Windows File System

FAT
The File Allocation Table (FAT) file system was
initially developed for DOS Operating System and
was later used and supported by all versions of
Microsoft Windows.
All the latest versions of Windows still support FAT
file system although it may not be popular.
FAT had various versions like FAT12, FAT16 and
FAT32. Numbers indicate the number of address bits
in the table: 12, 16 and 32.
FAT16 supports HDD from 16MB to 2GB
FAT32 supports larger HDD upto 32GB
Windows File System

NTFS
NTFS or the NT File System was introduced with the
Windows NT operating system.
NTFS allows ACL-based permission control which was
the most important feature missing in FAT File System.
L a t e r v e r s i o n s o f Wi n d o w s l i ke Wi n d o w s 2 0 0 0 ,
Windows XP, Windows Server 2003, Windows Server
2008, and Windows Vista also use NTFS.
NTFS has several improvements over FAT such as
security access control lists (ACL) and file system
journaling.
Supports large files 216 bytes with HDD upto 256TB
Windows File System

Journaling
A journaling file system is a file system that logs
changes to a journal (usually a circular log in a
dedicated area) before committing them to the main
file system. Such file systems are less likely to become
corrupted in the event of power failure or system crash.
Linux File System

File System in Linux


Linux supports many different file systems, but
common choices for the system disk include the ext
family (such as ext2, ext3 and ext4), XFS, JFS and
ReiserFS.
Ext stands for “Extended file system”, and was the
first created specifically for Linux. It’s had four major
revisions. “Ext” is the first version of the file system,
introduced in 1992. It was a major upgrade from the
Minix file system used at the time, but lacks
important features. Many Linux distributions no
longer support Ext.
Linux File System

File System in Linux


Ext2 is not a journaling file system. When introduced,
it was the first file system to support extended file
attributes and 2 TB drives.
Ext3 is basically just Ext2 with journaling. Ext3 was
designed to be backwards compatible with Ext2,
allowing partitions to be converted between Ext2 and
Ext3 without any formatting required.
Ext4 was also designed to be backwards compatible.
It includes newer features that reduce file
fragmentation, allows for larger volumes and files,
and uses delayed allocation to improve flash memory
life.
Application Software

Application Software
Application software is a software tool that functions
with the purpose of supporting or improving the user's
work.
Typical examples of software applications are word
processors, spreadsheets, media players, database
applications etc.
Application Software are usually available for a
particular Operating System and hardware platform for
which it has been compiled.
Application Software may be freely downloadable or
paid. Paid software would have licensing policy which
may be perpetual or time bound and may also be
restricted to certain number of users.
Application Software

Popular Application Software


Scientific Computing: Nastran, Fluent, Matlab,MSI,
Sas, Charmm
Database Applications: Oracle, MySQL, PgSQL,
MS Access
Compilers: C, C++, Java, Visual Studio, Fortran,
Pascal,
Graphics: TechPlot, Origin
CAD/CAM: Autocad, Ideas
Simulation: Arena, Gams, Cplex
Office : Microsoft Office, Star Office
Application Software Interface

API
An application programming interface (API) is a set
of routines, data structures, object classes and/or
protocols provided by libraries and/or operating
system services in order to support the building of
applications.
An API may be Language-dependent or Language-
independent.
Companies make their APIs freely available. For
example, Microsoft makes the Microsoft Windows API
and the Micrososft Windows Software Development
Kit (SDK), public so that software can be written for
their platform.
Application Software

Client-Server Applications
The client-server software
architecture model distinguishes
client systems from server systems,
which communicate over a computer
network.
A client-server application is a
distributed system comprising of
both client and server software. The
client software may be a browser.
A client software process may
initiate a communication session,
while the server waits for requests
from any client.
Application Software

Peer-to-Peer Applications
There is no notion of clients or servers but only
equal peer nodes that simultaneously function as
both “clients” and “servers”
File sharing (containing audio, video, data) is the
most common application of P2P networks
Some applications like Torrent may start as Client-
server application (for searching the data) and
then change over to peer-to-peer applications
(downloaded the content from another peer).
The advantage is that multiple nodes contribute
their resources and the architecture is robust as
the content may be available on multiple nodes so
that the failure of a node will not affect the system.
Application Software

References

https://opensource.com/life/16/10/introduction-
linux-filesystems
Linux System Administration

Network and Firewall


Management

Dr Vijay Ukani
Desktop Configuration

Network configuration files


The graphical tools edit a specific set of network
configuration files, using a couple of basic commands.
Exact name and configuration of these files is dependent
on the version of Linux
However, few network configurations files are common
across all Linux distros
/etc/hosts - The /etc/hosts file always contains the localhost IP
address, 127.0.0.1. Sometimes contains addresses of
additional hosts, which can be contacted without using an
external naming service such as DNS
/etc/resolve.conf - configures access to a DNS server
/etc/nsswitch.conf - defines the order in which to contact
different name services
Linux System Administration

Network configuration commands


ip Command:
The graphical tools are front-ends to ip command to display
and configure the kernel's networking configuration.
The ip command is used for assigning IP addresses to
interfaces, for setting up routes to the Internet and to other
networks, for displaying TCP/IP configurations.
ip link - Show list of interfaces
ip link set dev enp4s0 down - Turnoff wired interface
ip addr show - Show IP addresses of all interfaces
ip route show - Show routing table
sudo ip route add default via 10.1.19.27
ip addr add - Assign static IP to selected interface
sudo ip addr add 10.1.32.5/255.255.0.0 dev enp4s0
Linux System Administration

Network configuration commands


ifconfig Command:
ifconfig is a modern and legacy command to configure
network on Linux.
ifconfig - showing the current IP configuration
ifconfig -a - show list of network interfaces even if down
ifconfig enp4s0 10.1.32.4 netmask 255.255.0.0
Linux System Administration

Network configuration commands


 All changes made using ip or ifconfig commands are
temporary i.e. these changes will not survive a reboot
 To c o n f i g u r e a i n t e r f a c e p e r m a n e n t l y e d i t ,
\etc\network\interfaces file
auto wlo1
iface wlo1 inet dhcp

auto enp4s0
iface enp4s0 inet static
address 10.1.32.5
gateway 10.1.19.27
netmask 255.255.0.0
network 10.1.0.0
broadcast 10.1.255.255
Linux System Administration

Network configuration commands


netstat Command:
Netstat command is used display network statitics
netstat - Active connections
netstat -r - show routing table

host Command
host - display information on hosts or domains

whois Command:
Query specific domain name information
eg. whois google.com
Access Control List (ACL)
• ACLs are widely used in computer networking and in network
security for mitigating network attacks and controlling network traffic.
• ACLs are used to define and control classes of traffic on networking
devices based on various parameters of layer 2,3,4, and 7
• Virtually any type of traffic can be defined explicitly by using an
appropriately Numbered ACL. For example, in the past, the Ethernet
type field of an Ethernet frame header was used to define certain
types of traffic. An Ethernet type of 0x8035 indicated a reverse
address resolution protocol (RARP) frame. Numbered ACLs with a
range of 200-299 were used to control traffic according to Ethernet
type.
• ACLs based on MAC address - 700-799
• Standard IP ACL – 1-99 and 1300-1999
• Extended IP ACL – 100-199 and 2000-2699
ACL Topology
Primary reasons
• Limit network traffic and increase
network performance.
• Provide traffic flow control. ACLs can
restrict the delivery of routing updates.
• Provide a basic level of security for
network access.
• Decide which types of traffic are
forwarded or blocked at the router
interfaces.
• Like: e-mail traffic to be routed, but
block all Telnet traffic.
An ACL is made up of
statements that define whether
packets are accepted or
rejected at inbound and
outbound interfaces.
inbound and outbound
interfaces

S 0/0 OUT In S 0/1

F0/0 In OUT F0/0


Standard ACLs Example
Named IP ACLs
Router(config)# ip access-list extended NUACL
Router(config-ext-nacl)# deny ip any 200.1.2.10
0.0.0.1
Router(config-ext-nacl)# permit tcp any host
Standard 200.1.1.11 eq 80
Router(config-ext-nacl)# permit tcp any host
200.1.1.10 eq 25
Router(config-ext-nacl)# permit tcp any eq 25
host 200.1.1.10 any established
Router(config-ext-nacl)# permit tcp any
200.1.2.0 0.0.0.255 established
Router(config-ext-nacl)# permit udp any eq 53
200.1.2.0 0.0.0.255
Router(config-ext-nacl)# deny ip any any
Router(config-ext-nacl)# interface ethernet 1
Router(config-if)# ip access-group NUACL in
Router(config-if)# exit

Extended
Applying Standard ACLs
Use a standard ACL to block all traffic from 172.16.4.0/24 to 172.16.3.0
network, but allow all other traffic.

r1

r1(config)# access-list 1 deny 172.16.4.0 0.0.0.255


r1(config)# access-list 1 permit any
r1(config)# interface ethernet 0
r1(config-if)# ip access-group 1 out
Applying Extended ACLs
Use an extended ACL to block all FTP traffic from 172.16.4.0/24 network, but allow
all other traffic.

r1

access-list 101 deny tcp 172.16.4.0 0.0.0.255 172.16.3.0 0.0.0.255 eq 21


access-list 101 deny tcp 172.16.4.0 0.0.0.255 172.16.3.0 0.0.0.255 eq 20
access-list 101 permit ip any any
interface ethernet 1
ip access-group 101 in
Linux System Administration

Configure Linux Firewall


firewalld is the default front-end controller for iptables on
most Linux distro. The firewalld front-end has two main
advantages over raw iptables −
Uses easy-to-configure and implement zones abstracting
chains and rules.
Rulesets are dynamic, meaning stateful connections are
uninterrupted when the settings are changed and/or
modified.
Linux System Administration

The Uncomplicated Firewall


Ensure firewalld is both started and enabled
systemctl status firewalld
systemctl status ufw - for ubuntu
systemctl start firewalld && systemctl enable firewalld - To
start and enable ufw
sudo ufw enable
To assure that firewall is operational
firewall-cmd --state
sudo ufw status
Linux System Administration

The Uncomplicated Firewall


Default setting of ufw is in /etc/default/ufw file
To set default policies
sudo ufw default deny incoming
sudo ufw default allow outgoing
Allow incoming ssh
sudo ufw allow ssh
sudo ufw allow 22
Allow http
sudo ufw allow http or sudo ufw allow 80
sudo ufw allow https or sudo ufw allow 443
Allow FTP
sudo ufw allow ftp or sudo ufw allow 21/tcp
Linux System Administration

The Uncomplicated Firewall


Allow specific port range
sudo ufw allow 6000:6007/tcp
sudo ufw allow 6000:6007/udp
Specific IP Addresses
sudo ufw allow from 15.15.15.51
sudo ufw allow from 15.15.15.51 to any port 22
Subnets
sudo ufw allow from 15.15.15.0/24
sudo ufw allow from 15.15.15.0/24 to any port 22
Connections to a Specific Network Interface
sudo ufw allow in on eth0 to any port 80
Linux System Administration

The Uncomplicated Firewall


UFW is configured to deny all incoming connections by default
It simplifies the process of creating a secure firewall policy by requiring
you to create rules that explicitly allow specific ports and IP addresses
through
If you change your default incoming policy to allow (which isn’t
recommended), you would need to create deny rules for any services
or IP addresses
To write deny rules, just use the commands described above,
replacing allow with deny.
Deny specific port range
sudo ufw deny 6000:6007/tcp
sudo ufw deny 6000:6007/udp
Specific IP Addresses
sudo ufw deny from 15.15.15.51
Linux System Administration

The Uncomplicated Firewall


Deleting Rules
vijay@vijay-HP:~$ sudo ufw status numbered
Status: active
To Action From
-- ------ ----
[ 1] 22/tcp ALLOW IN Anywhere
[ 2] 80/tcp ALLOW IN Anywhere
[ 3] 443/tcp ALLOW IN Anywhere
[ 4] 22/tcp (v6) ALLOW IN Anywhere (v6)
[ 5] 80/tcp (v6) ALLOW IN Anywhere (v6)

sudo ufw delete 2


sudo ufw delete allow 80
Linux System Administration

The Uncomplicated Firewall


Checking UFW Status and Rules
sudo ufw status verbose
Disabling or Resetting UFW
sudo ufw disable
sudo ufw reset
Web Server Setup

Service Configuration
(http, squid, ftp, ssh, cups, smtp, nfs,
nis, samba)
Web Server Setup

Linux Services

A service is a program that runs in the background outside


the interactive control of system users as they lack an
interface.
This provides even more security, because some of these
services are crucial for the operation of the operating system.
The services are also known as daemons.
Sometimes the name of these services or daemons ends
with the letter d. For example, sshd is the name of the
service that handles SSH.
Web Server Setup

List all Services


Sometimes while trying to access a service, it might fail
probably either because the service is not enabled or it is not
running.
To list all services
sudo systemctl list-unit-files --type service --all
It displays all the services that are on the system with defined
status
Enabled services are currently running. They usually have no problems.
Disabled services are not active but can be activated at any time without a
problem.
Masked services won’t run unless that property is taken away.
Static services will only be used in case another service or unit needs it.
To list only the services that are active
sudo systemctl | grep running
Web Server Setup

Manage Services
To start a service
sudo systemctl start [service_name]
To stop a service
sudo systemctl stop [service_name]
To check the status of a service
sudo systemctl status [service_name]
Run a service while the OS is being loaded:
sudo systemctl enable [service_name]
Remove from initial load
sudo systemctl disable [service_name]
To install a service
sudo apt install net-tools
yum install net-tools
Web Server Setup

http service

Apache Web Server is used


Install apache web server using
yum -y install httpd
Daemon is httpd
service httpd start/stop/restart
Edit httpd.conf file specific to your httpd needs.
On Ubuntu
Install - sudo apt-get install apache2
Daemon is apache2.service
service apache2 start/stop/restart
Web Server Setup

Files used by Apache

Configuration file: /etc/apache2/apache2.conf


Log files: /var/log/apache2/access_log and
/var/log/apache2/error_log
Modules /etc/apache2/modules
Default Document Root /var/www/html
Default CGI Root /var/www/cgi-bin
Web Server Setup

Apache Configuration
Website content is stored in the /var/www/html/ directory
Apache creates log files for any errors it generates in the file
/var/log/apache2/error.log
It also creates access logs for its interactions with clients in
the file /var/log/apache2/access.log
Apache functions through the use of configuration files.
They are all located in the /etc/apache2/ directory.
Web Server Setup

Apache Configuration
/etc/apache2/apache2.conf – This is the main Apache configuration file
and controls everything Apache does on your system. Changes here
affect all the websites hosted on this machine.
/etc/apache2/ports.conf – The port configuration file. You can
customize the ports Apache monitors using this file. By default, Port 80
is configured for http traffic.
/etc/apache2/sites-available – Storage for Apache virtual host files. A
virtual host is a record of one of the websites hosted on the server.
/etc/apache2/sites-enabled – This directory holds websites that are
ready to serve clients. The a2ensite command is used on a virtual host
file in the sites-available directory to add sites to this location.
Web Server Setup

Basic Settings

Change the default value for ServerName www.<your-


domain.com> in apache2.conf and put the website
content in /var/www/html
Additionally you can configure Name based Virtual
Hosting (allow more than one websites to run on the
same server)
Web Server Setup

Virtual Hosting

Virtual Host allows you to run multiple websites from a


single physical server or Virtual Private Server. There are
two types of virtual hosts on Apache:
IP-Based Virtual Hosting – every individual website on the
Apache Server uses a different, unique IP address.
Name-Based Virtual Hosts – enables you to add multiple
domains using a single IP address.
Web Server Setup

Virtual Hosting
Create required directories in /var/www/vu.com and
/var/www/vijayukani.com
Create index.html files both sites
Create Virtual Host configuration files in /etc/apache2/sites-
available directory as vu.com.conf and vijayukani.com.conf for
both the sites (contents of this file on next slide)
Use the a2ensite helper to enable the virtual host file with the
command:
sudo a2ensite vu.com
sudo a2ensite vijayukani.com
Web Server Setup

Virtual Hosting

<VirtualHost *:8080>
ServerAdmin webmaster@vu.com
ServerName vu.com
ServerAlias www.vu.com
DocumentRoot /var/www/vu.com

ErrorLog ${APACHE_LOG_DIR}/vu.com-error.log
CustomLog ${APACHE_LOG_DIR}/vu.com-access.log
combined

</VirtualHost>
Squid Setup

SQUID SETUP
Squid Setup

What is a Web Proxy?


Squid is a most popular caching and forwarding HTTP web
proxy server to cache web pages from a web server to
improve web server speed, reduce response times and
reduce network bandwidth.
A proxy is a host which relays web access requests from
clients
used when clients do not access the web directly
used for security, logging, accounting and performance

browser proxy web


Squid Setup

Obtaining Squid
Source code (in C) from www.squid-cache.org
Binary executables
Linux (comes with RedHat and others)
FreeBSD
Windows
Pre-installed in Fedora/Enterprise Linux
Install using apt
sudo apt-get install squid
Squid Setup

Basic Settings
Edit the /etc/squid/squid.conf file to configure squid
Configuration options:
Disk Cache size and location
Authentication
Allowed Hosts
Any other access restrictions (sites, content, size,
time of access etc.) using ACL
service squid start/stop/restart
Squid Setup

Squid.conf Configuration
cache_dir ufs /var/spool/squid/cache 100 16 256
auth_param basic program /usr/lib/squid/ncsa_auth
/etc/shadow
acl sidbiusers proxy_auth required
http_access allow sidbiusers
acl our_network src 172.28.250.0/24
http_access allow our_network
(Note: use squid –z for the first time to create the
cache directory and its subdirectories)

You might also like