0% found this document useful (0 votes)
4 views68 pages

01 Introduction To Linux and Systems Administration

The document provides an introduction to Linux, describing it as an open-source, Unix-like operating system kernel created by Linus Torvalds in 1991. It discusses the ownership of Linux, its open-source nature, and the various distributions available, such as Ubuntu and Red Hat. Additionally, it outlines the architecture of Linux, including the kernel, shell, and utilities, and highlights its widespread use across different devices and server environments.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views68 pages

01 Introduction To Linux and Systems Administration

The document provides an introduction to Linux, describing it as an open-source, Unix-like operating system kernel created by Linus Torvalds in 1991. It discusses the ownership of Linux, its open-source nature, and the various distributions available, such as Ubuntu and Red Hat. Additionally, it outlines the architecture of Linux, including the kernel, shell, and utilities, and highlights its widespread use across different devices and server environments.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 68

Systems & Network Administration

CT106-3-2 (Version VE1)

Chapter 01
Introduction to Linux and Systems Administration
Introduction to Linux

“Linux at the Command Line”


What is Linux?

• It’s an Operating System


• Linux is an open-source, Unix-like
operating system kernel.
• Initially created by Linus Torvalds in
1991, it serves as the foundation for
various operating systems.
• Linux is widely used across devices
such as servers, desktops, smartphones,
and embedded systems.
• Popular Linux distributions include
Ubuntu, Fedora, and Debian, and it
allows users to modify and redistribute
the software freely.

Module Code & Module Title Slide Title SLIDE 3


What is Linux?

• Linux is the best-known and


most-used open-
source operating system.

Module Code & Module Title Slide Title SLIDE 4


WHAT is CORN and Kernel?

• The term “kernel” in Linux has an


interesting etymology. It’s a modernization
of the Old English word “cyrnel,” which
means “seed.”
• In that context, a kernel is something from
which the rest grows. You could also think
of it as a “core.” Botanically speaking, a
“core” contains seeds (or “kernels”). Since
the rest of the operating system grows
from the kernel, the term makes sense.
Interestingly, the German word “Kern”
shares a similar origin and meaning. It
refers to the core or fundamental part of
something, much like the kernel in Linux

• Corn kernels are the fruits of corn (called


maize in many countries).

Module Code & Module Title Slide Title SLIDE 5


Who “owns” Linux?

• By virtue of its open-source licensing, Linux is freely available to anyone. However, the
trademark on the name “Linux” rests with its creator, Linus Torvalds. The source code for
Linux is under copyright by its many individual authors, and licensed under the General
Public License v2 (GPLv2) license.
• The term “Linux” technically refers to just the Linux kernel. Most people refer to the
entire operating system as "Linux" because to most users an OS includes a bundle of
programs, tools, and services (like a desktop, clock, an application menu, and so on).
• Some people, particularly members of the Free Software Foundation, refer to this
collection as GNU/Linux, because many vital tools included are GNU components.
• However, not all Linux installations use GNU components as a part of the operating
system: Android, for example, uses a Linux kernel but relies very little on GNU tools.
• Released 25 years ago , OPEN SOURCE , NOT proprietorship software like Microsoft.

Module Code & Module Title Slide Title SLIDE 6


What is OPEN SOURCE?

1. Open Source: Linux’s code is open source, released under the GNU General Public
License (GPL). This means:
1. You can download and install Linux for free.
2. Administrators can study and customize the OS according to their needs.
2. Customizability: Linux is incredibly customizable because it offers various
distributions (distros) with different software options. You can choose core
components, swap out applications, and tailor it to your preferences.
3. Widespread Use: Linux powers 70 percent of the world servers. It’s also found
in Android devices, Chromebooks, digital storage, cameras, and even cars.
4. Ownership: The name “Linux” is trademarked by its creator, Linus Torvalds. The
term technically refers to just the Linux kernel, but most people refer to the
entire OS as “Linux” or GNU/Linux due to the vital GNU components included.

Module Code & Module Title Slide Title SLIDE 7


Global Usage ?

1. Global usage share for operating systems:


a. Windows: Windows is the dominant desktop operating system, with around 70-75% of the market
share.
b. macOS: Apple's macOS is generally in the 15-20% range.
c. Linux: Linux typically holds around 2-3% of the desktop market. However, its usage is much
higher on servers, embedded systems, and IoT devices.
d. Other OSes: Other OSs like Chrome OS and BSD variants making up less than 5%.
2. Global Server OS usage:
a. Linux: Linux is the most widely used operating system in server environments, with an estimated
market share of around 70-75%.
b. Windows Server: Windows Server holds about 15-20% of the global server market share.
c. Other OSes: The remaining 5-10% of server usage is typically split between various other
operating systems. Unix variants (like AIX, HP-UX, and Solaris), BSD, hods around 5 to 10%.

Module Code & Module Title Slide Title SLIDE 8


What is the difference between Unix & Linux?

