0% found this document useful (0 votes)
2 views26 pages

Linux Notes Selected Pages

The document provides an overview of the Linux file system, detailing various file types, directory structures, and essential file management commands. It explains the basic terminal commands for file and directory management, as well as the structure and functionality of the ext4 file system. Additionally, it covers user identification, creation, and the role of the shell in interacting with the operating system.

Uploaded by

Rik Koki
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)
2 views26 pages

Linux Notes Selected Pages

The document provides an overview of the Linux file system, detailing various file types, directory structures, and essential file management commands. It explains the basic terminal commands for file and directory management, as well as the structure and functionality of the ext4 file system. Additionally, it covers user identification, creation, and the role of the shell in interacting with the operating system.

Uploaded by

Rik Koki
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/ 26

lOMoARcPSD|57166776

 Each block will contain data of only one file, although a file may
reside in many blocks across the file system.
 Thus, the smallest disk space that can be allocated to a file is one
block.

File Types
 Text Files: Normally contain configuration information.
 Directory Files: Files that serve as storage space to organise other
files.
 Special Device Files: Important files for systems administrators as
they represent various system devices, e.g., hard drives and serial
ports.
 Binary Data Files: Program files are normally associated with
several binary data files, which store information such as functions
and graphics.
 Linked Files: Files that are associated with one another, i.e., they
point to another file (shortcut file), or they can represent the same
data.
 Executable program files: These exist on the hard drive until they
are executed in memory to become processes.
 Named Pipes: Identify the channel that passes information from
one process in memory to another.
 Socket Files: A type of named pipe file that allows a process on
another computer to write to a file on the local computer while
another process reads from that file.

