[go: up one dir, main page]

0% found this document useful (0 votes)
79 views89 pages

Osa Lab Manual

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 89

Department of Computer Science and Engineering

Graded Exercise

Operating System and


Administration 20CS42P

IV Semester
Computer Science

Operating System and Administration - 20CS42P -1-


Department of Computer Science and Engineering

Certificate

Name : Class: IV Semester

Register Number :

Institution :

This is certified to be the bonafide work of the student in the Operating System and

Administration – 20CS42P Laboratory during the academic year 202 – 202

Course Coordinator

Examiner Signature

1.

2.

Operating System and Administration - 20CS42P -2-


Department of Computer Science and Engineering

List of Experiments

Sl. No. Name of the Experiment Date of Remarks


Experiment

1 Operating system (OS) and Administration

2 Install and configure virtual machine – Virtual box

3 File and Directory Commands

4 Process creation and Management

5 Process Synchronization

6 Memory Management

7 Shell Programming

8 Automation of System Tasks

9 Network Management

10 User Authentication

11 System/Log monitoring commands and System


Information/Maintenance Commands

12 Domain Name Service (DNS)

13 Storage Management

Operating System and Administration - 20CS42P -3-


Department of Computer Science and Engineering

01 – Operating system (OS) and Administration

An Operating system (OS) is system software that manages computer hardware, software
resources, and provides common services for computer programs. In other words, an Operating
System (OS) is software that acts as an interface between computer hardware components and the
user.

1. Types of OS installation
Attended installation:
 An installation process usually needs a user who attends it to make choices, such as
accepting or declining an end-user license agreement (EULA), specifying preferences
such as the installation location, supplying passwords or assisting in product activation.
 In graphical environments, installers that offer a wizard-based interface are common.
 Attended installers may ask users to help mitigate the errors.
o For example, if the disk in which the computer program is being installed was
full, the installer may ask the user to specify another target path or clear enough
space in the disk.

Silent installation:
 An installation that does not display messages or windows during its progress.
 "Silent installation" is NOT the same as "unattended installation". [All silent installations
are unattended but not all unattended installations are silent.]
 In bigger organizations where thousands of users work, deploying the applications
becomes a typical task and for that reason silent installation is performed so that the
application is installed in background without affecting the work of user.

Unattended installation:
 An installation that is performed without user interaction during its progress or with no
user present at all.
 One of the reasons to use this approach is to automate the installation of a large number
of systems.
 An unattended installation either does not require the user to supply anything or has
received all necessary input prior to the start of installation. Such input may be in the
form of command line switches or an answer file, a file that contains all the necessary
parameters.
o For example, if the installation medium was faulty, the installer should fail the
installation, as there is no user to fix the fault or replace the medium. Unattended
installers may record errors in a computer log for later review.

Headless installation:
 Installation performed without using a computer monitor connected.
 In attended forms of headless installation, another machine connects to the target
machine (for example, via a local area network) and takes over the display output.
 Since a headless installation does not need a user at the location of the target computer,
unattended headless installers may be used to install a program on multiple machines at
the same time.

Operating System and Administration - 20CS42P -4-


Department of Computer Science and Engineering

Scheduled or Automated installation:


 An installation process that runs on a preset time or when a predefined condition meet the
requirements, as opposed to an installation process that starts explicitly on a user's
command.
o For example, a system administrator willing to install a later version of a
computer program that is being used can schedule that installation to occur when
that program is not running.
 An operating system may automatically install a device driver for a device that the user
connects.

Clean installation:
 A clean installation is one that is done in the absence of any interfering elements such as
old versions of the computer program being installed or leftovers from a previous
installation.
 The clean installation of an operating system is an installation in which the target disk
partition is erased before installation.
 Since the interfering elements are absent, a clean installation may succeed where an
unclean installation may fail or may take significantly longer.

Network installation:
Network installation (netinstall), is an installation of a program from a shared network resource
that may be done by installing a minimal system before proceeding to download further packages
over the network.
This may simply be a copy of the original media but software publishers which offer site licenses
for institutional customers may provide a version intended for installation over a network.
=== * ===

2. Boot methods
Booting is the process of starting a computer as initiated via hardware such as a button or by a
software command.
Types of Booting:
 Warm Booting: The Warm Booting is that in which system starts from the starting or
from initial state means.
o In the Warm Booting the system will be started from its beginning state means,
first, the user will press the Power Button, then this will read all the instructions
from the ROM and the Operating System will be automatically gets loaded into
the System (RAM).
 Cold Booting: The Cold Booting is that in which System automatically starts when the
system is in a running state.
o For example, due to Light Fluctuation, the system will automatically restarts. In
this, chances of damaging of system are more. The system will now be start from
its initial state, so some files may be damaged because they are not properly
stored into the system.
=== * ===
3. File System and Formatting:
File System:
 A file system is a process of managing how and where data on a storage disk, which is
also referred to as file management or FS.

Operating System and Administration - 20CS42P -5-


Department of Computer Science and Engineering

 It is a logical disk component that compresses files separated into groups, which is
known as directories.
 The file system enables user to view a file in the current directory as files are often
managed in a hierarchy.
 It is abstract to a human user and related to a computer; hence, it manages a disk's
internal operations.
 NTFS is the most common file system in modern times (Windows OS).
 Without file management, it would be impossible for a file with the same name to exist
and also impossible to remove installed programs and recover specific files.

Examples of File Systems:


The examples of file systems are given below:
 FAT: FAT is a type of file system, which is developed for hard drives. It stands for File
Allocation Table. On hard drives and other computer systems, it helps to manage files on
Microsoft operating systems. In devices like digital cameras, flash memory, and other
portable devices, it is also often found that is used to store file information. It also helps
to extend the life of a hard drive as it minimizes the wear and tears on the hard disc. Now
a days later versions of Microsoft Windows like Windows XP, Vista, 7, and 10 as use
NTFS.
o The FAT8, FAT12, FAT32, FAT16 are all the different types of FAT (for file
allocation table).
 GFS: A GFS is a file system, which stands for Global File System. It has the ability to
make enable multiple computers to act as an integrated machine. When the physical
distance of two or more computers is high, and they are unable to send files directly with
each other, a GFS file system makes them capable of sharing a group of files directly. A
computer can organize its I/O to preserve file systems with the help of a global file
system.
 HFS: HFS (Hierarchical file system) is the file system that is used on a Macintosh
computer for creating a directory at the time a hard disk is formatted. Generally, its basic
function is to organize or hold the files on a Macintosh hard disk. Apple is not capable of
supporting to write to or format HFS disks since when OS X came on the market. Also,
HFS-formatted drives are not recognized by Windows computers as HFS is a Macintosh
format. With the help of WIN32 or NTFS file systems, Windows hard drives are
formatted.
 NTFS: NTFS is the file system, which stands for NT file system and stores and retrieves
files on Windows NT operating system and other versions of Windows like Windows
2000, Windows XP, Windows 7, and Windows 10. Sometimes, it is known as the New
Technology File System. As compared to the FAT and HFS file system, it provides
better methods of file recovery and data protection and offers a number of improvements
in terms of extendibility, security, and performance.
 UDF: A UDF is a file system, stands for Universal Disk Format and used first
developed by OSTA (Optical Storage Technology Association) for ensuring consistency
among data written to several optical media. It is used with CD-ROMs and DVD-ROMs
and is supported on all operating systems. Now, it is used in the process of CD-R's and
CD-RW's, called packet writing.

Operating System and Administration - 20CS42P -6-


Department of Computer Science and Engineering

Formatting:
Formatting is a process of preparing the storage device to store the data. Formatting storage
device will erase the earlier contents of the device.
=== * ===

4. Post installation tasks:


Post Installation task is the set of steps to be carried out to ensure that the installation is complete
and went smoothly.
Post Installation Tasks for Ubuntu Operating System:
 Online accounts
The first step allows user to configure online accounts, in case user want to integrate the
desktop with different services.
 Livepatch