• You may have heard of Unix, which is an operating system developed in the 1970s at Bell
Labs by Ken Thompson, Dennis Ritchie, and others. Unix and Linux are similar in many
ways, and in fact, Linux was originally created to be indistinguishable from Unix.
• Both have similar tools for interfacing with the system, programming tools, filesystem
layouts, and other key components. However, not all UNIXs are free and open source.
• Linux, is open-source and free to use, modify, and distribute under the GNU General
Public License. Examples of Linux include Fedora, Debian, Red Hat, Ubuntu, and Android.
• Unix is proprietary, owned by various organizations (like IBM, Oracle, or AT&T), and
requires a paid license for usage. Examples of Unix include IBM AIX, Darwin, Solaris, HP-
UX, and macOS X.
• Over the years, a number of different operating systems have been created that
attempted to be “unix-like” or “unix-compatible,” but Linux has been the most successful,
far surpassing its predecessors in popularity.
Module Code & Module Title Slide Title SLIDE 9
Windows vs Linux

Module Code & Module Title Slide Title SLIDE 10


Disadvantage

Linux is used in the following ways: Server OS for web servers, database servers, file servers, email
servers and any other type of shared server. Supercomputers. Designed to support high-volume and
multithreading applications, Linux is well-suited for all types of server applications.

Module Code & Module Title Slide Title SLIDE 11


Linux + GNU Utilities = Free Unix

• a set of small programs


• Linux is an O/S core written by Richard
written by Linus Torvalds Stallman and others. They
are the GNU utilities.
and others http://www.gnu.org/

Module Code & Module Title Slide Title SLIDE 12


Linux Has Many Distributions (distro)
Linux Distributions (distro) Family
WHAT is GNU?
• The word "gnu" is consistently pronounced with two
syllables as g-noo.
• GNU is an umbrella term for a collection of free and open-
source software tools that can be used to create an
operating system.
• GNU stands for "GNU's Not Unix". It's often considered the
first recursive acronym, where one of the letters in the
acronym stands for the acronym itself.
• GNU includes a variety of core software tools, such as
programs and utilities. The GNU Core Utilities are one
example of these tools.
• When used to create an operating system, the resulting
operating system is also called GNU.
• GNU/Linux
– The Linux kernel was integrated into GNU to create the GNU/Linux
operating system. GNU/Linux is an operating system made entirely from
free software.

Module Code & Module Title Slide Title SLIDE 15


Package Managers
• In Linux, a package manager is a tool that automates the process of installing, updating, configuring, and
removing software packages (programs or libraries) from a system.
• Linux distributions use package managers to handle software installation and management in a
consistent and organized way. A package typically contains the compiled program code, configuration
files, and other resources needed to run the software.

Module Code & Module Title Slide Title SLIDE 16


Linux Has Many Distributions

• Ubuntu is a Linux distribution


based on Debian and composed
mostly of free and open-source
software.
• Ubuntu is officially released in
three editions: Desktop, Server,
and Core for Internet of things
devices and robots.
• All of the editions can run on a
computer alone, or in a virtual
machine.
• Latest release: Oracular Oriole
24.10 / 10 October 2024

Module Code & Module Title Slide Title SLIDE 17


Linux Has Many Distributions
• Red Hat belongs to the RPM-based family of Linux distributions. RPM stands
for Red Hat Package Manager, and it’s a package management system used by
various Linux distributions.
• Red Hat Linux, as well as its successor, Red Hat Enterprise Linux (RHEL), utilize
RPM for software installation, updates, and dependency management. Fedora,
which is also developed by Red Hat, serves as the upstream source for RHEL,
while CentOS Stream is another downstream variant of RHEL.
• Red Hat Linux, RHEL is designed for stability, security, and long-term
support. It’s widely used in server environments, cloud deployments, and
mission-critical applications
• The latest Red Hat Enterprise Linux (RHEL) release is 9.5, which was released
on November 12, 2024

Module Code & Module Title Slide Title SLIDE 18


Concepts of upstream and downstream in the
context of software development
• The upstream refers to the original source or foundation of a software
project. It’s where development begins.
• In the case of Red Hat Enterprise Linux (RHEL), the upstream source
is Fedora. Fedora is a community-driven Linux distribution
sponsored by Red Hat.
• Developers work on new features, enhancements, and bug fixes in
Fedora. These changes serve as the testing ground for future RHEL
releases.
• The downstream refers to derivative projects or distributions that are
based on the original source.
• In the context of RHEL, CentOS Stream is a downstream variant.
• CentOS Stream receives updates and changes from RHEL after
they’ve been tested and stabilized in Fedora.
• CentOS Stream provides a more predictable and continuous flow of
updates compared to the traditional CentOS (which used to be a
downstream clone of RHEL).

Module Code & Module Title Slide Title SLIDE 19


Linux Usage

• Linux-powered web servers when using the internet. For the delivery of web
content, search results, and online purchasing, platforms like Google, Facebook,
and Amazon significantly rely on Linux servers.
• Household appliances, automotive entertainment systems and network file system
appliances. Network OS for routers, switches, domain name system servers, home
networking devices and more.