File Names
• Linux file names usually consist of alphanumeric characters
underscores ( _ ), dashes or hyphens ( - ) and full stop characters
( . ).
• Files that begin with a dot ( . ) are called hidden files.
• The command-line prompt in a Linux terminal ( $, # ) or to start a
file name with a hyphen.

Directory Files
• Directory Files: a special file that contains a list of the files, paired
with those files’ inode numbers.
• Subdirectory: a directory that is found in another directory.

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

Linux Files

The Directory Structure

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

Linux Basic File Structure


Introduction
• root: the home directory for the root user.
• home: Contains the user's home directories along with directories
for services.
• bin: Commands needed during boot up that might be needed by
normal users
• sbin - Like bin but commands are not intended for normal users.
Commands run
• by LINUX.
• proc - This file system is not on a disk. It is a virtual file system that
exists in the kernel’s imagination which is memory.
• 1 - A directory with info about process number 1. Each process has a
directory below proc.
• usr - Contains all commands, libraries, man pages, games and static
files for
• normal operation.
• bin - Almost all user commands. some commands are in /bin or
/usr/local/bin.
• sbin - System admin commands not needed on the root file system.
e.g., most
• server programs.
• include - Header files for the C programming language. Should be
below
• /user/lib for consistency.
• lib - Unchanging data files for programs and subsystems
• local - The place for locally installed software and other files.
• man - Manual pages
• info - Info documents
• doc - Documentation
• tmp
• X11R6 - The X windows system files. There is a directory similar to
usr below
• this directory.
• X386 - Like X11R6 but for X11 release 5
• boot - Files used by the bootstrap loader, LILO. Kernel images are
often kept
• here.
• lib - Shared libraries needed by the programs on the root file system
• modules - Loadable kernel modules, especially those needed to boot
the system
• after disasters.
• dev - Device files

File Management Commands


File and Directory Management
• dd: Convert and copy a file formatting according to the options.
Disk or data duplication.

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

• Dir: List directory contents.


• file: Determines file type. Also, can tell type of library.
• pathchk: Check whether filenames are valid or portable.
• sum: Checksum and count the blocks in a file.
• test: Check file types and compare values.
• vdir: List directory contents.

File viewing and editing.


• ed: Editor
• emacs: Full-screen editor.
• gitview: A hexadecimal or ASC file viewer.
• vi: Editor with a command mode and text mode. Starts in command
mode.

The OS File System: Overview


• File System: a subsystem within the OS responsible for managing
how data is stored, organized, and accessed on storage devices.

Activities it is responsible for


• Data Organization: Organizes data into files and directories.
• Data Storage: Manages how data is stored on physical storage
devices (e.g., hard drives, SSDs).
• Data Retrieval: Provides mechanisms for reading and writing data.
• Metadata Management: Maintains information about files, such
as name, size, permissions, and timestamps.
• Space Management: Manages free space, allocation, and
deallocation of storage space.
• Examples: ext4, NTFS, FAT32, HFS, APFS.
Key Components of the File System
• Directory Structure: Organizes files into a hierarchical structure of
directories.
• Superblock: Contains metadata about the file system.
• Inode: Data structures that store information about files and
directories (in Unix-like file systems).
• Journal: Keeps track of changes not yet committed to the file
system to aid in recovery after crashes (in journaling file systems
like ext3 and ext4).

ext4 File System Type


Fourth Extended File System – ext4
• Is a journaling file system used in Unix-like operating systems,
including Linux.
o Journal: Keeps track of changes not yet committed to the file
system.

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

o Helps prevent file system corruption and speeds up recovery


after crashes by keeping a log (journal) of changes.
o Improves the reliability of the journaling mechanism by using
checksums to detect and prevent corruption in the journal.

• Is designed to manage how data is stored and retrieved on disk


partitions.
• Uses extents instead of the traditional block mapping.
o An extent is a range of contiguous physical blocks, which
helps reduce fragmentation and improve performance,
especially for large files.

• Supports files up to 16 terabytes (TB) and supports volumes up to 1


exabyte (EB) (1,024 petabytes).
• Improves performance by delaying the allocation of blocks until the
data is written to the disk, reducing fragmentation.
• Allocate multiple blocks in a single operation, which improves the
efficiency of large file operations.
• Includes optimizations that make the file system check (fsck)
process faster.
• Allows for the preallocation of disk space for a file like databases
that need to ensure that disk space will be available.
• Supports timestamps with nanosecond precision and can handle
timestamps beyond the year 2038.
• Use mkfs.ext4 to create and fsck.ext4 to check an ext4 file
system on a block device.
• sudo mkfs.ext4 /dev/sdXn - Create ext4 file system on
/dev/sd[a-z][1-n]
• sudo fsck.ext4 /dev/sdXn - Checking ext4 file system on
/dev/sd[a-z][1-n]

WEEK 3: The Linux Terminal


The Linux Command Line Interface
• Shell is also known as the Command Line.
• Shell: a program that takes the keyboard commands and passes
them to the operating system to carry out.
• Almost all Linux distributions supply a shell program from the GNU
Project called bash.
• The name “bash” is an acronym for “Bourne Again SHell”, a
reference to the fact bash is an enhanced replacement for sh, the
original Unix shell program written by Steve Bourne.

Terminal Emulators
• When using a graphical user interface, another program is needed.

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

o This program is known as the terminal emulator to interact


with the shell.
• If we look through our desktop menus, we will probably find one.
• KDE uses konsole and GNOME uses gnome-terminal, though it's
likely called simply “terminal” on our menu. There are several other
terminal emulators available for Linux, but they all do the same
thing; give us access to the shell.

System Identification
 Where Linux is being accessed via a network, the network
administrator assigns each user a unique identification number
associated with the user’s login name. Users are also allocated to a
group (or groups). These groups usually represent a set of users
with similar needs, such as members of a department or a team
working on a particular project.
 The User ID (UID) and Group ID (GID) are used to enforce file
ownership, permissions, and other security measures within the
Linux system.

Creating a User (commands to use)


1. “sudo adduser <username>”.

2. Create and retype the password.

3. Add the details for the new user.

4. Changing the password for the default user.

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

Skill Development
• Builds foundational skills essential for advanced system
administration and programming.
• Opens opportunities for a deeper understanding of the operating
system and its internals.

Basic Terminal Commands


COMMAND FUNCTION
pwd • Print Working Directory.
• Displays the full path of the current directory you are
in.
• How the command is used: pwd
ls • List Directory Contents.
• Lists files and directories in the current directory.
ls -l • Long display a list of files in the current directory.
cd  Change Directory.
• Changes the current directory to the specified
directory.
mkdir • Make Directory.
• Creates a new directory with the specified name.
• How the command is used: mkdir
<directoryname>
rmdir • Remove Directory.
• Deletes an empty directory.
touch • Create an Empty Text File.
• Creates a new, empty file with the specified name.
• Updates the last accessed time for the file.
• Does not open the file in a text editor.
• Useful for updating the timestamps of a file that relies
on date-related activities, such as archiving and
backing up.
• How the command is used: touch <filename>
cp • Copy Files.
• Copies files or directories from one location to
another.
• How the command is used: cp <source>
<destination>
mv • Move or Rename Files
• Moves files or directories from one location to another
or renames them.
• How the command is used: mv <source>
<destination>
rm • Remove Files.
• Deletes one or more files. and/or directories with files
with –r option.
file • This is useful for getting a quick idea of the nature of
a file’s contents.
• It displays the file types for all files in the current

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

directory.
• It performs a series of tests on the file(s) specified to
report a classification.
• How the command is used: file <filename>
cat • To view the contents of a file.
• Is a quick command to display the contents of a file
on the screen.
• Does not allow you to move backwards and forwards
in the file and, if the contents cannot fit onto one
screen, the display will scroll to the end of the file.
• How the command is used: cat f<filename>
more • To view the contents of a file in controlled amounts.
• How the command is used: more <filename>
less • To view the contents of the file and be able to move
around in the file.
• The less command is like the more command but
allows greater flexibility in moving backwards and
forwards in a file.
• How the command is used: less <filename>
head • To display the first ten lines of a specified file.
• To display the first n lines of a specified file: head –n
<filename>
• How the command is used: head <filename>
tail • To display the last ten lines of a specified file.
• To display the last n lines of a specified file: tail –n
<filename>
• To display the end of a file from the nth line: tail +n
<filename>
• How the command is used: tail <filename>
wc • To count the number of bytes, lines, words and
characters in a specified file.
• How the command is used: wc [options]
<filename>
sort • To sort the contents of a file into alphabetical or
numerical order:
• Outputs the sorted file to the screen but does not
modify the original file.
• Uses each new line as a new record.
• Will sort according to alphabetical or numerical order,
depending on file content.
• How the command is used: sort <filename>
grep • To search files for a specific pattern or text:
• Is a quick way to search a file for a string pattern.
• Allows you to search all files for a specific text string.
• Requires the search phrase to be placed in single
quotes.
• Displays the line of text containing the specified text
string.
• Will not find text patterns spread over more than one

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

line.
• How the command is used: grep [options]
<filename>
diff • To display the difference between two text files on a
line-by-line basis.
• Displays output that shows how you would need to
change the first file so that it resembles the second
file.
• Works best when there are few differences between
the two specified files.
• –b: to ignore whitespace characters.
• How the command is used: diff [options]
<filename>
find • The find command is used to locate one or more files
that satisfy a condition in the paths that you specify
and can perform actions on the file that has been
found (such as printing the pathname).
• Options that can be used with the find command:
• How the command is used: find <pathname-
list> <condition-list> <action-list>
chmod • Change the mode bits of a file (permissions).
• The same applies for directories.
• How the command is used: <num code>
<filename>
chown • Changes the ownership of a file.
• How the command is used: <newowner>
<filename>
chgrp • Changes the group ownership of a file.
• How the command is used: <newgroup>
<filename>
umask • To change default file permissions.
• How the command is used: umask <newmask>
nano • Allows you the edit the file.
• How the command is used: nano <filename>
vim •
rmdir • Removing a directory.
• How the command is used: rmdir
<directoryname>
whoami • Shows the username.
• How the command is used: whoami
sudo • A new user is added.
adduser • A new password is required.
su • The person allows the jump between different users.
sudo apt • Install anything.
install • How the command is used: sudo apt install
<itemtobeinstalled>
sudo apt • The user can update their user/terminal.
update • How the command is used: sudo apt update.

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

wc Command
• -c: bytes count • -w: word count
• -m: character count • -l: line count

grep command
Available Options:
• -c: Displays only the number of matching lines in each file.
• -l: Lists only the name of the file that contains the specified pattern.
• -n: Displays the line number of the line containing the specified
text.
• -i: Does not distinguish between uppercase and lowercase.
• -o: Print only the characters matching the regular expression.

find Command
• Pathname-list specifies the paths to search.
• Condition list could be any of the following:
o -name: the file name of the specific file to be found.
o -perm ###: where ### represents the octal file
permissions.
o -type x: where x is one of the following types: d (directory
file), f (ordinary file), c (character device file), b (block device
file).
o -user <username> – for files with a specific owner or UID.
o -group <group_name> : for files belonging to a specific
group or GID.
o -size n: to find files of size n blocks.
o -links n to find files with n links.
o -atime n: to find files that were accessed n days ago.
o -mtime n: to find files that were modified n days ago.
o -ctime n: to find files that were created n days ago.

• Action list – specifies the action that should be carried out on the
files that meet the criteria (as per the conditions list):
o –print: to display files to the screen.
o -exec command: to execute a command.
o -ok command: like exec, except that you are queried first.

Essential Linux Utilities


• apt: The Advanced Package Tool is a command-line package
manager used in Debian-based distributions like Ubuntu.

apt update
Updates the local package index with the latest information about
available packages and their versions from the repositories configured in
the system.

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

Using Applications and Applets


Install htop
• htop is a useful command-line tool in the Linux environment to
determine the cause of load by each process.
• It is like Task Manager in the Windows OS environment.
• It can be used to troubleshoot and kill a process that is utilizing
excessive server resources.

Traceroute
• Traceroute: a network diagnostic tool used to track the path that
data packets take from a source computer to a destination host
across an IP network.
• By sending packets with gradually increasing time-to-live (TTL)
values, `traceroute` identifies each hop (router or gateway) along
the path and measures the time it takes for each hop.
• This helps in identifying network bottlenecks, understanding routing
paths, and diagnosing connectivity issues.
• The output includes a list of all the intermediate routers, the round-
trip time to each router, and the IP address or domain name of each
hop, providing a detailed map of the route taken by the packets to
reach the target.

wget
• wget is a command-line utility for downloading files from the web.
• It supports HTTP, HTTPS, and FTP protocols and is particularly useful
for downloading files or websites for offline viewing.

vi Text Editor
vi is a powerful and widely used text editor available in most Unix-like
operating systems.
It has three main modes:
• Command mode: Default mode for navigating and executing
commands.
• Insert mode: Mode for inserting and editing text.
• Visual mode: Mode for selecting and manipulating text visually.

The following commands operate in command mode (hit Esc before


using them)
x delete one character at the cursor position
u undo
dd delete the current line
G go to end of file
1G go to beginning of file
10G go to line 10
$ go to end of line
1 go to beginning of line
:q! exit without saving

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

:w save (but not exit)


:wq or :x save and exit
Arrow keys: move cursor around (in both modes)

Common Mistakes and Troubleshooting


Common Errors and How to Resolve Them
• Incorrect Usage of Commands: Provide examples of common
mistakes and correct usage.
• Permission Denied Errors: Explain how to use sudo to gain
necessary permissions.
• File not found errors: Check file paths and spelling errors.

Tips for Efficient Terminal Use


• Use tab completion to save time when typing commands.
• Use keyboard shortcuts for faster navigation and editing.
• Avoid using rm -rf without double-checking the target directory.

Troubleshooting Scenarios
• Slow Performance: Check system resources using utilities like
htop.
• Network Connectivity Issues: Use tools like ping and traceroute
to diagnose.

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

• Keys pressed in this mode are interpreted as characters and are


inserted into the text file.
• Pressing <a>, <i>, <C> or <o> will take you from command mode
into text entry mode.
• The command you choose to enter the text entry mode depends on
what you intend to do.
• The other options will be discussed in the text entry mode section.

File Security
Command Mode File Ownership
• The first level of implementing data security is file ownership.
• Each file in a Linux system has an owner that corresponds with one
of the authorized users.
• When a user creates a file, it is marked as being owned by that
user.
• Only the creator of a file or a superuser (root privileges, i.e.,
sudoers) can change the ownership of a file.
• Once the creator of a file changes ownership of the file, that user no
longer owns it and can regain ownership only if the new owner or
superuser returns ownership.

Changing File Ownership


• The system administrator may reassign ownership of a files.
• Chown
• chgrp

Permission Categories
• File permissions control access to an ordinary (Text) file or directory
file.
• These permissions specify who can use a file or directory and how.
Classes of the Ownership
• U: user who owns the file.
• G: group to which the user belongs.
• O: other system users.

Permission Categories
Symbol Category Ordinary
r Read Can view the contents
of the file.
w Write Can change the file’s
contents.
x Execute/Search Can run a program file.

Permission Categories
• If you give one user in any group the Write permission (i.e., the
ability to change a file), then you give that permission to everyone
else in the group too.

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

• File permissions can be changed only by the owner of a file or


the superuser (root).
• The Execute permission makes sense only if the file is a program
(command) or a shell script (a file that contains a list of one or more
commands that can be executed by the shell, like a DOS batch file
- .bat).
• Therefore, the Execute permission is usually excluded from ordinary
files.

umask Command
• It essentially controls the permission bits that will be unset for new
files and directories.
• The umask value specifies which permission bits should be masked
(turned off) when new files or directories are created.
• It is a four-digit octal number where each digit represents different
sets of permissions:
o First digit: Special permissions (setuid, setgid, sticky bit).
o Second digit: Owner (User) permissions.
o Third digit: Group permissions.
o Fourth digit: Others' permissions.

Example: umask 0002


- First digit (0): No special permissions.
- Second digit (0): Do not mask any owner permissions (owner can read
and write).
- Third digit (0): Do not mask any group permissions (group can read and
write).
- Fourth digit (2): Mask the write permission for others (others can read,
but not write).

Calculating Permissions with umask 0002


New Files:
- Default permission: 666 (rw-rw-rw-).
- umask 0002 masks the last digit: 666 - 002 = 664 -> mode
- Resulting permission: 664 (rw-rw-r--).

New Directories:
- Default permission: 777 (rwxrwxrwx).
- umask 0002 masks the last digit: 777 - 002 = 775.
- Resulting permission: 775 (rwxrwxr-x).

Setting Default Permissions


Default Permissions
• The chmod command allows the owner of a file to change the
permissions for files and directories.

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

Redirecting Standard Error Files


 To redirect the standard error file from the screen to a file:
 Type command 2 > file_name and press <Enter>.
 To redirect
Examples:
stdout and
• To redirect the standard error file from the
stderr at the
screen to a file:
same time:
$ ls –l 2> ls_l_testingresults
 Type comma
• To redirect stdout and stderr at the same time:
nd >
$ cat testing > testingresults 2>error.file
output.file 2
• To redirect stdout and stderr to the same file:
>
$ ls –l > output.file 2>&1
error.file a
nd press <Enter>.
 To redirect stdout and stderr to the same file:
 Type command >output.file 2>&1 and press <Enter>.

Pipelines
 Are used to redirect the flow of data between processes, giving
greater flexibility in the use of the Linux system.
 Save time and disk space because intermediate data does not need
to be stored in a temporary file.
 The vertical bar ( ¦ or | ) symbol is used to denote a pipe.
 To set up a pipe in Linux:
Type command1 ¦ command2
Examples:
 $ ls – l , select the  $ ls –l | grep file1
filename to use .  $ ls –l | grep file1 | wc
 $ ls – l | wc  $ ls –l | grep file1 | wc –l
 $ ls –l | wc –l

Filters
 Commands that take their input from the stdin and send their
output to the stdout are called filter programs or filters.
 A defining feature of filters is that they are commands or programs
that can be used Examples: cat, head, tail,
anywhere in a wc,sort,cut and grep
pipeline “| ” and
they generally perform useful transformations on the data that
passes through them.
 The tr (translate) command is another filter command.
 It is used to:
o Convert one character into another character.
o Compress a group of characters into a single character.
o Delete specific characters.
 To use the translate command:
 Type tr [options] string1 [string2] and press <Enter>.

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

 When using the tr command:


o Specifying both strings translates the characters in string1 to
those in string2.
o The strings may be individual characters or ranges of
characters.
o The –d option can be used to delete characters from the file
(string2 is not required).
 To convert all lowercase ‘t’ characters in a file to uppercase:
o Type tr t T <file_name and press <Enter>.
 To convert all lowercase a, b, and c characters in the output of the
who command to uppercase:
o Type who ¦ tr a-c A-C and press <Enter>.
 To display a file with all the ‘a’ characters deleted:
o Type cat file_name ¦ tr –d ‘a’

Sampling Data in a Pipeline


 The tee command is used to sample data at a point in a pipeline.
 Sampling data can be useful if a pipeline process is not producing
the expected result. The tee command sends a copy of the data
passing through a pipeline to a file. It is a filter command that reads
the stdin and writes to both the stdout and a
file. The tee command works like a T-connection in a pipeline.
 tee command write data into the file and display it on the
screen/display.

 Example :
o $ ls – l
o $ ls – l | tee testingtee.file
o cat testingtee.file

 What you will notice is that although the output was displayed on
 the screen, it was simultaneously directed to the file testingtee.file

 The data sent to the file is not altered in any way; it is merely sent
in two different directions
 To check data after the who command and write it to a file
called sample:
 The type ls -l ¦ tee filename.txt ¦ sort and press <Enter>.
 Sort the filename.txt file, write the sorted list to the check file
with tee, and use pipelining to append a count of how many
unknown entries there are to the check file.
 Get the date using the date command and append the output of
the command to the file check using a tee, then display a count of
the number of words in the data output.
 View the check file using the cat command.
 Note that the check contains the sorted filename.txt file as well
as the date on the last line.

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

Applets
 Applets are icons that reside in your panels for launching specific
applications and sometimes offering additional functionality.
 Applets in Linux is a built-in functionality feature.
 There are already some built-in Applets in the taskbar, like a clock,
network manager, and volume, and you can choose
any Applet of your choice from the Applets application.
 There are many available not only in the default Ubuntu installation,
but some extras, also.
 One of the Applets you can install is Cinnamon on Ubuntu 20.04
o $ sudo apt update && sudo apt update – y
o $sudo apt install cinnamon –y / sudo apt-get install cinnamon
–y
o $sudo reboot

 Another Applet to install is gnome-applets-data


o $sudo apt-get update –y
o $sudo apt-get install -y gnome-applets-data

GNOME
What is GNOME?
 GNOME, which stands for GNU Network Object Model Environment,
is a free and open-source desktop environment for Unix-like
operating systems. It provides an intuitive and attractive graphical
user interface for users, along with a suite of applications and tools
for everyday tasks.

Important points about GNOME


User Interface
 GNOME features a simple and modern user interface with a focus on
ease of use.
 It includes elements like the GNOME Shell, which provides core
interface functions like the top bar, system status area, and an
overview mode for switching between applications and virtual
desktops.

Applications
 GNOME comes with a range of built-in applications, such as the
Nautilus file manager, the GNOME Terminal, the Gedit text editor,
and the GNOME Software app for managing software installations.
 These applications are designed to integrate seamlessly with the
GNOME desktop environment.

Customization
 While GNOME aims for simplicity, it also allows for extensive
customization through extensions and settings.

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

 Use ‘sudo apt install ubuntu-desktop’.

4. Reboot the system by using ‘sudo reboot’.

GNOME Shell extensions


1. Install GNOME Shell Extensions by using the sudo apt-get install
gnome-shell-extensions in the terminal.

2. Install GNOME Shell Integration Add-on for Web Browser. For Firefox
and Chrome install the GNOME Shell Integration.

3. Install Dash to the panel by going to extensions.gnome.org


and searching for “Dash to panel" in the search bar.

4. Enable Dash to panel by clicking the extension listing for Dash to


panel.
o Toggle the switch to enable the extension.
o You might see a prompt to confirm installation; accept it.

Install the GNOME Tweak Tool


1. Open a Terminal: You can open a terminal by searching for
"Terminal" in your applications menu or by pressing Ctrl + Alt + T.
 Use these commands:
o sudo apt update.
o sudo apt-add-repository universe.
o sudo apt install gnome-tweaks.

2. After Installation:
 You can launch GNOME Tweaks by searching for "Tweaks" or
"GNOME Tweaks" in your applications menu.
 Use GNOME Tweaks to customize various aspects of your
GNOME desktop environment, including appearance,
extensions, fonts, and more.
 By following these steps, you should be able to install and use
GNOME Tweaks on your Linux system with GNOME.

System Firewall
What is a Firewall?
 A firewall is a facility that prevents unauthorized access to or from a
private network or a computer.
 It is a network security device that monitors and controls incoming
and outgoing network traffic based on predetermined security rules.
 Acts as a barrier between a trusted network and an untrusted
network (e.g., the Internet).

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

Types of Firewalls
 Hardware Firewalls: Physical devices that provide a barrier at the
network perimeter.
 Software Firewalls: Programs installed on individual computers to
protect them.
 Network Firewalls: Often a combination of hardware and software
firewalls.

Importance of Firewalls
 Protects against unauthorized access.
 Helps prevent cyber-attacks.
 Controls and monitors network traffic.
 Provides logging and reporting on network traffic.
 Tracks system events, which you can analyze to set more suitable
rules.

Basics of Firewall Configuration


Default Policies
 Incoming Traffic: Generally, incoming traffic is more likely to be
dangerous and is often restricted.
 Outgoing Traffic: Outgoing traffic is typically less restricted but
should still be monitored.

Allowing and Denying Traffi c


Allow Rules
 Permit certain types of traffic.
 Example: allowing SSH traffic on port 22.

Deny Rules
 Block certain types of traffic.
 Example: blocking all incoming traffic by default

Uncomplicated Firewall (ufw)


 The Debian family of Linux uses ufw to protect the system.
 By default, ufw comes pre-installed on Ubuntu.
 ufw is a much easier way to create an IPv4 or IPv6 host-based
firewall.

Basic Application of ufw


 Ufw’s most fundamental use is to control access to ports, allowing or
denying connections based on specific requirements.

IP Address Blocking

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

 ufw can be used to deny access from specific IP addresses,


particularly those known to pose security risks, thereby enhancing
network security.
 Check if the ufw is installed.
 Use the apt or dpkg commands to check.

apt command
 Run: apt list –-installed | grep ufw
 The first part of the command lists all installed packages.
 The second part filters the output to show lines that contain ufw

dpkg command
 Run: dpkg –l | grep ufw
 The first part of the command lists all installed packages
 The second part filters the output to show lines that contain ufw

 If you see ufw listed in the output, it means ufw is installed.


 If there is no output, ufw is not installed.
 dpkg (Debian Package) is the low-level package manager for
Debian-based systems like Ubuntu.

How Pipes Work


 Basic Structure: command_1 | command_2
Example: ls –la | grep ufw
ls –la: lists all files, directories, and hidden files, with detailed
information.
|: The pipe symbol takes the output ‘ls –la’ and passes it as
input to the next command.
grep: used for searching text using.
ufw: pattern to search for.

Practical Uses of Pipes


 Pipes allow the combination of simple commands to perform more
complex tasks.
 Each command in the pipeline processes the data sequentially.
Filtering Output  ps aux | grep ssh.
 Lists all running processes and filters the
list to show only those related to SSH.
Counting Lines  cat file.txt | wc –l.
 Outputs the contents of file.txt and
counts the number of lines.
Sorting and Displaying  ls -la | sort.
 Lists files in a detailed view and sorts
the output alphabetically.
Combining Multiple  ls -la /var/log | grep '\.log' | wc –l.
Filters  Lists all files in /var/log, filters for files

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

ending in .log, and counts the number of


log files.

Uncomplicated Firewall (ufw): Configuration


Configuration Steps
1. Install ufw (if not already installed).
 Update the package list on your system.
 Install ufw on your system.

2. Enable ufw.
 sudo ufw enable – to activate ufw once it has been enabled.
 Once enabled – ufw starts enforcing the firewall rules.

3. Set default policies.


 sudo ufw default deny incoming - command sets the
default policy to deny all incoming traffic.
 sudo ufw default allow outgoing - command sets the
default policy to allow all outgoing traffic.

4. Allow specific incoming connection.


 sudo ufw allow ssh.
o allows incoming traffic on port 22 (SSH).
 sudo ufw allow http.
o allows incoming traffic on port 80 (HTTP)
 sudo ufw allow https.
o allows incoming traffic on port 443 (HTTPS)

Port Numbers
Port Numbers: Introduction
 They are numerical identifiers, used to differentiate types of
network traffic.
 Help direct data to the correct application or service on a
computer.
 Each port number corresponds to a specific process or service.

Common Ports
Port 22 - Secure Shell (SSH)
 Used for secure remote logins and command execution.
 Used to log into a remote machine and execute commands securely.
 Provides a secure channel over an unsecured network by using
encryption.

Port 80 - Hypertext Transfer Protocol (HTTP)


 Used for transmitting web pages over the internet.
 The browser uses HTTP to request the web page from the server,
and the server responds with the requested content.

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

Port 443 - Hypertext Transfer Protocol Secure (HTTPS)


 Secure version of HTTP.
 Uses SSL/TLSA encryption to secure the data transferred between
the web server and the browser.
 Used for secure web page transfers.

Importance of Understanding Ports


 Knowing which ports are used by which services helps in configuring
firewalls and securing networks.
 Recognizing port numbers can aid in troubleshooting network issues
and understanding network traffic.

Uncomplicated Firewall (ufw): View Status & Rules


Default View
 Provides a simple list of active firewall rules, showing which ports
and services are allowed.
 Command: sudo ufw status.

Verbose View
 Provides detailed information about the firewall status, including
logging status, default policies, and more detailed rules.
 Command: sudo ufw status verbose.

Numbered View
 Lists the active firewall rules with numbers. This is useful for
managing the rules, such as deleting specific rules by their number.
 Command: sudo ufw status numbered

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

WEEK 7: Linux Processes


Process Status
 A process is an instance of a running program. Each process is
assigned a unique Process ID (PID) and can be thought of as a
separate task within the operating system.
 Linux is a multitasking operating system, which means that it can
run more than one process at a time. Linux users can check on the
status of running programs and influence the running of those
programs.

Process Control
Viewing Processes
 The ps command lists currently running processes.
 To view all the processes with ps, use ps -ef.
 For example, ps -aux provides a detailed view.

Killing Processes
 The kill command can terminate processes.
 For example, kill -9 PID forcefully kills the process with the specified
PID.

Job Control
 Commands like bg, fg, and jobs manage processes within a shell.

 Sometimes you need to end a program or process from the


command line. Use the following steps:
o Locate the process id [PID] of the process/program you want
to kill.
o Use the kill command with the following syntax: kill PID.
o If the process is still running, do the following: kill -9 PID.
o The -9 is a SIGKILL signal telling the process to terminate
immediately.

Running Processes in the Background


 Standard Execution
o Typically, an executing process must be completed before
another can run.
 Background Execution
o Processes can run in the background.
o This allows the user to continue other work at the prompt.
 System Performance

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

o Running too many background processes can slow down the


system.
o Having too many background processes may cancel out any
time savings.
 To prevent the output of background processes from getting mixed
up with the output of foreground processes, redirect the output of
the background processes to a file.
 To prevent other conflicts, do not run background processes that
require input from the keyboard.

Foreground Processes
 These run in the foreground and are typically initiated by the user
from the terminal.
 The user interacts directly with these processes.
 Foreground processes are processes that run directly under the
control of the user.
 They are initiated and interact with the user via the terminal or
graphical interface.
 The terminal remains occupied by the process until it is completed.
 User inputs are directly sent to the process.
Examples:
• Running a Text Editor:
• vi week7.txt
• The terminal is occupied by vi and user input is
directed to editing week7.txt.
• Executing a Command:
• ls -la
• The ls command runs in the foreground and the
terminal displays the output of the directory listing.

To run a process in the background:


• When issuing a command to run a process in the background, a PID
is displayed, and the user is returned to the prompt to continue with
other work.
1. Run the find command in the background: find / -type d > found 2>
errorlog &
2. Note the PID: e.g [1] 1234 - the PID of the background process
3. Check running processes using ps aux command:
4. Compare with the PID of the background process
5. Continue with other work in the foreground
6. Check the contents of the found file: more found
7. Cancel the more command if the listing gets too long: <Ctrl><C> or
q

Background Processes
 These run in the background, without user interaction.
 They often perform tasks like system monitoring or handling
network requests.

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

Types of Processes
 Running: current process that is being executed in the operating
system.
 Waiting: a process which is waiting for system resources to run.
 Stopped: a process that is not running.
 Zombie: process whose parent processes have ended, but the child
process is still in the process table.

Terminal Processes
Hangup (SIGHUP) Signal
 When a user logs off, the system sends a hangup signal (SIGHUP) to
all processes related to that user, terminating them.
 This signal can be redirected or ignored using the nohup command
to prevent unintended termination.

Interrupt (SIGINT) Signal


 Pressing <Ctrl><C> sends an interrupt signal (SIGINT) to terminate
a foreground process.
 This signal is used to stop processes that are running in the
foreground.

Quit (SIGQUIT) Signal


 Pressing <Ctrl><\> sends a quit signal (SIGQUIT) to a process,
causing it to terminate and produce a core dump if applicable.

Terminate (SIGTERM) Signal


 Is used to terminate a process by its PID.
 Processes can catch this signal to perform cleanup operations before
exiting.

Kill (SIGKILL) Signal


 Is used to terminate a process forcefully (execute a sure kill)
 Unlike SIGTERM, SIGKILL cannot be caught or ignored by the
process, making it a last resort for terminating stubborn processes.

Examples: Signal Usage – run the commands to test each signal


1. Hangup (SIGHUP) Signal - running a process and logging out,
causing SIGHUP to be sent
• sleep 300 &: start a process in the background by running
the command
• exit: close the terminal, this will send a hangup signal to the
background processes
2. Interrupt (SIGINT) Signal - interrupting a long-running process
with Ctrl+C

Downloaded by Kamogelo Motleleng ([email protected])


lOMoARcPSD|57166776

• ping google.com: start a process that runs indefinitely


• Press ctrl+c to send SIGINT
3. Terminate (SIGTERM) Signal - terminating a process using kill with
SIGTERM
• tail -f /var/log/syslog: start a long-running process
• ps -ef | grep tail: open another terminal, find the PID, and
send SIGTERM
• kill PID: send SIGTERM to terminate the tail process
4. Kill (SIGKILL) Signal – terminating by force an unresponsive
process using kill with SIGKILL
• sleep 1000 &: start a process, PID #### is assigned to the
sleep process
• sudo kill -9 PID

Protecting Processes with nohup


 To prevent a process from being terminated by SIGHUP when
logging off, use the nohup command followed by the command and
& to run it in the background.
 Example: nohup command &
 Output is redirected to nohup.out.
 If a command is preceded by nohup, the process will execute even if
the user exits the terminal.

Handling Processes
• Check process status using the process status commands:
• ps -ef or ps aux
• The process status commands can be combined with grep to
filter out the process you want to check
• Terminate a process by its PID using the kill command followed by
the PID.
• Example: kill PID

Downloaded by Kamogelo Motleleng ([email protected])

You might also like