Livepatch is a service that allows the installation of some updates that would generally
require a system reboot, such as those of the kernel.
 Help improve Ubuntu
In this step user can choose whether or not to send data from his system to Ubuntu. The
option is activated by default. The user can verify the secrecy of the data being sent
beforehand. The results are used to improve Ubuntu.
 Privacy
If required, a user can enable location services so that apps can determine user
geographic location. All the applications installed by default on Ubuntu are free
software.
 You are ready to start!
The last screen shows some featured applications -some of which are not free software
with the option to open the software center to install them.
=== * ===

Operating System and Administration - 20CS42P -7-


Department of Computer Science and Engineering

2 – Install and configure virtual machine – Virtual box

Virtual Box:
VirtualBox is a cross-platform virtualization application. It installs on existing operating
systems and also it extends the capabilities of the existing computer so that it can run
multiple operating systems (it means, inside multiple virtual machines) at the same
time.
 Host operating system (host OS): the operating system of the physical
computer on which VirtualBox was installed.
 Guest operating system (guest OS): the operating system that is running
inside the virtual machine.
 Virtual machine (VM). When running, a VM is the special environment that
VirtualBox creates for guest operating system.

VirtualBox’s main features:


Portability
No hardware virtualization required

1. Download and install the latest version of Oracle VM Virtual Box


(from: https://www.virtualbox.org/wiki/Downloads).

Operating System and Administration - 20CS42P -8-


Department of Computer Science and Engineering

1. Installation steps
• Double click or right click on the Oracle VM Virtual Box Executable file.

• “Setup Wizard” screen appears Click next.

• Then “Custom setup with all the features of VM” screen appears Click next.

Operating System and Administration - 20CS42P -9-


Department of Computer Science and Engineering

• Next “Select the way you want features to be installed” Screen appears
Click next.

• Next “Warning network interface” screen appears Click yes.

• And last “Ready to install” screen appears Click on install button.

Operating System and Administration - 20CS42P - 10


-
Department of Computer Science and Engineering

• While installing another dialogue box appears asking “would you


like to install this device software?” Click on install.

• After completion of installation Click on the finish button.

• So that installation of Virtual box completes you can use it.

Operating System and Administration - 20CS42P - 11


-
Department of Computer Science and Engineering

Steps to install Operating system:


1. Open Oracle VM VirtualBox, then click on “Machine” icon and then click on
“New”.

2. Now give any “Name” to Virtual OS and Click on “Next” button.

Operating System and Administration - 20CS42P - 12


-
Department of Computer Science and Engineering

3. Then select the desired memory size “1024MB” and click on “Next” button.

4. And next select “Create Virtual Hard Disk now” and Click on “Create” button.

5. Next select “Virtual Disk Image” and click on “Next” button.

Operating System and Administration - 20CS42P - 13


-
Department of Computer Science and Engineering

6. Next select “Dynamically allocated” and click on “Next” button.

7. Enter the name of Virtual Hard disk then select the size of hard disk as
per requirement (10GB) and click “Create” button.

Operating System and Administration - 20CS42P - 14


-
Department of Computer Science and Engineering

8. Now go to “Settings”.

Operating System and Administration - 20CS42P - 15


-
Department of Computer Science and Engineering

9. Select “Storage” and then select “Empty” Disk.

10. Select “Disk” icon and choose the “Choose/Create a virtual optical disk
file” then select the “Ubuntu ISO file” that you already downloaded. Then
click on “OK” button.

11. Then click on the “Start” button and carry on with the installation process of
ubuntu.
Operating System and Administration - 20CS42P - 16
-
Department of Computer Science and Engineering

12. Once the OS is installed you can use the OS in Virtual Machine any time.

Operating System and Administration - 20CS42P - 17 -


Department of Computer Science and Engineering

03 – File and Directory Commands

ls (list)

 Use ls without any arguments to display current directory contents.


 ls with the -a option. files all begin with a "dot", which indicates they are "hidden" files.

=== * ===
pwd (Present Working Directory)
 Will give the present working directory path information
 Example 1 : pwd

=== * ===
mkdir (Make Directory)
 mkdir will create a new directory (folder)
 Syntax: mkdir directoryname(folder name)
Example 1: mkdir polytechnic // will create directory with name polytechnic

Operating System and Administration - 20CS42P - 18 -


Department of Computer Science and Engineering

=== * ===

cd (Change Directory)
 cd is used to Change Directory
 Change to home direcotory
o cd // Change to default home directory
o cd ~ // Change to default home directory

 Go up one level back to the current directory's parent directory


o cd ..
o pwd
=== * ===
rmdir (Remove Directory)
 Will remove (delete) the directory
 Make sure that folder is empty before issuing rmdir command.
 Make sure current directory is not part of the directory being deleted.
o rmdir civil (assume current directory is /home/polytechnic)
o rmdir /polytechnic/computer (assume /polytechnic/computer folder exists)
=== * ===

Operating System and Administration - 20CS42P - 19 -


Department of Computer Science and Engineering

Creating files using vi editor

The vi editor has three modes of operation viz. the command mode, the insert mode, and the ex-
command mode.

1) Command mode
In this mode, all the keys work as commands. These keys are used for inserting, appending, deleting,
opening new lines, moving the cursor over the paragraphs and sentences, etc. In this mode, the keys are
not displayed but each key performs an operation.

By default the vi editor is in command mode, hence we cannot type text in command mode. In order to
write programs or text in the vi editors, we need to switch to the insert mode which can be done by
pressing the escape button.

2) Insert mode
In this mode, we can insert, append, edit or replace texts. We can switch from the command mode to
Insert mode by pressing the escape button and then pressing I or A to enter into insert mode.

3) Ex command mode
This mode is used for entering commands at the bottom line of the vi editor called a command line. To
switch to Ex command mode press the escape key then type: (colon). In order to save the contents and
quit from the vi editor press wq after the : (colon). i.e :wq.

Vi editor saving and quitting commands:


:w -Save the contents of the file.
:q – Quit from vi editors.
:wq -Save the file and quit from the vi editor.

To create a sample file in editor open terminal and type vi in prompt type command

And give appropriate permission to the file and run command to view output

Operating System and Administration - 20CS42P - 20 -


Department of Computer Science and Engineering

Operating System and Administration - 20CS42P - 21 -


Department of Computer Science and Engineering

File Manipulation Commands:


Creating File:
 touch: will create empty files
o Example: touch a.txt

Display the Contents of Files:


 Syntax: cat filename
o cat /path/filename
 Example:
o cat a.txt

=== * ===

rm (Remove File)
 Will remove (delete) the files

Operating System and Administration - 20CS42P - 22 -


Department of Computer Science and Engineering

 Syntax: rm FileName
o rm path/Filename
 Example:
o rm a.txt // Assume a.txt is present in current directory

=== * ===
cp (Copy)
 Used to create a copy of a existing file.
 Copy an existing file in current directory to another file in the current directory. Make
sure that the file to be copied must be exists in specified location.
 Syntax: cp file1 file2
 cp path1/file1 path2/file2 // creates copy of file1 in current directory or in specified
directory
 cp a.txt b.txt (Make sure file a.txt exists in current directory)
o new file b.txt is created and contents of b.txt is same as a.txt

=== * ===
mv (Move)
 Used to rename the file (in other words, used to move the files from one location to
another location)
 It can be used to rename the Directory (Folder) also.
 Example 1:
o mv OldFileName NewFileName

Operating System and Administration - 20CS42P - 23 -


Department of Computer Science and Engineering

=== * ===

Pipes: The pipe command lets user sends the output of one command to another. Piping, as the
term suggests, can redirect the standard output, input, or error of one process to another for
further processing.

 Syntax: cat [filename] | sort

=== * ===

more
It is a filter for paging through text one screenfull at a time.
o more filename
 Press Space bar / Return Key to read the remaining parts of the file.
 Press q to quit viewing contents

less
It is used to viewing the files instead of opening the file.Similar to more command
but it allows backward as well as forward movement.
Example:
less test.sh