Module Code & Module Title Slide Title SLIDE 20


Let the Linux Lab Begin!

You getting ready for


Lab Action

The Ideal Lab Facility

Module Code & Module Title Slide Title SLIDE 21


Linux Architecture
It illustrates the basic architecture of a Linux operating system,
showing its layered structure. Each layer builds on the previous
one, providing abstraction and functionality for the user.
• Hardware (Innermost Layer): The physical components of a
computer, like the CPU, memory, and storage. The hardware is
at the core of the system, providing the foundation for
everything.
• Kernel: This layer is directly on top of the hardware and acts
as an interface between hardware and software. It is used to
manage communication with hardware devices, organizes and
manages data storage and allows multiple processes to run
simultaneously.
• Shell: The interface between the user and the kernel. Shells
interpret commands from the user and pass them to the kernel
for execution. Different types of shells such as: sh (Bourne
shell), csh (C shell), bash (Bourne again shell), ksh (Korn shell),
tcsh (Tenex C shell)
• Utilities (Outermost Layer): These are various command-line
tools and programs that allow users to perform specific tasks.

Module Code & Module Title Slide Title SLIDE 22


Linux Architecture
This diagram provides another view of the Linux Operating
System architecture, showing how its different components
interact.
• Hardware is accessed and managed by the Kernel. It
represents the physical components of the computer such
as CPU, RAM & I/O.
• Kernel modules allow the system to interact with specific
hardware or extend features.
• Kernel is the core of the Linux operating system that
manages system resources (CPU, memory, devices), process
scheduling and communication
• System libraries act as intermediaries, enabling user
applications to communicate with the kernel. Its function
is to access system call, handle I/O operations, managing
memory and file handling.
• User space contains the tools and processes (system
software, user processes, user utilities and compliers) users
interact with, all running on top of the kernel.

Module Code & Module Title Slide Title SLIDE 23


Kernel vs Shell vs Bash
• Kernel: The kernel is the core of the operating system. It’s
a software residing in memory that tells the CPU what to
do. It manages resources such as memory, processes, and
I/O devices. The kernel is the main component of a Linux
operating system (OS) and is the core interface between a
computer’s hardware and its processes.

• Shell: A shell is a user program that provides an interface


for the user to use operating system services. It accepts
human-readable commands from users and converts
them into something which the kernel can understand. It
is a command language interpreter that executes
commands read from input devices such as keyboards or
from files.
𝑳𝒊𝒏𝒖𝒙 𝑺𝒉𝒆𝒍𝒍𝒔 (𝑾𝒉𝒆𝒏 𝒕𝒐 𝒖𝒔𝒆)?
• Bash: Bash (Bourne Again SHell) is a command-line 𝑏𝑎𝑠ℎ: 𝑆𝑡𝑎𝑛𝑑𝑎𝑟𝑑 𝐿𝑖𝑛𝑢𝑥 𝑠ℎ𝑒𝑙𝑙; 𝑔𝑟𝑒𝑎𝑡 𝑓𝑜𝑟 𝑔𝑒𝑛𝑒𝑟𝑎𝑙 𝑢𝑠𝑒 𝑎𝑛𝑑 𝑠𝑐𝑟𝑖𝑝𝑡𝑖𝑛𝑔.
interpreter or Unix Shell widely used in GNU/Linux 𝑧𝑠ℎ: 𝐼𝑑𝑒𝑎𝑙 𝑓𝑜𝑟 𝑝𝑜𝑤𝑒𝑟 𝑢𝑠𝑒𝑟𝑠 𝑤ℎ𝑜 𝑤𝑎𝑛𝑡 𝑐𝑢𝑠𝑡𝑜𝑚𝑖𝑧𝑎𝑡𝑖𝑜𝑛 𝑎𝑛𝑑 𝑎𝑑𝑣𝑎𝑛𝑐𝑒𝑑
Operating System. It is a default login shell for most 𝑓𝑒𝑎𝑡𝑢𝑟𝑒𝑠.
Linux distributions. Bash is a command interpreter. It is a 𝑠ℎ: 𝐵𝑒𝑠𝑡 𝑓𝑜𝑟 𝑙𝑒𝑔𝑎𝑐𝑦 𝑠𝑐𝑟𝑖𝑝𝑡𝑠 𝑎𝑛𝑑 𝑐𝑟𝑜𝑠𝑠-𝑝𝑙𝑎𝑡𝑓𝑜𝑟𝑚 𝑐𝑜𝑚𝑝𝑎𝑡𝑖𝑏𝑖𝑙𝑖𝑡𝑦.
𝑐𝑠ℎ: 𝑆𝑢𝑖𝑡𝑎𝑏𝑙𝑒 𝑓𝑜𝑟 𝐶 𝑝𝑟𝑜𝑔𝑟𝑎𝑚𝑚𝑒𝑟𝑠 𝑜𝑟 𝑙𝑒𝑔𝑎𝑐𝑦 𝑠𝑦𝑠𝑡𝑒𝑚𝑠 𝑢𝑠𝑖𝑛𝑔 𝑐𝑠ℎ.
command-line–only interface containing a handful of 𝑡𝑐𝑠ℎ: 𝐸𝑛ℎ𝑎𝑛𝑐𝑒𝑑 𝐶 𝑠ℎ𝑒𝑙𝑙 𝑓𝑜𝑟 𝑢𝑠𝑒𝑟𝑠 𝑤ℎ𝑜 𝑤𝑎𝑛𝑡 𝑚𝑜𝑟𝑒 𝑚𝑜𝑑𝑒𝑟𝑛 𝑓𝑒𝑎𝑡𝑢𝑟𝑒𝑠.
built-in commands; it has the ability to launch other 𝑘𝑠ℎ: 𝑈𝑠𝑒 𝑓𝑜𝑟 𝑐𝑜𝑚𝑝𝑙𝑒𝑥 𝑠𝑐𝑟𝑖𝑝𝑡𝑖𝑛𝑔 𝑡𝑎𝑠𝑘𝑠 𝑎𝑛𝑑 𝑈𝑛𝑖𝑥-𝑙𝑖𝑘𝑒 𝑒𝑛𝑣𝑖𝑟𝑜𝑛𝑚𝑒𝑛𝑡𝑠.
programs and to control programs that have been 𝑑𝑎𝑠ℎ: 𝑈𝑠𝑒 𝑖𝑛 𝑝𝑒𝑟𝑓𝑜𝑟𝑚𝑎𝑛𝑐𝑒-𝑐𝑟𝑖𝑡𝑖𝑐𝑎𝑙 𝑜𝑟 𝑒𝑚𝑏𝑒𝑑𝑑𝑒𝑑 𝑠𝑦𝑠𝑡𝑒𝑚𝑠.
launched from it. 𝑓𝑖𝑠ℎ: 𝐵𝑒𝑠𝑡 𝑓𝑜𝑟 𝑢𝑠𝑒𝑟𝑠 𝑝𝑟𝑖𝑜𝑟𝑖𝑡𝑖𝑧𝑖𝑛𝑔 𝑒𝑎𝑠𝑒 𝑜𝑓 𝑢𝑠𝑒 𝑎𝑛𝑑 𝑖𝑛𝑡𝑒𝑟𝑎𝑐𝑡𝑖𝑣𝑖𝑡𝑦.

