Chapter Five Security PDF
Chapter Five Security PDF
(ITec4112)
Chapter Five
Security
1
Operating System
What is an Operating System?
A program that acts as an intermediary between a user of
a computer and the computer hardware.
What is the purpose of an operating system?
To provide an environment in which a user can execute
programs.
What are the goals of an Operating System?
The primary goal of an Operating System is to make the
computer system convenient to use.
The secondary goal is to make the computer system
efficient to use.
2
Components of OS
Process Management
Memory Management
I/O Management
File System
Management
User Interface
Unix/Linux-like Systems Vs Windows Systems
4
Linux Distributions and UIs
A Linux distribution is an operating system based on a Linux
Kernel
Components
Kernel
Package Management
Libraries
Other software
A distribution is built around a package management system
5
Linux Distros
Debian – non-commercial; Mandriva Linux
developed by community OpenSUSE
Knoppix Arch Linux
Linux Mint
Gentoo
Ubuntu
Kubuntu Chrome OS
Linux Mint Chromium OS
Trisquel Slackware
Elementary OS
Fedora – community
distribution sponsored by Red
Hat
Red Hat Enterprise Linux
(RHEL)
CentOS
Oracle Linux
Scientific Linux
Linux Distros
Linux Operations Review
File system Hierarchy
When we compare file system in Windows and Linux, in Microsoft
Windows, files are stored in folders on different data drives like C:
D: E:
But, in Linux, files are ordered in a tree structure starting with the
root directory.
This root directory can be considered as the start of the file system,
and it further branches out various other subdirectories.
The root is denoted with a forward slash ‘/’.
A general tree file system on your UNIX may look like this.
8
Linux Operations Review
Single-rooted hierarchy and Extensible File systems
Linux uses single rooted, inverted tree like File System Hierarchy
[FHS]
/ –This is top level directory
It is parent directory for all other directories
It is called as ROOT directory
It is represented by forward slash (/)
9
Linux Operations Review
Extensible File systems
Linux file system has a hierarchal file structure as it contains a root
directory and its subdirectories.
All other directories can be accessed from the root directory.
A partition usually has only one file system, but it may have more
than one file system.
Linux file system contains two-part file system software
implementation architecture
10
Directory Structure
The directories help us to store the files and locate them
when we need them.
Also, directories are called folders
Directories can be organized in a tree-like hierarchy in Linux
and several other operating systems
The directory structure of Linux is well-documented and
defined in the Linux FHS (Filesystem Hierarchy Standard).
11
Directory Structure
The below table gives a very short standard, defined, and
well-known top-level Linux directory list and their purposes:
/ (root filesystem): It is the top-level filesystem directory. It must
include every file needed to boot the Linux system before another
filesystem is mounted.
/boot: It includes the static kernel and bootloader configuration and
executable files needed to start a Linux computer.
/bin: This directory includes user executable files.
/dev: It includes the device file for all hardware devices connected to
the system.
/etc: It includes the local system configuration files for the host
system.
/lib: It includes shared library files that are needed to start the system.
/home: The home directory storage is available for user files.
/mnt: It is a temporary mount point for basic filesystems that can be
used at the time when the administrator is working or repairing a
filesystem.
12
Directory Structure
top-level Linux directory list and their purposes:
/media: A place for mounting external removable media devices like
USB thumb drives that might be linked to the host.
/opt: It contains optional files like vendor supplied application
programs that must be placed here.
/root: It's the home directory for a root user. Keep in mind that it's not
the '/' (root) file system.
/tmp: It is a temporary directory used by the OS and several programs
for storing temporary files.
/sbin: These are system binary files. They are executables utilized for
system administration.
/usr: They are read-only and shareable files, including executable
libraries and binaries, man files, and several documentation types.
/var: Here, variable data files are saved. It can contain things such as
MySQL, log files, other database files, email inboxes, web server data
files, and so on.
13
Types of Linux File System
When we install the Linux operating system, Linux offers
many file systems such as Ext, Ext2, Ext3, Ext4, JFS,
ReiserFS, XFS, btrfs, and swap.
Ext, Ext2, Ext3 and Ext4 file system
The file system Ext stands for Extended File System.
Ext2 is the first Linux file system that allows managing two terabytes
of data.
Ext3 is developed through Ext2; it is an upgraded version of Ext2 and
contains backward compatibility. The major drawback of Ext3 is that it
does not support servers
Ext4 file system is the faster file system among all the Ext file
systems.
It is a very compatible option for the SSD (solid-state drive) disks,
14
Types of Linux File System…
JFS File System
JFS stands for Journaled File System, and it is developed by IBM
for Unix.
It is an alternative to the Ext file system.
It can also be used in place of Ext4, where stability is needed with few
resources.
It is a handy file system when CPU power is limited.
ReiserFS File System
ReiserFS is an alternative to the Ext3 file system.
It has improved performance and advanced features.
In the earlier time, the ReiserFS was used as the default file system in
SUSE Linux, but later it has changed some policies, so SUSE
returned to Ext3.
XFS File System
XFS file system was considered as high-speed JFS, which is
developed for parallel I/O processing.
NASA still using this file system with its high storage server (300+
15
Terabyte server).
Types of Linux File System…
Btrfs File System
Btrfs stands for the B tree file system.
It is used for fault tolerance, repair system, fun administration,
extensive storage configuration, and more.
It is not a good suit for the production system.
Swap File System
The swap file system is used for memory paging in Linux operating
system during the system hibernation.
A system that never goes in hibernate state is required to have swap
space equal to its RAM size.
16
17
Linux File and Directory Permissions
File ownership is an important component of Linux that
provides a secure method for storing files.
Every file in Unix has the following attributes −
Owner permissions − The owner's permissions determine what
actions the owner of the file can perform on the file.
Group permissions − The group's permissions determine what
actions a user, who is a member of the group that a file belongs to,
can perform on the file.
Other (world) permissions − The permissions for others indicate
what action all other users can perform on the file.
The letters rwx represent different permission levels:
Permission Files Directories
r can read the file can ls the directory
w can write the file can modify the directory's contents
x can execute the file can cd to the directory
18
Linux File and Directory Permissions
For example, if you enter:
ls -l
You should see output similar to the following:
-rw-r--r-- 1 user1 group1 62 Jan 15 16:10 myfile.txt
drwxr-xr-x 2 user1 group1 2048 Jan 15 17:10 Example
The first character in each line indicates whether the listed
object is a file or a directory. Directories are indicated by a
(d); the absence of a d at the beginning of the first line
indicates that myfile.txt is a regular file.
19
Linux File and Directory Permissions
Note the multiple instances of r, w, and x.
These are grouped into three sets that represent different
levels of ownership:
Owner or user permissions: After the directory (d) slot,. -rw-r--r--,
the owner permissions are rw-, indicating that the owner can read
and write to the file but can't execute it as a program.
In the example drwxr-xr-x, the owner permissions are rwx, indicating
that the owner can view, modify, and enter the directory.
Group permissions: The second rwx set indicates the group
permissions. In the fourth column of the example above, group1 is
the group name. In the example -rw-r--r--, group members can only
read the file.
In the example drwxr-xr-x, group members can view as well as enter
the directory.
Other permissions: The final rwx set is for "other" (sometimes
referred to as "world"). This is anyone outside the group. In both
examples above, these are set to the same permissions as the group.
20
File and directory permisions
File permissions for (-rw-rw-r--)
21
22
User and group account
User account
Users are identified by User Accounts
Every user account is identified by User ID (UID)
The kernel uses the UID rather than the username
Other member could also join the group and the user John
could also join other groups.
23
Users and Group account
User accounts
User
Name
UID
Group(GID)
Password file
Shadow file
Password file
/etc/passwd
This file contains the user account information for your system.
Ordinary ASCII text file
Master list of information about users
Password information not stored
Entry
Username:Password:UID:GID:User-Info:Home_Directory:Default_Shell 24
User and group account
User accounts…
Username: The Username field simply identifies the username
the user will supply when logging in to the system
Password: This is a legacy field. At one time, the user’s
password was stored in encrypted form in this field in the
passwd file.
However, for security reasons, the password has been
Password file…
User name : alebachew
Public
X
Holds user encoded password in the absence of shadow password
file
UID
User identification number: 1000
Administrative (root):0
Regular :>500
Service :1 to 500
GID: 1000
Users primary group membership
26
User and group account…
Password file …
User information : alebachew
Contains information such as a user’s full name
Home directory
Initial working directory
Login shell
The program used as command interpreter for the user
/etc/shell
27
User and group account…
Shadow password file
Stored in /etc/shadow
Stores encrypted passwords
Could be accessed by only superuser
Editing by hand is not recommended
Entry
Username: Encoded-
password:Last_Modified:Min_Days:Max_Days:Days_Warn:Disabled_Da
ys:Expire:flag
Username This is the user’s login name from /etc/passwd.
Password This is the user’s password in encrypted format
Last_Modified
Stores the date of the last password change
Expressed as the number of days since Jan 1,1970
0 forces a password change on next login
28
User and group account…
Shadow password file…
Minlife
Prevents a user from changing back to the old password
Specify the minimum number of days required before a password
can be changed.
0 disables this feature
Maxlife
Specifies the maximum number of days that the user is allowed to
keep the same password
It is set to high value (99999 days) to disable this feature
Effectively, this means a password isn’t required
Days_Warn
This field displays the number of days prior to password
expiration that the user will be warned of the pending
expiration.
Leave blank to disable
29
User and group account…
Shadow password file…
Inactive/Disabled_Days
This field displays the number of days to wait after a
password has expired to disable the account.
Days after the password expires that the account will be
automatically disabled
Set to -1 to disable
Expire
Date on which the account expires and will be automatically
disabled
It is set to a null value, indicating the account never expires.
30
User and group Account…
Group Account
Enables users to share files and system resource
31
User and group Account…
Entry in /etc/group
Each record is composed of the following four fields:
Group-name:Password:GID:Users
Group-name
Specifies the name of the group.
Password (*)
Specifies the group password.
GID
Specifies the group ID (GID) number of the group.
Users
Lists the user name of members of the group.
Names are separated by commas
No space should be appear within the list
Most Unix systems impose a limit of 16 (sometimes 32 ) group
memberships per user
32
User and group Account…
Group Shadow file
As with /etc/shadow, each line in /etc/gshadow represents a record
for a single group.
Each record is composed of the following fields:
Group_Name:Encoded-Password:Group_Admins:Group_Members
Encoded-Password (*)
Group-admins
Group-Member/Additional-Users
Used by newgrp
Username
UID
Primary group
Login shell
Default is /bin/bash
$ chsh –s shellPath username
$ sudo chsh -s {shell-name-here} {user-name-here}
-$ chsh -s /bin/bash
-$ chsh -s /bin/bash Abraham
/bin/false - Disables access to an account
34
User and group account…
Defining password
$ passwd userName
Traditionally 8 chars
Linux allows more
Creating Home directory
Set permision and ownership
Example
Mkdir /home/abraham
Chown abraham./home/araham
Chmod 755 /home/abraham
35
Creating and Managing User Accounts
There are two approaches to creating user accounts and groups.
There is a GUI tool, the User Manager, and
There are command line programs.
Defining user accounts
Using Utilities
useradd
passwd
usermod
userdel
userdd is the command used to create a new user for the
Linux system.
Syntax: useradd options username
Example (1): useradd amanuel
Amanuel account is created using the default parameters contained in
the following configuration files: /etc/default/useradd
Example (2): useradd -e 2023-05-30 amanuel
36
Options
–c Includes the user’s full name.
–e Specifies the date when the user account will be disabled. Format the
date as yyyy-mm-dd.
–f Specifies the number of days after password expiration before the
account is disabled. Use a value of –1 to disable this functionality,
e.g., useradd –f –1 amanuel.
–g Specifies the user’s default group.
-G Specifies additional groups that the user is to be made a member of.
–M Specifies that the user account be created without a home directory.
–m Specifies the user’s home directory.
–p Specifies the user’s password.
37
Using Passwd
The passwd utility is used to change an existing user’s password
You can find out this information using the –S option with passwd.
Syntax: passwd username
Example: passwd –S amanual
38
Using usermod
From time to time, you will need to modify an existing user account.
The syntax for usermod is very similar to that used by useradd.
Syntax:
usermod options username
options
-c Edits the user’s full name.
–e Sets the date when the user account will be disabled. Format the date as yyyy-mm-dd.
–f Sets the number of days after password expiration before the account is disabled. Use a
value of –1 to disable this functionality.
–g Sets the user’s default group.
–G Specifies additional groups that the user is to be made a member of.
-l Changes the username.
–L Locks the user’s account. This option invalidates the user’s password.
–m Sets the user’s home directory.
–p Sets the user’s password.
–s Specifies the default shell for the user.
–u Sets the UID for the user.
–U Unlocks a user’s account that has been locked.
39
Using userdel
The userdel command is used to delete user accounts.
This can but does not have to delete the associated files (the user’s home
directory, temporary files, and mail file).
Syntax: userdel username
Example: userdel Amanuel
If you do want to remove the home directory when you delete the
user,
you need to use the –r option in the command line.
Example: userdel –r Amanuel, will remove the account and delete
his home directory.
40
Managing groups
Using utilities
Using groupadd
Using groupmod
Using groupdel
Groupadd
Syntax:
groupadd options groupname
groupadd –r student
Options:
–g Specifies a GID for the new group.
–p Specifies a password for the group.
–r Specifies that the group being created is a system group.
41
Managing groups
Using groupmod
To modify a group, including adding users to the group
42
Managing groups
Using groupdel
There are no options; instead it is simply
groupdel groupname
The group is deleted from the /etc/group and /etc/gshadow files,
and the group is removed from any user’s list of groups as stored in
/etc/passwd.
Example: groupdel student
43
Password Aging
Allows you to specify a time period during which a password
is valid
Has a benefit of ensuring
passwords are changed regularly
44
45
Password aging …
using /etc/login.defs
Set defaults for all users in the file
46
Disabling user account
Lock the account
#passwd –l username
Locks the user form logging into the host using his/her password
47
Deleting user account
Manually
Remove home directory
Change file ownership
Remove account entry from password and shadow files
Take backup
Change all other passwords the users knows
Not recommended
Userdel
Delete user account permanently
directory
48
Managing files and folder permission
Managing ownership
Managing permissions
49
What Are Permissions
Permissions are a mechanism to support operating system
protection.
Protection ensures that users do not misuse system resources
(CPU, memory, network, partitions, directories and files).
Permissions specify who can access a file or directory and the
types of access.
In Linux, permissions are controlled at three levels:
1- Owner (called user, or ‘u’ for short)
2- Group (‘g’ for short)
3- The rest of the world (called other, or ‘o’ for short)
Each level of access provides:
Read: for a file, it can be viewed or copied. For a
directory, the directory’s contents can be viewed
by ls.
Write: for a file, it can be overwritten (e.g., using
save as). for a directory, files can be written there.
Execute: for a file, it can be executed (this is
necessary for executable programs and shell
scripts). for a directory, a user can cd into it
64