cmp (Compare)
 compare two files byte by byte
 Syntax: cmp [ file1] [file2]

head and tail


 Output the first/last part of files (by Default first/last 10 lines)
o head filename
o tail filename
 Example1:
o head -5 a.txt will display first 5 lines of a.txt
o tail -5 a.txt will display last 5 lines of a.txt

Operating System and Administration - 20CS42P - 24 -


Department of Computer Science and Engineering

File Permissions
 There are three users in linux namely owner(u), group(g), others(o).
o Note: For all users can be identified with letter a
 All three uses will have three possible permissions namely read(r), write(w), execute(e)
 Numbers assigned for permissions are read(4), write(2), execute(1)

 Command used to change permission of file is chmod


 Syntax: chmod filePermissionPattern filename

Examples

Operating System and Administration - 20CS42P - 25 -


Department of Computer Science and Engineering

 add execution permission to group and other users for file output.pdf
o chmod go+x output.pdf
o ls output.pdf -l
o -rwxrwxr-x 1 admincs admincs 1.9M Mar 28 08:45 output.pdf

 remove write permissions to group users


o chmod g-w output.pdf
o ls output.pdf -l
o -rwxr-xr-x 1 admincs admincs 1.9M Mar 28 08:45 output.pdf

Working with numbers in chmod


Syntax: chmod chmodnumber filename

Example 1: if user wants rwxrw-r-- format set number to 764


777 = rwxrwxrwx
o 765 = rwxrw-r-x
o 654 = rw-r-xr—

Example 2:
o chmod 777 output.pdf will set all permissions to all users
o chmod 765 output.pdf will set rwxrw-r-x to users
o chmod 654 output.pdf will set rw-r-xr-- to users
=== * ===

Operating System and Administration - 20CS42P - 26 -


Department of Computer Science and Engineering

File Compression and Decompression:


Compression reduces the size of an application or document for storage or transmission.
Compressed files are smaller, download faster, and easier to transport. Decompression or
expansion restores the document or application to its original size.
Compressing files:

gzip:compresses the file and a file with .gz extension is created

If no errors are encountered a compressed version of largeFile, largeFile.gz is


created in the current directory.

Decompressing files

To decompress we write,
gunzip k.c.gz

Text Processing Commands


Commands affecting text and text files
sort
 sort command is used to sort a file, arranging the records in a particular order.
 By default, the sort command sorts file assuming the contents are ASCII.
 Using options in the sort command can also be used to sort numerically.
 The sort command can also sort by items not at the beginning of the line, ignore case
sensitivity, and return whether a file is sorted or not.
 Sorting is done based on one or more sort keys extracted from each line of input.
 By default, the entire input is taken as the sort key.
 Blank space is the default field separator.
Operating System and Administration - 20CS42P - 27 -
Department of Computer Science and Engineering

Syntax:
sort filename

uniq
 uniq filter removes duplicate lines from a sorted file. It is often seen in a pipe coupled
with sort.
 uniq [filename]
 removes the duplicates lines as well as displys frequency of duplicate lines.

== * ===
cut
 A tool for extracting fields from files.
 Important options are -d, which specifies delimiter to separate fields, -f which indicates
field numbers
 Example 1: cut –c 1-2 headtail.txt

Operating System and Administration - 20CS42P - 28 -


Department of Computer Science and Engineering

head and tail

 head/tail: output the first/last part of files (by Default 10 lines)


o head FileName
o tail FileName
 Example 1: head -5 a.txt will display first 5 lines of a.txt
tail -5 a.txt will display last 5 lines of a.txt

grep
 A multi-purpose file search tool that uses Regular Expressions. (Global Regular
Expression Pring).
o grep pattern [FileName...]
o

wc
 wc gives a "word count" on a file or I/O stream:
 Syntax: wc -lwc FileName
Operating System and Administration - 20CS42P - 29 -
Department of Computer Science and Engineering

 Example:
o wc headtail.txt

=
== * ===

Operating System and Administration - 20CS42P - 30 -


Department of Computer Science and Engineering

04 – Process creation and Management

Process

 A process is any active (running) instance of a program. In other words, process is a


program in execution.
 A new process can be created by the fork() system call.
 The new process consists of a copy of the address space of the original process. fork()
creates new process from existing process.
 Existing process is called the parent process and the process is created newly is called
child process.

 Each process is given a unique process identification number (PID).


 PID is usually five-digit number.
o This number is used to manage each process.
o user can also use the process name to manage process.

Starting a Process

A process executes in two ways they are,


 Foreground Processes
 Background Processes

Foreground Processes
 Every process by default runs in Foreground (which means the output is printed on the
screen.) The best example for the foreground process is the ls command which prints the
output on the screen by listing the files and directories.
 When a program is running in the foreground, user cannot start another process without
completing the previous process. [ It is because of this reason foreground process is
considered a time-consuming process.]
Background Processes
 When a process starts running and it is not visible on the screen it is called a background
process.
 User can simultaneously run ‘n’ number of commands in the background process.

 To enable the background process, provide ampersand symbol (&) at the end of the command.
They run in the background and usually do not need user input. For example
Antivirus.

 Example : ls &

sleep
command is used to create a dummy job. A dummy job helps in delaying the
Operating System and Administration - 20CS42P - 31 -
Department of Computer Science and Engineering

execution. It takes time in seconds by default but a small suffix(s, m, h, d) can be


added at the end to convert it into any other format. This command pauses the
execution for an amount of time which is defined by NUMBER.
Syntax:
sleep NUMBER[SUFFIX]...
Example:

Jobs
The jobs command will list all jobs on the system; active, stopped, or
otherwise.

ps
The default output of ps is a simple list of the processes running in current terminal.
 Example: ps
PID TTY TIME CMD
23989 pts/0 00:00:00 bash
24148 pts/0 00:00:00 ps

Operating System and Administration - 20CS42P - 32 -


Department of Computer Science and Engineering

Operating System and Administration - 20CS42P - 33 -


Department of Computer Science and Engineering

Demonstrate exec( ) system call


The exec() family of functions replaces the current process image with a new process image.
exec command in Linux is used to execute a command from the bash itself. This command does
not create a new process it just replaces the bash with the command to be executed. If the exec
command is successful, it does not return to the calling process.
exec > out.txt
 Redirect all output to the file out.txt for the current shell process.
 Redirections are a special case, and exec does not destroy the current shell process, but
bash will no longer print output to the screen, writing it to the file instead.

Example 1:

Operating System and Administration - 20CS42P - 34 -


Department of Computer Science and Engineering

bg: background
 bg used to place foreground jobs in background. [used to send a process running in the
foreground to the background in the current shell.]
Syntax: bg [ job_spec]

 Example: sleep 500 is a command which is used to create a dummy job which runs for
500 seconds.
o Use jobs command to list all jobs
o Create a process using sleep command, get job id as 1
o Put that process in background using id
 $ jobs // Display current jobs running and displayed nothing
 $ sleep 500 // Create one job, which sleeps for 500 seconds.
 ^z // Terminate the job by pressing Ctrl + z
o [1]+ Stopped sleep 500
 $ jobs // Display current jobs running and displayed one job stopped
o [1]+ Stopped sleep 500
 $ bg %1 // Refer the process by job number place it in background
o [1]+ sleep 500 &
 $ jobs // Display current jobs running and displayed one job which is running.
[1]+ Running sleep 500

=== * ===
fg: forground
 bg is a command that moves a background process on current Linux shell to the
foreground.
Syntax: bg [ job_spec]
 Place the jobs identified by each job_spec in the foreground, making it the current job.
Example: sleep 500 is a command which is used to create a dummy job which runs for 500
seconds.
 $ jobs
 $ sleep 500
 ^z
o [1]+ Stopped sleep 500
 $ jobs
o [1]+ Stopped sleep 500
 $ bg %1
o [1]+ sleep 500 &
 $ jobs
Operating System and Administration - 20CS42P - 35 -
Department of Computer Science and Engineering

o [1]+ Running sleep 500


 $ fg %1 // Brings the background process (referred by its number) to foreground
 sleep 500 // waiting for the process to terminate.