Module Code & Module Title Slide Title SLIDE 24


The Linux File System

• The *Nix (Unix or Linux) file system is a hierarchical directory structure


• The structure resembles an upside-down tree
• Directories are collections of files and other directories. The structure is
recursive with many levels.
• Every directory has a parent except for the root directory.
• Many directories have children directories.
• Unlike Windows, with multiple drives and multiple file systems, a *Nix
system only has ONE file system.
• The Linux Standard Base (LSB) specifies the structure of a Linux file
system.

Module Code & Module Title Slide Title SLIDE 25


The Linux File System

Module Code & Module Title Slide Title SLIDE 26


/: The root directory where it all begins. Every other directory is a subdirectory of this
one.
/𝗯𝗶𝗻: Contains fundamental binary files, necessary for minimal system functioning.
/𝘀𝗯𝗶𝗻: Similar to /bin, but contains binaries essential for system bootup and repair.
/𝗲𝘁𝗰: Holds system-wide configuration files. It's the go-to place for system
administrators.
/𝗵𝗼𝗺𝗲: A personal space for users. Think of it as your work desk, containing your
documents, downloads, and more.
/𝘃𝗮𝗿: Stores variable data files such as logs, emails, print queues, and most notably
databases.
/𝘂𝘀𝗿: Holds user-related programs, libraries, and files.
/𝗹𝗶𝗯: Contains shared library files supporting the binaries in /bin and /sbin.
/𝗼𝗽𝘁: Optional or add-on software packages are located here.
/𝘁𝗺𝗽: A place for temporary files used by the system, cleared upon reboot.
/𝗯𝗼𝗼𝘁: All the files necessary for booting the system are here.
/𝗱𝗲𝘃: Contains device files for all hardware devices on the system.
/𝗽𝗿𝗼𝗰: An interesting directory that doesn't contain files but system and process
information.
/𝗿𝗼𝗼𝘁: This is the home directory for the root user, not to be confused with the root (/)
directory at the top of the filesystem.
/𝗿𝘂𝗻: This directory hosts temporary files (like /tmp) but these are specifically related to
running processes and are created at an early stage of the boot process.
/𝘀𝗿𝘃: This directory contains data for services provided by the system.
/𝘀𝘆𝘀: Similar to /proc, this is a virtual filesystem providing a unified interface through
which the kernel provides information about devices, drivers, and some kernel features.
/𝗺𝗻𝘁: This is a generic mount point under which you mount filesystems or devices.
/𝗺𝗲𝗱𝗶𝗮: This directory is generally used by the system as a mount point for removable
media like CDs, digital cameras, or other media devices.

Module Code & Module Title Slide Title SLIDE 27


Continue….

Module Code & Module Title Slide Title SLIDE 28


Accessing Linux

• When the shell is first opened, you are presented with a prompt, indicating that
the shell is waiting for input.
– The shell typically uses $ as the prompt, but may use a different symbol.
– Most importantly: when typing commands, either from this workshop or from other sources, do
not type the prompt, only the commands that follow it. Also note that after you type a
command, you have to press the Enter key to execute it.
– The prompt is followed by a text cursor, a character that indicates the position where your
typing will appear. The cursor is usually a flashing or solid block, but it can also be an
underscore or a pipe.

Module Code & Module Title Slide Title SLIDE 29


command syntax

In Linux and other Unix-like operating systems, commands are often structured in one of two ways:
• command—option argument: In this structure, you first specify the command you want to run,
followed by an option (also known as a flag or a switch), and then an argument. The option
usually modifies the behavior of the command, and the argument is typically the object on which
the command acts.
– For example, in the command ls -l /home, ls is the command, -l is an option that tells ls to use a long listing format,
and /home is the argument specifying the directory to list.
• command subcommand argument: In this structure, after the initial command, a subcommand is
used to specify a particular operation of the command, followed by an argument.
– For example, in the command git clone https://github.com/user/repo.git, git is the command, clone is
the subcommand that tells git to clone a repository, and https://github.com/user/repo.git is the argument
specifying the repository to clone.
These structures provide a consistent way to interact with commands and their various
functionalities in the command-line interface. Different commands may support different options,
subcommands, and types of arguments, so it’s always a good idea to refer to the command’s manual
(man) pages for detailed usage information. You can access these with the man command, like so:
man ls or man git.
Module Code & Module Title Slide Title SLIDE 30
Navigating the File System

• cd change the current working directory


• pwd print the current working directory
• ls list the contents of a directory
• .. move up one directory level
• / the root directory of the file system

Module Code & Module Title Slide Title SLIDE 31


Modifying the Linux File System
• More useful commands
– cd: Changes the current working directory to the specified directory. If no directory is provided, it returns to
the user's home directory.
– mkdir test: Creates a directory named test in the current working directory.
– echo 'Hello everyone' > test/myfile.txt: Creates a file myfile.txt inside the test directory and writes "Hello
everyone" into it (overwriting any existing content).
– echo 'Goodbye all' >> test/myfile.txt: Appends "Goodbye all" to the myfile.txt file inside the test directory.
– less test/myfile.txt: Opens myfile.txt in the less pager to allow scrolling and viewing of its contents.
– mkdir test/subdir1/subdir2: Fails because the parent directory test/subdir1 does not exist, and mkdir cannot
create nested directories without the -p option.
– mkdir -p test/subdir1/subdir2: Succeeds because the -p option creates any missing parent directories in the
specified path, ensuring subdir1 and subdir2 are created.
– mv test/myfile.txt test/subdir1/subdir2: Moves myfile.txt into the test/subdir1/subdir2 directory, renaming it
if necessary.
– rmdir test: Fails because rmdir only removes empty directories, and test contains files or subdirectories.
– rm -Rv test: Succeeds because rm -Rv removes the test directory and all its contents recursively (-R) and
verbosely (-v), providing feedback on what is being deleted.

Module Code & Module Title Slide Title SLIDE 32


The List Command

• Useful options for the “ls” command:


– ls -a List all file including hidden file beginning with a period “.”
– ls -ld * List details about a directory and not its contents
– ls -F Put an indicator character at the end of each name
– ls –l Simple long listing
– ls –lh Give human readable file sizes
– ls –lS Sort files by file size
– ls –lt Sort files by modification time

Module Code & Module Title Slide Title SLIDE 33


The List Command

Module Code & Module Title Slide Title SLIDE 34


root
The root user is the master

• The root user is the highest-level administrative account in Linux.


• It has complete control over the system, including access to all files
and system resources.
• The root account can modify or delete files, manage system settings,
install or remove software, and perform other critical tasks.
• While essential for system maintenance and troubleshooting, the root
account introduces significant security risks due to its powerful
privileges.
• To mitigate risks, many systems use lower-privileged user accounts
and elevate privileges only, when necessary, often through sudo.
• The root account is typically identified by the username "root" and
has a unique user ID of 0.

Module Code & Module Title Slide Title SLIDE 35


Permission level
Comman
d/Term Description Purpose Authentication Method User Role
Temporarily switches to Temporarily
another user (defaults to Requires the target user's becomes the target
su Switch User root if no user is specified). password (e.g. root password). user.
Requires the invoking user's uns specific
Runs a single command as password (configured in sudoers commands with
sudo Superuser Do another user (usually root). file). elevated privileges.
Authorized to run
A user with permission to Configured in the /etc/sudoers commands with
sudoer Sudoer run sudo commands. file. elevated privileges.
Combines sudo and su to Requires the invoking user's Temporarily
Sudo to switch to the root user password (configured in sudoers becomes root, using
sudo su Superuser using sudo privileges. file). sudo privileges.
The administrative super
account with full access to Logs in directly as root or uses su Has unrestricted
root Root User all commands and files. /sudo. access to the system