=== * ===
nohup
The nohup command is one way of blocking the SIGHUP signal and allowing processes to
complete even after logging out from the terminal/shell.
SIGHUP (Signal Hang UP) is a signal that terminates a Linux process when its controlling
terminal is closed. The syntax for using the nohup command is:

nohup [command] [arguments]

To run a command using nohup without any arguments, simply follow the syntax:
nohup [command]

=== * ===

Stopping a process
kill
This command terminates running processes on a Linux machine.

To use these utilities you need to know the PID (process id) of the process you
want to kill

Syntax –
kill PID
To find the PID of a process simply type

Operating System and Administration - 20CS42P - 36 -


Department of Computer Science and Engineering

pkill
 command used to send signal to kill process by process name.
 while issuing pkill, make sure that selected process name is the correct process to be
stopped, verify it by its full path by issuing pgrep –f processname.
 Syntax: pkill -f ProcessName

=== * ===
nice
 nice command in Linux helps in execution of a program/process with modified
scheduling priority.
 It launches a process with a user-defined scheduling priority.
 Linux Kernel schedules the process and allocates CPU time accordingly for each of them.
 The kernel stores a great deal of information about processes including process priority
which is simply the scheduling priority attached to a process.
 Processes with a higher priority will be executed before those with a lower priority, while
processes with the same priority are scheduled one after the next, repeatedly.
 There are a total of 140 priorities and two distinct priority ranges implemented in Linux.
 The first one is a nice value (niceness) which ranges from -20 (highest priority value) to
19 (lowest priority value) and the default is 0.
 The other is the real-time priority, which ranges from 1 to 99 by default, then 100 to 139
are meant for user-space.
Operating System and Administration - 20CS42P - 37 -
Department of Computer Science and Engineering

Check Nice Value of Linux Processes


nice runs command COMMAND with an adjusted "niceness", which
affects process scheduling. A process with a lower niceness value is given
higher priority and more CPU time. A process with a higher niceness value
(a "nicer" process) is given a lower priority and less CPU time, freeing up
resources for processes that are more demanding.

Niceness values range from -20 (most favorable to the process)


to 19 (least favorable to the process).

Syntax
nice [OPTION] [COMMAND [ARG]...]

nice -5 wc –l &

Operating System and Administration - 20CS42P - 38 -


Department of Computer Science and Engineering

top
 The top command has been around a long time and is very useful for viewing details of
running processes and quickly identifying issues such as memory hogs.
 Its default view is shown below. Example 1: top

Commands to Schedule Tasks:


cron
Cron Command

The cron can be defined as a software utility that is provided by a Linux-like OS that operates
the scheduled operation on a predetermined period. It's a daemon process and executes as
a background process. It performs the described tasks at a predefined period when a
condition or event is encountered without user intervention.

The crontab ("cron table") is a list of commands for executing the scheduled operations at a
particular time. It permits the user for adding, removing, or modifying the scheduled
operations.

The syntax of the crontab command contains six parts separated by a space in which the first
five parts illustrate the time to execute the operation and the last part illustrates the command.

Operating System and Administration - 20CS42P - 39 -


Department of Computer Science and Engineering

To install sudo apt-get install cron

Setting up the Cron Operation


We need to open the crontab along with a text editor for configuring the cron operation and
enter the syntax for a command we wish to execute.

Editing a crontab file


We need to type a command in our terminal window for opening the configuration file of the
crontab for a current user. The command is mentioned as follows:

1. crontab -e

Operating System and Administration - 20CS42P - 40 -


Department of Computer Science and Engineering

Simple Example:

Example 2:
To run a job at 4.35 pm edit crontab

Operating System and Administration - 20CS42P - 41 -


Department of Computer Science and Engineering

Check remote server connectivity using cronjob


Save below file as ping.sh

Run ping.sh from crontab

Operating System and Administration - 20CS42P - 42 -


Department of Computer Science and Engineering

To check the output check ping.txt file in tmp folder

at

at command is a command-line utility that is used to schedule a command to be
executed at a particular time in the future.
 Jobs created with at command are executed only once.
 The at command can be used to execute any program or mail at any time in the future.
 It executes commands at a particular time and accepts times of the form HH:MM to run a
job at a specific time of day.
 In the command, expression like noon, midnight, teatime, tomorrow, next week, next
Monday, etc. could be used with at command to schedule a job.
 Syntax: at [OPTION...] runtime
Working with at command
 Command to list the user’s pending jobs:
o at -l
OR
o atq

Operating System and Administration - 20CS42P - 43 -


Department of Computer Science and Engineering

To display calendar using at command

NOTE (press ctrl+d) to instruct we are done with at commands

To run at after 1 minute from now

 Schedule a job for the coming Monday at a time twenty minutes later than the current
time:
o at Monday +20 minutes
 Schedule a job to run at 1:45 Aug 12 2020:
o at 1:45 081220
 Schedule a job to run at 3pm four days from now:
o at 3pm + 4 days
 Schedule a job to shutdown the system at 4:30 today:
o echo "shutdown -h now" | at -m 4:30
 Schedule a job to run five hour from now:
o at now +5 hours

use atrm jobno to remote a task from at command

Operating System and Administration - 20CS42P - 44 -


Department of Computer Science and Engineering

05 – Process Synchronization

Commands to exhibit thread concepts:

 Threads are a popular programming abstraction for parallel execution on modern


operating systems.
 When threads are forked inside a program for multiple flows of execution, these threads
share certain resources (e.g., memory address space, open files) among themselves to
minimize forking overhead and avoid expensive IPC (inter-process communication)
channel.
 These properties make threads an efficient mechanism for concurrent execution.
 In Linux, threads (also called Lightweight Processes (LWP)) created within a program
will have the same "thread group ID" as the program's PID.
 Each thread will then have its own thread ID (TID).
 Threads are nothing more than standard processes which happen to share certain
resources.
 Classic command-line tools such as ps or top, which display process-level information by
default, can be instructed to display thread-level information.

Using the ps
The "-T" option for the ps command enables thread views.

 The "SPID" column represents thread IDs, and "CMD" column shows thread names.

Using the top


The top command can show a real-time view of individual threads.
To enable thread views in the top output, invoke top with "-H" option. This will list all Linux
threads.
User can also toggle on or off thread view mode while top is running, by pressing 'H' key.
Example 1: top

Operating System and Administration - 20CS42P - 45 -


Department of Computer Science and Engineering

To restrict the top output to a particular process and check all threads running inside the process:
Example 2: top -H -p 1572

Using htop
A more user-friendly way to view threads per process is via htop, an ncurses-based interactive
process viewer.
This program allows user to monitor individual threads in tree views.
To enable thread views in htop, launch htop, and press F2 to enter htop setup menu.
sChoose "Display option" under "Setup" column, and toggle on "Tree view" and "Show custom
thread names" options. Presss F10 to exit the setup.

Operating System and Administration - 20CS42P - 46 -


Department of Computer Science and Engineering

=== * ===

Operating System and Administration - 20CS42P - 47 -


Department of Computer Science and Engineering

06 – Memory Management
1. free command
Commands to view memory consumption:

2. /proc/meminfo
 Check memory usage by reading the file at /proc/meminfo.
 Know that the /proc file system does not contain real files.
o They are rather virtual files that contain dynamic information about the kernel
and the system.

 Check the values of MemTotal, MemFree, Buffers, Cached, SwapTotal, SwapFree. They
indicate same values of memory usage as the free command.
3. vmstat
 vmstat –s
 Portion of output is

Operating System and Administration - 20CS42P - 48 -


Department of Computer Science and Engineering


The top few lines indicate total memory, free memory etc and so on.

Operating System and Administration - 20CS42P - 49 -


Department of Computer Science and Engineering

4. top command
 The top command is generally used to check memory and cpu usage per process.
 It also reports total memory usage and can be used to monitor the total RAM usage.
 The header on output has the required information.
 Check the KiB Mem and KiB Swap lines on the header. They indicate total, used and free