Module Code & Module Title Slide Title SLIDE 36


File System Ownership and Permissions

• All files and directories have an individual and a group ownership.


• All files and directories have read (r), write (w), and execute (x) permissions
assigned as octets to the individual owner (u), the group (g) owner and all
others (o) that are logged into the system.
• You can change permissions if you are the individual owner or a member
of the group.
• Only root can change ownership.

Unix permission bits: Permissions


Read, Write, Execute 4 = read 4+2+1=7
Owner, Group, World 2 = write 644 means what?
1 = execute 755 means what?

Module Code & Module Title Slide Title SLIDE 37


File and Directory Ownership and Permissions

• Try
– cd (change directory)
– touch myfile (create file)
– mkdir mydir (create directory)
– ls –l myfile (examine file)
– ls –ld mydir (examine directory)
– chmod g+w myfile (add group write permission)
– ls –l myfile
– chmod ugo+x myfile (add user, group and other execute permission)
– ls –l myfile
– chmod ugo+w mydir (add user, group and other write permission)
– ls –ld mydir
– chmod a-w (a=ALL, remove user, group and other write permission)

Module Code & Module Title Slide Title SLIDE 38


Introduction to Linux
Access Permissions

There are three permissions for any file, directory or application program.
The following lists the symbols used to denote each, along with a brief
description:
r — Indicates that a given category of user can read a file.
w — Indicates that a given category of user can write to a file.
x — Indicates that a given category of user can execute the file.

Each of the three permissions are assigned to three defined categories of


users.
The categories are:
owner — The owner of the file or application.
group — The group that owns the file or application.
others — All users with access to the system.

Module Code & Module Title Slide Title SLIDE 39


Introduction to Linux
Access Permissions
One can easily view the permissions for a file by invoking a long format listing
using the command
ls –l

For instance, if the user Aries creates an executable file named test, the output
of the command ls -l test would look like this:
-rwxrwxr-x 1 Aries student 0 Sep 26 12:25 test

The permissions for this file are listed at the start of the line, starting with r w x .
This first set of symbols define owner access.
The next set of r w x symbols define group access
The last set of symbols defining access permitted for all other users.

Module Code & Module Title Slide Title SLIDE 40


Introduction to Linux
Listing the Content of a Directory

This listing indicates that the file is readable, writable, and executable by
the user who owns the file (user Aries) as well as the group owning the file
(which is a group named student).
The file is also world-readable and world-executable, but not world-writable.
ls is used to list the contents of a directory.

If the command ls is written with parameter –l then the command lists


contents of the working directory with details. Example:

$ ls –l

Module Code & Module Title Slide Title SLIDE 41


File permissions

• drwxrwxrwt is a directory with the “sticky bit” set


• Anyone can create files, only the owner can delete

Module Code & Module Title Slide Title SLIDE 42


Linux File Permission

Module Code & Module Title Slide Title SLIDE 43


File permissions
There are two ways to set permissions when using the chmod command:
Symbolic mode:
testfile has permissions of -r--r--r--
U G O*
$ chmod g+x testfile ==> -r--r-xr--
$ chmod u+wx testfile ==> -rwxr-xr--
$ chmod ug-x testfile ==> -rw--r--r--
U=user, G=group, O=other (world)

Module Code & Module Title Slide Title SLIDE 44


File permissions cont.

Absolute mode:
We use octal (base eight) values represented like this:
Letter Permission Value
R read 4
W write 2
X execute 1
- none 0
For each column, User, Group or Other you can set values from 0 to 7.
Here is what each means:
0= --- 1= --x 2= -w- 3= -wx
4= r-- 5= r-x 6= rw- 7= rwx

Module Code & Module Title Slide Title SLIDE 45


File permissions cont.
• The Linux command chmod 755 index.html is
Numeric mode cont: used to change the permissions of the file index.html.
• The number 755 represents the permissions in octal
Example index.html file with typical notation, where
permission values: • the first digit represents the owner’s permissions,
• the second digit represents the group’s
$ chmod 755 index.html permissions,
• and the third digit represents everyone else’s
$ ls -l index.html
permissions.
-rwxr-xr-x 1 root wheel 0 May 24 • In this case, 755 translates to:
06:20 index.html
• 7 (for the owner): read (4), write (2), and execute
(1) permissions, adding up to 7.
$ chmod 644 index.html • 5 (for the group): read (4) and execute (1)
permissions, adding up to 5.
$ ls -l index.html • 5 (for others): read (4) and execute (1)
-rw-r--r-- 1 root wheel 0 May 24 permissions, adding up to 5.
06:20 index.html • So, after running chmod 755 index.html, the owner
of index.html can read, write, and execute the file, while
everyone else can only read and execute it.

Module Code & Module Title Slide Title SLIDE 46


File permissions cont.
• The command ls -l index.html is used to display detailed
Numeric mode cont: information about the file index.html. The output -rwxr-
xr-x 1 root wheel 0 May 24 06:20
Example index.html file with typical index.html can be interpreted as follows:
permission values: • -rwxr-xr-x: This is the file permission.
• The first character - indicates that this is a regular file.
$ chmod 755 index.html • The next three characters rwx show that the owner
has read, write, and execute permissions.
$ ls -l index.html
• The next three r-x show that the group has read and
-rwxr-xr-x 1 root wheel 0 May 24 execute permissions. The final three r-x show that
06:20 index.html others have read and execute permissions.
• 1: This is the number of hard links to the file.
• root: This is the owner of the file.
$ chmod 644 index.html • wheel: This is the group that owns the file.
• 0: This is the size of the file in bytes.
$ ls -l index.html • May 24 06:20: This is the last modification time of the file.
-rw-r--r-- 1 root wheel 0 May 24 • index.html: This is the name of the file.
06:20 index.html

Module Code & Module Title Slide Title SLIDE 47


Set-user-ID (SUID)
• The Set-user-ID (suid) bit is a special type of permission in Unix-like operating systems that allows a
user to run an executable file with the permissions of the file’s owner.
• This is useful for programs that need to perform tasks that require higher privileges than those which
common users have, such as changing their login password.
• Here’s an example:
– Consider the /usr/bin/passwd command, which is used to change a user’s password. This command
needs to write to the /etc/shadow file, which holds encrypted user passwords. This file is owned by root
and not writable by regular users. If you look at the permissions of /usr/bin/passwd, you’ll see something like
this: Set-user-ID
– -rwsr-xr-x 1 root root 68208 Feb 15 2021 /usr/bin/passwd
• Notice the s in the owner’s execute field. This indicates that the Set-user-ID bit is set. When a user runs
the passwd command, it runs with the owner’s (root’s) privileges, and can therefore write to
/etc/shadow.
• However, this can be a security risk if not handled properly. If a program that has the suid bit set has a
vulnerability, it could be exploited to gain root privileges on the system. Therefore, it’s important to only
set the suid bit on programs that absolutely need it, and to ensure these programs are secure.
• The number 68208 in the output of the command -rwsr-xr-x 1 root root 68208 Feb 15
2021 /usr/bin/passwd represents the size of the file /usr/bin/passwd in bytes. This means
that the passwd executable is 68208 bytes in size.

Module Code & Module Title Slide Title SLIDE 48


Set-group-ID (SGID)

• On directories, SGID ensures new files inherit the directory's group ownership, not the user's current
group.
• This is useful for maintaining consistent group ownership in shared directories.
• Example of SGID on a Directory:
• Consider a directory called /shared that is owned by group dev. If SGID is set on this directory:
chmod g+s /shared
• Any new file created inside /shared will automatically be assigned the dev group, ensuring consistency
in group ownership for collaborative work.
Set-user-ID

Module Code & Module Title Slide Title SLIDE 49


SUID vs SGID
The setuid/setgid (SUID/SGID) bits allows the binary to run with the privileges of the user/group owner
instead of those of the user executing it.

Module Code & Module Title Slide Title SLIDE 50


SUID vs SGID

• The sticky bit is on directories residing within filesystems for Unix-like operating systems. When a
directory's sticky bit is set, the filesystem treats the files in such directories in a special way so
only the file's owner, the directory's owner, or root can rename or delete the file.
• You can set a sticky bit on a file or a folder using “t” or “1”.
chmod +t demo.sh
chmod 1755 demo.sh

Module Code & Module Title Slide Title SLIDE 51


Text editors

• a more powerful and efficient way to


create and edit files is with a text
editor.
• Text editors are programs that allow
the user to create, open, edit, and
close plain- text files. There exist
many text editors, few of them
are nano, vim, emacs, gedit etc.
• If you want to open a text editor, just
type the name of it and hit enter. we
will open cat_new.txt file with the
nano text editor by entering the
command nano cat_new.txt.

Module Code & Module Title Slide Title SLIDE 52


Editing Files with Vim and Nano

• Linux settings are stored in text files


• To change settings, edit text files
• Test editor at the CLI do not have menus
• Common text Editors are:
• Vim
• Nano
• Gedit
• Vi
• Atom text editor
• Sublime text editor

Module Code & Module Title Slide Title SLIDE 53


VIM
• Vim modes
• Normal /Command mode – keystrokes issue commands to Vim
• The default mode that Vim opens with is Normal mode. Sometimes, Normal mode
is also called Command mode. The Normal mode is used for performing actions
like navigation, text substitution, cut, copy, paste, delete, etc.
• Insert mode – keystrokes place text in text files
• You actually write text to a file in the insert mode of Vim editor.
• Execute mode – keystrokes issue additional commands to Vim
• It is used to select text with arrow keys so that various operations (like cut, copy,
paste, delete, etc) can be performed on selected text.
• Changes modes
• ESC –takes you to Command mode
• I – takes you from command mode to insert mode (as do many other keys)
• : - takes you from Command mode to Execute mode