amounts of the memory. The buffer and cache information is present here too.
 Portion of output is

5. htop
 Similar to the top command, the htop command also shows memory usage along with
various other details.
 The header on top shows cpu usage along with RAM and swap usage with the
corresponding figures.
 .

Operating System and Administration - 20CS42P - 50 -


Department of Computer Science and Engineering

Work on Practice Session

Operating System and Administration - 20CS42P - 51 -


Department of Computer Science and Engineering

Work on Practice Session


07 – Shell Programming

Script 1: Biggest of Three Numbers using if-elif-fi | Output


# Find biggest of Three numbers
echo Enter Three Numbers
read a b c
if (( $a>=$b && $a>=$c ))
then
big=$a
elif(( $b>=$a && $b>=$c ))
then
big=$b
elif(( $c>=$a && $c>=$b ))
then
big=$c
fi
echo Biggest among $a $b $c is $big
=== * ===

Script 3: Script to reverse a string


#Reversing a string

s="Hello"
strlen=${#s}
for (( i=$strlen-1; i>=0; i-- ));
do
revstr=$revstr${s:$i:1}
done
echo "Original String : $s"
echo "Reversed String : $revstr"

Script 3: Script to read age of a person and display if he is eligible to vote

Script 3: Script to demonstrate switch statement to give color of your choice

Operating System and Administration - 20CS42P - 52 -


Department of Computer Science and Engineering

File Handling Scripts:


Script 7: Read the contents of a file and display the same on Screen (Demo cat command)
read -p "Enter file name : " filename
while read line
do
echo $line
done < $filename

Operating System and Administration - 20CS42P - 53 -


Department of Computer Science and Engineering

=== * ===
8 – Automation of System Tasks

Illustrate automation of basic tasks like monitoring memory consumption, check


connectivity, etc., at different frequencies.

The cron is a software utility, offered by a Linux-like operating system that automates the
scheduled task at a predetermined time.

Creating cron jobs


 To create or edit a cron job as the root user, run the command
o # crontab -e
Listing crontab files
 To view the cron jobs that have been created, simply pass the -l option as shown
o # crontab -l
Deleting a crontab file
 To delete a cron file, simply run crontab -e and delete or the line of the cron job that user
wants and save the file.
 To remove all cron jobs, run the command:
o # crontab -r

The rules which govern the format of date and time field as follows:
 When any of the first five fields are set to an asterisk(*), it stands for all the values of the
field. For instance, to execute a command daily, we can put an asterisk(*) in the week’s
field.
 One can also use a range of numbers, separated with a hyphen(-) in the time and date
field to include more than one contiguous value but not all the values of the field. For
example, we can use the 7-10 to run a command from July to October.
 The comma (, ) operator is used to include a list of numbers which may or may not be
consecutive. For example, “1, 3, 5” in the weeks’ field signifies execution of a command
every Monday, Wednesday, and Friday.
 A slash character(/) is included to skip given number of values. For instance, “*/4” in the
hour’s field specifies ‘every 4 hours’ which is equivalent to 0, 4, 8, 12, 16, 20.

Permitting users to run cron jobs:


 The user must be listed in this file to be able to run cron jobs if the file exists.
o /etc/cron.allow
 If the cron.allow file doesn’t exist but the cron.deny file exists, then a user must not be
listed in this file to be able to run the cron job.
o /etc/cron.deny
 Note: If neither of these files exists then only the superuser(system administrator) will be
allowed to use a given command.

 As cron processes will run in background, so to check whether scripts are executed or

Operating System and Administration - 20CS42P - 54 -


Department of Computer Science and Engineering

not, one way to check the log file i.e. /var/log/syslog


 Search for cron in syslog using command: cat /var/log/syslog/ | grep cron
 User can see all the entries, which shows, the scripted executed at a scheduled time
mentioned in crontab file.

To install sudo apt-get install cron

Setting up the Cron Operation


We need to open the crontab along with a text editor for configuring the cron operation and
enter the syntax for a command we wish to execute.

Editing a crontab file


We need to type a command in our terminal window for opening the configuration file of the
crontab for a current user. The command is mentioned as follows:

2. crontab -e

Operating System and Administration - 20CS42P - 55 -


Department of Computer Science and Engineering

Simple Example: Work on Practice Session

Example 2:
To run a job at 4.35 pm edit crontab

Operating System and Administration - 20CS42P - 56 -


Department of Computer Science and Engineering

Work on Practice Session

Check remote server connectivity using cronjob


Save below file as ping.sh

Run ping.sh from crontab

Operating System and Administration - 20CS42P - 57 -


Department of Computer Science and Engineering

Work on Practice Session

To check the output check ping.txt file in tmp folder

Example 3: Automation script to check memory consumption

Create a shell script to check memory consumtion


Memcon.sh

Schedule job in cron tab as below

Operating System and Administration - 20CS42P - 58 -


Department of Computer Science and Engineering

Work on Practice Session

Check output

=== * ===

Operating System and Administration - 20CS42P - 59 -


Department of Computer Science and Engineering

09 – Network Management

Enable internet on Linux VM.

Step 1: Ensure the internet connection

First, ensure that the wired network connection is already turned on by going to the network tab in the settings.

Step 2: Turn OFF the Virtual Machine

If you still do not have the internet connection established, you need to change the machine’s network adapter
settings from the Virtual machine settings.

For changing the network settings and for the modifications to take effect, turn off the virtual machine.

Step 3: Open network settings of Virtual Machine

After closing the Virtual Machine, open the virtual machine settings by right-clicking on the machine and
selecting the settings option from the context menu.

Operating System and Administration - 20CS42P - 60 -


Department of Computer Science and Engineering

In the settings window that appeared, click on the Network tab from the left bar.Step 4: Enable the Network
Adapter

In the machine’s Network Adapter settings, click on the “Enable Network Adapter” to enable the network
adapter and modify its settings.

Step 4: Enable the Network Adapter

In the machine’s Network Adapter settings, click on the “Enable Network Adapter” to enable the network
adapter and modify its settings.

If it is unchecked, then definitely this was the reason behind the internet connection not working because there
was no network adapter assigned to the Virtual machine by the VirtualBox.

Operating System and Administration - 20CS42P - 61 -


Department of Computer Science and Engineering

Step 5: Select the Network Device

After enabling the network adapter for the virtual machine, you can select the preferred method from the
“attached to” dropdown menu to attach the virtual network adapter to your host OS network.

We will suggest selecting the Bridged Adapter because this way, the virtual machine will be connected to the
network using the host OS Ethernet adapter.

After selecting the appropriate method from the “Name” drop-down, select the right device that you want to
choose.

Step 6: Save Settings and start the Virtual Machine

After configuring all the described settings, click on the OK button to save the settings.

And start the machine by double-clicking on the machine.

Operating System and Administration - 20CS42P - 62 -


Department of Computer Science and Engineering

You will have the internet connection working perfectly fine on your virtual machine in the virtual box.

ifconfig:
 ifconfig(interface configuration) is used to configure the kernel-resident network
interfaces.
 It is used at the boot time to set up the interfaces as necessary.
 It is used to assign the IP address and netmask to an interface or to enable or disable a
given interface.

Example 1: ifconfig -a
 -a : This option is used to display all the interfaces available, even if they are down.

Operating System and Administration - 20CS42P - 63 -


Department of Computer Science and Engineering

=== * ===

iwconfig:
 iwconfig command in Linux is like ifconfig command, in the sense it works with kernel-
resident network interface but it is dedicated to wireless networking interfaces only.
 It is used to set the parameters of the network interface that are particular to the wireless
operation like SSID, frequency etc.
 iwconfig may also be used to display the parameters, and the wireless statistics which are
extracted from /proc/net/wireless.

=== * ===

ethtool:
The ethtool utility on Linux allows you to view and change some of your network-driver and interface-card
settings, especially for wired devices.

sudo apt install ethtool

Operating System and Administration - 20CS42P - 64 -


Department of Computer Science and Engineering

arpwatch:

ARP also known as “Address Resolution Protocol” is a very useful tool to find IP to MAC address mappings.
It is also used to manipulates or displays the kernel’s IPv4 network neighbor cache.

telnet:

 The telnet command is used to create a remote connection with a system over a TCP/IP
network.
 It allows us to administrate other systems by the terminal.

ftp:
 ftp is the user interface to the Internet standard File Transfer Protocol.
 The program allows a user to transfer files to and from a remote network site.
 Prerequisites:
Operating System and Administration - 20CS42P - 65 -
Department of Computer Science and Engineering

 Install Ftp (FTP-Client) and vsftpd (FTP-Server) using Software Manager.


 Change /etc/vsftpd.conf file to enable write permission (other settings can be done
according to requirement.
◦ nano /etc/vsftpd.conf
 Search for # write_enable=YES (around 30th line in that file)
 Uncommnent and Save and Exit
 Restart the Service: systemctl restart vsftpd

Example 1: Get the connection to ftp


 ftp 192.100.100.2 21
 Enter user name and password for connection, this will take user to ftp utility and then
issue ftp command sets
 For more command take the help by issuing ? and to quit utility type quit command.

Example 2: Download the file from ftp server (Connection done in Example 1)
 get a.txt /home/admincs/Desktop/test.txt
o will download the file a.txt from ftp server to current user Desktop with file
name test.txt

Example 3: Upload the file from local machine to ftp server (Connection done in Example
1)
 put /home/admincs/index.html test.html
 will upload the file index.html from current (local /home/admincs) user to remote ftp
server with name test.html

netstat
 netstat is a command line utility for Linux that prints network connections, routing tables,
interface statistics, masquerade connections, and multicast memberships.
 netstat can be used to diagnose network issues and service problems.
 Important Options used:
o -a: all listening and non-listening ports, -t tcp ports
o -u udp ports, -l listening ports
o -s Statistics of ports, -r Kernel Routing Information

Example 1: netstat -at | head // To list all tcp ports.

Operating System and Administration - 20CS42P - 66 -


Department of Computer Science and Engineering

ping
 ping (Packet Internet Groper) command is used to check the network connectivity
between host and server/host.
 This command takes as input the IP address or the URL and sends a data packet to the
specified address with the message “PING” and get a response from the server/host this
time is recorded which is called latency.

Example 1: ping -c 5 -s 100 172.16.20.116


o Will send 5 ICMP Packets to test wheter machine 100.172.16.116 is alive or not, and
each packet size data is 100 bytes, total packet size is 108 (8 bytes of header).

Example

traceroute:
o traceroute command in Linux prints the route that a packet takes to reach the host.
o This command is useful when user want to know about the route and about all the hops
that a packet takes.

Example 1: traceroute www.google.com


traceroute to www.google.com (142.250.195.196), 30 hops max, 60 byte packets
1 172.16.20.1 (172.16.20.1) 0.761 ms 1.407 ms 1.973 ms
2 172.16.1.100 (172.16.1.100) 0.137 ms 0.137 ms 0.140 ms
3 117.236.190.194 (117.236.190.194) 7.500 ms 9.117 ms 8.384 ms
4 172.24.64.138 (172.24.64.138) 2.385 ms 2.380 ms 136.232.204.173.static.jio.com
(136.232.204.173) 3.082 ms
5 ***
6 72.14.218.250 (72.14.218.250) 19.051 ms 18.964 ms 19.297 ms
7 ***
8 216.239.59.230 (216.239.59.230) 20.538 ms maa03s42-in-f4.1e100.net
(142.250.195.196)
17.921 ms 216.239.59.230 (216.239.59.230) 20.029 ms

 The first column corresponds to the hop count. The second column represents the
address of that hop and after that, three space-separated time in milliseconds.
o traceroute command sends three packets to the hop and each of the time refers to
the time taken by the packet to reach the hop.

Example 2: traceroute 172.16.2.10 //local server


traceroute to 172.16.2.10 (172.16.2.10), 30 hops max, 60 byte packets
Operating System and Administration - 20CS42P - 67 -
Department of Computer Science and Engineering

1 172.16.20.1 (172.16.20.1) 0.624 ms 1.013 ms 1.428 ms


2 172.16.2.10 (172.16.2.10) 0.212 ms !X 0.206 ms !X 0.186 ms !X

Example 2: traceroute 127.0.0.1 //local machine


traceroute to 127.0.0.1 (127.0.0.1), 30 hops max, 60 byte packets
1 localhost (127.0.0.1) 0.034 ms 0.010 ms 0.010 ms

Options used:
-4 Use ip version 4 i.e. use Ipv4 -6 Use ip version 6 i.e. use Ipv6
-F Do not fragment packet.
=== * ===
tcpdump
 tcpdump is a packet sniffing and packet analyzing tool for a System Administrator to
troubleshoot connectivity issues in Linux.
 It is used to capture, filter, and analyze network traffic such as TCP/IP packets going
through system.
 It is many times used as a security tool as well. It saves the captured information in a
pcap file, these pcap files can then be opened through Wireshark or through the command
tool itself.
 tcpdump -i enp1s0
 Importatnt Options used:
o –c Specifice Number of Packets captured
o –e Print the link-level header on each dump line.

Example 1: tcpdump -c 5 -i enp1s0


tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp1s0, link-type EN10MB (Ethernet), capture size 262144
bytes 13:46:05.519973 IP 172.16.20.63.51082 > 239.255.255.250.1900:
UDP, length 173
13:46:05.521176 IP 172.16.20.107.42602 > dns.google.domain: 39493+ PTR?
250.255.255.239.in-addr.arpa. (46)
13:46:05.521196 IP 172.16.20.107.42602 > dns.google.domain: 39493+ PTR?
250.255.255.239.in-addr.arpa. (46)
13:46:05.521206 IP 172.16.20.107.42602 > 172.16.1.100.domain: 39493+ PTR?
250.255.255.239.in-addr.arpa. (46)
13:46:05.521400 IP 172.16.1.100.domain > 172.16.20.107.42602: 39493 NXDomain* 0/0/0
(46)
5 packets captured
17 packets received by
filter 7 packets dropped
by kernel

Operating System and Administration - 20CS42P - 68 -


Department of Computer Science and Engineering

10 – User Authentication

Work on user accounts:


useradd
 useradd is a command in Linux that is used to add user accounts to system.
 It is just a symbolic link to adduser command in Linux and the difference between both
of them is that useradd is a native binary compiled with system whereas adduser is a Perl
script which uses useradd binary in the background.
 When we run the ‘useradd‘ command in the Linux terminal, it performs the following
major things:
o It edits /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow files for the
newly created user accounts.
o Creates and populates a home directory for the new user.
o Sets permissions and ownerships to the home directory.
 Syntax:
o useradd -d /home/newusername –p passwordstring newusername
o This creates user with name newusername
 -d option will create directory for new user at /home directory
 -p option allows specifying password while creating user with the value
given in place of passwordstring
o User can change the password later by typing command
 passwd newusername
 This asks the user to enter the new password and confirm password
o

o
=== * ===

Create the new user account with their home directory.

Useraddd command does not set any valid password by default, and user cannot log in
until a password is set.To set the password user the following command:

passwd
 The passwd command changes passwords for user accounts.
 A normal user may only change the password for their own account, while the superuser
may change the password for any account.

Operating System and Administration - 20CS42P - 69 -


Department of Computer Science and Engineering

Verify the values in /etc/password:

=== * ===

userdel
 userdel command in Linux system is used to delete a user account and related files.
 This command basically modifies the system account files, deleting all the entries which
refer to the username LOGIN.
 Syntax: sudo userdel neuserw

Operating System and Administration - 20CS42P - 70 -


Department of Computer Science and Engineering

=== * ===
usermod

 usermod command or modify user is used to change the properties of a user.


 After creating a user we have to sometimes change their attributes like password or login
directory etc.
 To change the home directory of a user
o usermod -d /home/newfolder existinguser

 To change the group of a user


o usermod -g newgroupname existinguser

Groups: Groups in
Linux refer to the user groups. In Linux, there can be many users of a single system, (normal
user can take uid from 1000 to 60000, and one root user (uid 0) and 999 system users (uid 1 to
999)).

groupadd

 groupadd command is used to create a new user group.


 Syntax: groupadd newgroupname
 Every new group created is registered in the file “/etc/group“. To verify that the group has
been created, enter the command
o sudo tail /etc/group

Operating System and Administration - 20CS42P - 71 -


Department of Computer Science and Engineering

 Adding existing user to group // Explained once again in next topic


o usermod -g existinggroupname existinguser
=== * ===

groupmod

 groupmod command is used to modify or change the existing group.


 It can be handled by superuser or root user.
 Basically, it modifies a group definition on the system by modifying the right entry in the
database of the group.
 Syntax: groupmod [option] groupname
o Change the group name to new name.
o groupmod -n groupnewname groupoldname

=== * ===
Operating System and Administration - 20CS42P - 72 -
Department of Computer Science and Engineering

Work on Practice Session


gpasswd
 gpasswd command is used to administer the /etc/group and /etc/gshadow.
 gpasswd command assigns a user to a group with some security criteria.
 gpasswd command is called by a group administrator with a group name only which
prompts for the new password of the group.
 System administrators can use the -A option to define group administrator(s) and -M
option to define members.
 Syntax: gpasswd [option] group

Example:
 add the user to group:
o gpasswd -a existinguser existinggroup
 Deleting the created user from group geeks.
o gpasswd -d existinguser existinggroup
=== * ===

groupdel
 groupdel command is used to delete a existing group.
 It will delete all entry that refers to the group, modifies the system account files, and it is
handled by superuser or root user.
 Syntax: groupdel existinggroup

=== * ===

Operating System and Administration - 20CS42P - 73 -


Department of Computer Science and Engineering

LDAP server and client configuration:


Work on Practice Session
 Lightweight Directory Access Protocol (LDAP) is a standard protocol designed to
manage and access hierarchical directory information over a network.
 It can be used to store any kind of information, though it is most often used as a
centralized authentication system or for corporate email and phone directories.
 Use phpLDAPadmin, a web interface for viewing and manipulating LDAP information.
 Prerequisites: install apache and php

Step 1: Installing and Configuring the LDAP Server

 Install the LDAP server and some associated utilities.


 sudo apt-get update
 sudo apt-get install slapd ldap-utils
 During the installation,
o Enter administrator password for LD
o AP.
o Install and fill the fields asked during configuration:
 sudo dpkg-reconfigure slapd
There are quite a few new questions to answer in this process. Accept most of the defaults.
Questions are:
 Omit OpenLDAP server configuration? No
 DNS domain name?
 This option will determine the base structure of directory path. Read the message
to understand exactly how this will be implemented. This installation use
example.com .
 Organization name?
 For this guide, use example as the name of organization. (user may choose
anything which is appropriate. )
 Administrator password? enter a secure password twice
 Database backend? MDB
 Remove the database when slapd is purged? No
 Move old database? Yes
 Allow LDAPv2 protocol? No
At this point, LDAP server is configured and running. Open up the LDAP port on firewall so
external clients can connect:
 sudo ufw allow ldap

Test LDAP connection with ldapwhoami, which should return the username as:
 ldapwhoami -H ldap:// -x
 Output
o anonymous
o anonymous is the result expected, since running ldapwhoami without logging in
to the LDAP server. This means the server is running and answering queries.

Operating System and Administration - 20CS42P - 74 -


Department of Computer Science and Engineering

WEEK
Work 11 Session
on Practice

Top command is a performance monitoring program that can display CPU usage, memory usage, swap
memory, cache size, buffer size, process PID, users, commands, etc. The top command is used to
display all running and active real-time processes in an ordered list and update them regularly. It can
also sort the processes of running processes according to memory or CPU utilization.
The top command is useful for system administrators to monitor and take corrective measures when
needed top

The output displays the summary area (the dashboard with resource usage stats) and the task area (a list
of all processes).

3. iostat

The iostat command in Linux lets you monitor CPU utilization and I/O (input/output) statistics of all the
disks and file systems.

iostat commands are useful for changing system configuration to better balance the i/o load between
physical disks

Operating System and Administration - 20CS42P - 75 -


Department of Computer Science and Engineering

Work on Practice Session

cat /proc/cpuinfo

To see what type of processor/CPU your computer system has, use this Linux command:

$ cat /proc/cpuinfo

Cat /proc/meminfo

The ‘/proc/meminfo‘ is used by to report the amount of free and used memory (both physical and
swap) on the system as well as the shared memory and buffers used by the kernel.

Operating System and Administration - 20CS42P - 76 -


Department of Computer Science and Engineering

Work on Practice Session

free

free command which displays the total amount of free space available along with the amount of
memory used and swap memory in the system, and also the buffers used by the kernel.

df

To know amount of space consumed by a particular file system on your LINUX system or how much
space is available on a particular file system.

df command that displays the amount of disk space available on the file system containing each file
name argument

Operating System and Administration - 20CS42P - 77 -


Department of Computer Science and Engineering

Work on Practice Session

Suppose you have a file named kt.txt and you want to know the used disk space on the file system that contains this file
then you can use df in this case as:
// using df for a specific file //

$df kt.txt
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/the2 1957124 1512 1955612 1% /snap/core

dmesg command, shorthand for “diagnostic message”, is a Linux utility for displaying the messages
that flow within the kernel ring buffer. A kernel ring buffer is a logging mechanism from the system
startup which comes into play for diagnostics of a failed device.

Operating System and Administration - 20CS42P - 78 -


Department of Computer Science and Engineering

Work on Practice Session

Shutdown

The shutdown command in Linux is used to shutdown the system in a safe way. You can shutdown
the machine immediately, or schedule a shutdown using 24 hour format.It brings the system down in a
secure way. When the shutdown is initiated, all logged-in users and processes are notified that the
system is going down, and no further logins are allowed.
Only root user can execute shutdown command.
Syntax of shutdown Command
shutdown [OPTIONS] [TIME] [MESSAGE]

How to shutdown the system at a specified time


The following example will schedule a system shutdown at 05 A.M:
sudo shutdown 05:00
The following example will schedule a system shutdown in 20 minutes from now:
sudo shutdown +20

How to shutdown the system immediately

$shutdown now

How to reboot using shutdown


For reboot, the option is -r.
$shutdown –r now OR
$reboot

Operating System and Administration - 20CS42P - 79 -


Department of Computer Science and Engineering

Finding Linux system logs Work on Practice Session

All Ubuntu system logs are stored in the /var/log directory. Change into this directory in the terminal
using the command below:

$cd /var/log

You can view the contents of this directory by issuing the following command:
$ls /var/log

Essential system log files that may be present in the /var/log directory and what they contain:

 /var/log/syslog: stores general information about any global activity in the system.
 /var/log/auth.log: keeps track of all security-related actions (login, logout, or root user activity).
 /var/log/kern.log: stores information about events originating from the Linux kernel.
 /var/log/boot.log: stores system startup messages.
 /var/log/dmesg: contains messages related to device drivers.
 /var/log/faillog: keeps track of failed logins, which comes in handy when investigating attempted
security breaches.

halt command in Linux with examples


This command in Linux is used to instruct the hardware to stop all the CPU functions.
Basically, it reboots or stops the system

Operating System and Administration - 20CS42P - 80 -


Department of Computer Science and Engineering

Example 1: To cease all CPU Work


function on the system.
on Practice Session
$halt
Output:
Broadcast message from ubuntu@ubuntu
root@ubuntu:/var/log# (/dev/pts/0) at 10:15...
The system is going down for halt NOW.

init command in Linux with examples

init is parent of all Linux processes with PID or process ID of 1. It is the first process
to start when a computer boots up and runs until the system shuts down. init stands
for initialization

What is YUM?
YUM (Yellowdog Updater Modified) is an open-source command-line as well as
graphical-based package management tool for RPM (RedHat Package Manager)
based Linux systems.
It allows users and system administrators to easily install, update, remove or search
software packages on a system

Operations of YUM
YUM can implement operations like:

o Listing installed packages


o Listing existed packages
o Updating available installed packages
o Removing packages
o Installing packages

The yum command in Linux - A Complete Reference - LinuxForDevices

RPM (RPM Package Manager)

Operating System and Administration - 20CS42P - 81 -


Department of Computer Science and Engineering

RPM is a popular package management tool in Red


Work on Practice Hat Enterprise Linux-based
Session
distros. Using RPM, you can install, uninstall, and query individual software packages.
Still, it cannot manage dependency resolution like YUM. RPM does provide you useful
output, including a list of required packages. An RPM package consists of an archive
of files and metadata. Metadata includes helper scripts, file attributes, and
information about packages.

RPMmaintains a database of installed packages, which enables powerful and fast


queries

Operating System and Administration - 20CS42P - 82 -


Department of Computer Science and Engineering

Week
Work on 12 – Session
Practice

Domain Name Service (DNS)

Domain Name Service (DNS) is an internet service that maps IP addresses to fully
qualified domain names (FQDN) and vice versa.
• BIND stands for Berkley Internet Naming Daemon.
• BIND is the most common program used for maintaining a name server on Linux. •

Sudo apt-get update


Sudo apt install –y bind*

Configure DNS Server in Linux

1. Network Information
2. Install Bind
3. Configure Cache NameServer
4. Test the Cache NameServer
5. Configure Primary/Master Nameserver
6. Build the Forward & Reverse Resolution for Primary/Master NameServer
7. Test the DNS server

FTP server on LINUX and transfer files to demonstrate its working.

ftp

ftp is the user interface to the Internet standard File Transfer Protocol. The program allows a
user to transfer files to and from a remote network site.

Examples below are to upload and download files using ftp service.
Prerequisites:
 Install Ftp (FTP-Client) and vsftpd (FTP-Server) using Software Manager.
 Change /etc/vsftpd.conf file to enable write permission (other settings can be done
according to requirement.
◦ nano /etc/vsftpd.conf
 Search for # write_enable=YES (around 30th line in that file)
 Uncommnent and Save and Exit
 Restart the Service: systemctl restart vsftpd

Example 1: Get the connection to ftp


 ftp 172.16.20.116 21
o Enter user name and password for connection, this will take user to ftp utility and
then issue ftp set of command
o For more command take the help by issuing? And to quit utility type quit
Operating System and Administration - 20CS42P - 83 -
Department of Computer Science and Engineering

command.
Work on Practice Session
Example 2: Download the file from ftp server
 get a.txt /home/admincs/Desktop/test.txt
o will download the file a.txt from ftp server to current user Desktop with file
name test.txt

Example 3: Upload the file from server


 put /home/admincs/index.html test.html
o will upload the file index.html from current (local /home/admincs) user to
remote ftp server with name test.html
Example 4: User can issue commands like mkdir, cd, rmdir etc linux basic commands to
control the remote server machine. (For more commands go to ? Command and man ftp
command)

Apache Server Setup

To install Apache, install the latest meta-package apache2 by running:

sudo apt update


sudo apt install apache2

After letting the command run, all required packages are installed and we can test it out by
typing in our IP address for the web server.

After letting the command run, all required packages are installed and we can test it out by
typing in our IP address for the web server.

If you see the page above, it means that Apache has been successfully installed on your server

To change default page from from normal page to custom page create html
file in /etc/var/html/test.html
Operating System and Administration - 20CS42P - 84 -
Department of Computer Science and Engineering

<html> Work on Practice Session


<head>
<title> Ubuntu rocks! </title>
</head>
<body>
<p> I'm running this website on an Ubuntu Server server!
</body>
</html>

Now go to /etc/apache2/mods-enebled directory and edit configuration


file
$nano dir.conf
Change index.html page to your page
Open browser and type localhost , it displays your created html page

3. Creating Your Own Website


By default, Apache comes with a basic site (the one that we saw in the previous step) enabled. We can
modify its content in /var/www/html or settings by editing its Virtual Host file found
in /etc/apache2/sites-enabled/000-default.conf.

We can modify how Apache handles incoming requests and have multiple sites running on the same
server by editing its Virtual Hosts file.

Today, we’re going to leave the default Apache virtual host configuration pointing
to www.example.com and set up our own at gci.example.com.

So let’s start by creating a folder for our new website in /var/www/ by running

sudo mkdir /var/www/gci/


We have it named gci here but any name will work, as long as we point to it in the virtual hosts
configuration file later.

Now that we have a directory created for our site, lets have an HTML file in it. Let’s go into our newly
created directory and create one by typing:

cd /var/www/gci/
nano index.html
Paste the following code in the index.html file:

<html>
<head>
<title> Ubuntu rocks! </title>
</head>
<body>
Operating System and Administration - 20CS42P - 85 -
Department of Computer Science and Engineering

<p> I'm running this website


Workononan Ubuntu
Practice Server server!
Session
</body>
</html>

Setting up the VirtualHost Configuration File


We start this step by going into the configuration files directory:

cd /etc/apache2/sites-available/
Since Apache came with a default VirtualHost file, let’s use that as a base. (gci.conf is used here to
match our subdomain name):

sudo cp 000-default.conf gci.conf


Now edit the configuration file:

sudo nano gci.conf


We should have our email in ServerAdmin so users can reach you in case Apache experiences any
error:

ServerAdmin yourname@example.com
We also want the DocumentRoot directive to point to the directory our site files are hosted on:

DocumentRoot /var/www/gci/
The default file doesn’t come with a ServerName directive so we’ll have to add and define it by adding
this line below the last directive:

ServerName gci.example.com
This ensures people reach the right site instead of the default one when they type
in gci.example.com.

Now that we’re done configuring our site, let’s save and activate it in the next step!

Activating VirtualHost file


After setting up our website, we need to activate the virtual hosts configuration file to enable it. We do
that by running the following command in the configuration file directory:

sudo a2ensite gci.conf


You should see the following output

Enabling site gci.


To activate the new configuration, you need to run:
service apache2 reload
root@ubuntu-server:/etc/apache2/sites-available#
To load the new site, we restart Apache by typing:

service apache2 reload

Operating System and Administration - 20CS42P - 86 -


Department of Computer Science and Engineering

End result Work on Practice Session

Now is the moment of truth, let’s type our host name in browser. Hooray!

13 – Storage Management

Basic Commands for Storage Partitions


fdisk
 fdisk is used to check the partitions on a disk.
 The fdisk command can display the partitions and details like file system type.
 However it does not report the size of each partitions.
o sudofdisk -l
 Each device is reported separately with details about size, seconds, id and individual
partitions.
sfdisk
 sfdisk utility purpose similar to fdisk, but with more features.
 It can display the size of each partition in MB.
o sudosfdisk -l -uM
cfdisk
 cfdisk is a linux partition editor with an interactive user interface based on ncurses.
 It can be used to list out the existing partitions as well as create or modify them.
 An example of how to use cfdisk to list the partitions.

 cfdisk works with one partition at a time.


Operating System and Administration - 20CS42P - 87 -
Department of Computer Science and Engineering

o So if user need to see the details of a particular disk, then pass the device name to
cfdisk. Work on Practice Session
o sudocfdisk /dev/sdb
parted
 partedutility is to list out partitions and modify them if needed.
o sudo parted -l
df
 df is not a partitioning utility, but prints out details about only mounted file systems.
 The list generated by df even includes file systems that are not real disk partitions.
o df -h
o df -h | grep ^/dev
 Note:df shows only the mounted file systems or partitions and not all.

Logical Volume Management (LVM)

Installation command

Verify Package Installation

Operating System and Administration - 20CS42P - 88 -


Department of Computer Science and Engineering

Check Utilities Version Work on Practice Session

Operating System and Administration - 20CS42P - 89 -

You might also like