Module Code & Module Title Slide Title SLIDE 54


VIM

Module Code & Module Title Slide Title SLIDE 55


VIM

Module Code & Module Title Slide Title SLIDE 56


Nano

• Nano is simpler than Vim and does not use


modes
• Enter text directly in the file
• The Ctrl metakey manages the file
• Ctrl+O – save the file
• Ctrl+X – exit the file and close the text editor

Module Code & Module Title Slide Title SLIDE 57


Nano

Module Code & Module Title Slide Title SLIDE 58


SU vs SUDO

Module Code & Module Title Slide Title SLIDE 59


Summary/Recap of main points

• FOSS – recognize and describe free and Open-source software, including


advantages and disadvantages
• General Public License (GPL) – understand how the GPL influences the
development and availability of Linux
• GUI vs CLI – Understand the advantages and disadvantages of each
• Recognize both command syntax structures:
• command—option argument
• command subcommand argument
• Recognize basic commands: ls, cat, cd ,pwd ,whoami ,touch
• Use Vim and Nano to open ,edit ,save ,and close files
• Use su to elevate privileges to root
• Use sudo to exercise delegated privileges"

Module Code & Module Title Slide Title SLIDE 60


GNU General Public License (GPL)

The GNU General Public License (GPL) has had a significant influence on the development and availability of Linux;
1. Freedom of Use and Modification: The GPL assures that the Linux kernel source code will always remain
available1. This allows anyone to use, modify, and distribute the code, fostering a collaborative development
environment. This has led to the creation of numerous Linux distributions2.
2. Copyleft Principle: The GPL is a “copyleft” license, which means that any changes to the software must also be
distributed under the same license2. This ensures that improvements to the code are shared with the community,
promoting continuous development and innovation2.
3. Open Core Model: The GPL makes it difficult for companies to apply an “open core” model, where only the core of
a product is open source and other components are proprietary2. This ensures that the entire Linux kernel remains
open and free2.
4. Influence on Other Projects: The success of the Linux project under the GPL has influenced other successful
projects to adopt the GPL as well2.
5. Cost: The GPL doesn’t require Linux to be free of cost, although the source code is distributed without
charge1. This has made Linux accessible to a wide range of users, including those who may not have the financial
resources to pay for an operating system1.
In summary, the GPL has played a crucial role in shaping the open, collaborative, and accessible nature of Linux. It
has helped Linux to become a robust and widely-used operating system that it is today.

Module Code & Module Title Slide Title SLIDE 61


Linux Command Cheat Sheet

Module Code & Module Title Slide Title SLIDE 62


Basic Linux Commands
Command Description
ls Lists all files and directories in the present working directory
ls -R Lists files in sub-directories as well
ls -a Lists hidden files as well
Lists files and directories with detailed information like
ls -al permissions,size, owner, etc.
cd or cd ~ Navigate to HOME directory
cd .. Move one level up
cd To change to a particular directory
cd / Move to the root directory
cat > filename Creates a new file
cat filename Displays the file content
cat file1 file2 >
file3 Joins two files (file1, file2) and stores the output in a new file (file3)

Module Code & Module Title Slide Title SLIDE 63


Basic Linux Commands
Command Description
mv file "new file path" Moves the files to the new location
mv filename new_file_name Renames the file to a new filename
Allows regular users to run programs with the security privileges of the
sudo superuser or root
rm filename Deletes a file
man Gives help information on a command
history Gives a list of all past commands typed in the current terminal session
clear Clears the terminal
Creates a new directory in the present working directory or a at the
mkdir directoryname specified path
rmdir Deletes a directory
mv Renames a directory
pr -x Divides the file into x columns
pr -h Assigns a header to the file
pr -n Denotes the file with Line Numbers
Module Code & Module Title Slide Title SLIDE 64
File Permission Commands

Command Description
ls -l to show file type and access permission
r read permission
w write permission
x execute permission
-= no permission
Chown user For changing the ownership of a file/directory
Chown user:group filename change the user as well as group for a file or directory

Module Code & Module Title Slide Title SLIDE 65


User Management Commands

Command Description
sudo adduser username To add a new user
sudo passwd -l 'username' To change the password of a user
sudo userdel -r 'username' To remove a newly created user
sudo usermod -a -G GROUPNAME
To add a user to a group
USERNAME
sudo deluser USER GROUPNAME To remove a user from a group
finger Shows information of all the users logged in
finger username Gives information of a particular user

Module Code & Module Title Slide Title SLIDE 66


User Management Commands

Command Description
sudo adduser username To add a new user
sudo passwd -l 'username' To change the password of a user
sudo userdel -r 'username' To remove a newly created user
sudo usermod -a -G GROUPNAME
To add a user to a group
USERNAME
sudo deluser USER GROUPNAME To remove a user from a group
finger Shows information of all the users logged in
finger username Gives information of a particular user

Module Code & Module Title Slide Title SLIDE 67


What We will Cover Next

Chapter 02
Virtualization and OS installation

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy