System Administration
System Administration
Junior TBS
Rouaida Hentati
Chapter 1. Get Started with Red Hat Who Is Red Hat?
Enterprise Linux Red Hat is the world's leading provider of open source
software solutions
LinuxandMicrosoftWindowsarethepredominantoperatingsystems.
Red Hat Enterprise Linux (RHEL) is Red Hat's commercial
What Makes Linux Great?
Opensource software production-grade Linux distribution. Red Hat develops and
Linux is open- source
is software with source integrates open source software into RHEL through a
software.
code that anyone can multistage process.
Linux provides a command-
use, study, modify, and Red Hat participates in supporting individual open-source
line interface (CLI) for easy
share. projects
access and powerful
Users can use the Red Hat sponsors and integrates open-source projects
scripting.
software according to into the community-driven Fedora distribution.
Linux is a modular operating its software license.
Red Hat stabilizes the CentOS Stream software to be
system that is designed to Copyleft licenses
or"share-alike" ready for long-term support and standardization, and
easily replace or remove designedto Permissive licenses
encouragekeeping designedtomaximizecode integrates it into RHEL, the production-ready
components. thecodeopen reusability.
source.
expl: MIT/X11
distribution.
What Is a Linux Distribution? expl:GPLand LGPL
theSimplifiedBSD
theApacheSoftware
Kernel
RHCOS is fundamentally an A Red Hat Universal Base Image (UBI)
image-based RHEL is essentially a freely redistributable
Hardware
container host, which uses derivative of RHEL. UBI is designed to
the Container Runtime be a foundation for cloud-native and
Interface web application use cases that are
developed in containers.
Chapter 2. Access the Command Line Shell basics
Commands that are entered at the shell prompt have three
A command line is a text-based interface that is used to
basic parts:
input instructions to a computer system. The Linux
command line is provided by a program called the shell. the name of the program to run
The shell displays a string when it is waiting for user input, It might be followed by one or more
called the shell prompt. Command to run options
The computer might provide a graphical login prompt on -i => to specify the user's private key.
one of the virtual consoles. For the connection to work, only the user who owns the file can have access to read
the private key file.
Note Note
In Red Hat Enterprise Linux 6 and 7, the graphical login When you first log in to a new machine, you are prompted
screen runs on the first virtual console, but when you log with a warning from ssh that it cannot establish the
in, your initial graphical environment replaces the login authenticity of the host
screen on the first virtual console instead of starting on a
new virtual console. In Red Hat Enterprise Linux 8, the Log Out from a Remote System
behavior is the same as in Red Hat Enterprise Linux 9. Ctrl+D Or
[remoteuser@remotehost ~]$ exit
logout
Access the Command Line with the Key Components of GNOME Shell:
Desktop 1. Top Bar: Provides access to system controls (volume,
network, calendar) and user account settings.
GNOME Desktop Environment: 2. Activities Overview: Organizes windows and applications;
GNOME 40 serves as the default graphical user accessed via the Activities button or the Super key.
interface for Red Hat Enterprise Linux 9, operating on 3. System Menu: Adjusts screen brightness, manages
Wayland or the legacy X Window System. The GNOME network settings, and allows account adjustments.
Shell offers a customizable user interface with the 4. Dash: Displays favorite and running applications, including
"Standard" theme, which can be switched to a a "Show Applications" button for additional options.
"Classic" theme during login. 5. Windows Overview: Thumbnails of active windows for easy
Keyboard Shortcuts: navigation.
Users can view and customize keyboard shortcuts 6. Workspace Selector: Allows users to switch and manage
through the Settings menu. multiple workspaces.
Workspaces:
Workspaces help users organize their environment by
7. Message Tray: Displays notifications and calendar
separating different tasks. Users can switch between events, accessible by clicking the clock on the top bar.
workspaces using keyboard shortcuts or the Activities
Starting a Terminal:
overview.(press Ctrl+Alt+LeftArrow or
To access the command line, users can open the GNOME
Ctrl+Alt+RightArrow to switch between workspaces
Terminal using various methods, including searching from
sequentially)
the Activities overview or using the Alt+F2 command.
Powering Off or Rebooting the System: Locking the Screen and Logging Out:
Shutting down or restarting the system is done via the Users can lock the screen or log out through the system
system menu, with confirmation prompts for both menu. The screen locks automatically after a period of
actions. inactivity.
Execute Commands with the Bash Shell To type more than one command on a single line, use the
semicolon (;) as a command separator.
Command History
history Command: Lists previously executed
commands, each with a unique number.
Exclamation Point (!): Allows you to quickly rerun
previous commands.
!number: Runs the command corresponding
to the specified history number.
!string: Runs the most recent command
starting with that string.
Significant Red Hat Enterprise Linux Directories
Chapter 3. Manage Files from the
/boot Files to start the boot process.
Command Line
The File-system Hierarchy /dev
Special device files that the system uses to access
hardware.
The Linux system stores all files on file systems, which
are organized into a single inverted tree known as a file- /etc System-specific configuration files.
... Runtime data for processes that started since the last
/run
boot.
mv oldname.txt
The mv command can both move The rmdir command
newname.txt
files to a new location and removes only empty
rename files. rmdir EmptyDir directories.
mv file.txt
path changes, but the content rm -r nonEmptyDir For non-empty directories,
destination_direc
remains unchanged. you must use rm -r.
tory/
Make Links Between Files
You can create multiple file names that point to the same file. These file names are called links.
ln originalfile.txt hardlink.txt
ln -s /path/to/originalfile.txt symlink.txt
ls -il originalfile.txt hardlink.txt # shows same
ls -l symlink.txt # shows the link destination
inode numbers
Match File Names with Shell Expansions ~: Expands to the user's home directory.
Bash Shell Expansions: ~username: Expands to another user's
When a command is typed, Bash performs several Tilde home directory.
expansions to transform it before executing. These Expansion Example:
echo ~user: Outputs /home/user.
include:
Select files by using patterns These patterns
include wildcards Variables store values, which can be accessed
Common wildcards include: using $VARNAME or ${VARNAME}.
Variable
*: Matches any string (including zero Example:
characters).
Expansion USERNAME=operator; echo $USERNAME:
?: Matches any single character. Outputs operator.
Pathname [ABC]: any character inside the brackets.
[!abc] or [^abc]: character not inside the
Expansion Executes a command and replaces it with the
brackets.
(Globbing) [[:alpha:]]: Any alphabetic character output.
[[:alnum:]:Any alphabetic character or digit Done using $(command).
Examples: Command Example:
ls a*: Matches files starting with "a". echo Today is $(date +%A): Outputs Today
Substitution
ls *a*: Matches files containing "a". is Wednesday.
Note:An earlier form of command substitution uses
ls ????: Matches files with exactly four
backticks: `command`. Although the Bash shell still
characters. accepts this format, try to avoid it
Each section number helps to distinguish topics with similar names, such as
passwd(1) (for the password-changing command) and passwd(5) (for
the password file format).
Search Techniques:
The man -K (uppercase) option searches for the keyword in the
full-text page, not only in the titles and descriptions
man -K keyword performs a full-text search, although it is
resource-intensive and time-consuming.
Man pages usually contain standardized sections
Summary
Use the man command to view man pages and to
display information about components of a Linux
system, such as files, commands, and functions.
By convention, to refer to a man page, the name of a
page is followed by its section number in parentheses.
You can use regular expressions to search content in
man pages.
Note
Comma-separated options on a single line, such as -, -l, and
--login, all result in the same behavior.
Note
The man command -t option prepares a man page for
printing, using by default PostScript.
Chapter 5. Create, View, and Edit Text Files
Edit Text Files from the Shell Prompt Vim Operating Modes:
Edit Files with Vim
Vim (Vi IMproved) is a powerful text editor, an enhanced highlight and
manipulate
version of the original vi editor, that is often used in these text
environments.
Benefits of Using Vim
Pre-installed and Accessible
Available Across Platforms
No Need for a GUI
Getting Started with Vim The Minimum, Basic Vim Workflow
Vim comes in different variants, most notably: The u key undoes the most recent edit.
vim-minimal: A lightweight version with the basic vi The x key deletes a single character.
The :w command writes (saves) the file and remains in command mode for
editor functionality. more editing.
vim-enhanced: A more feature-rich version that The :wq command writes (saves) the file and quits Vim.
includes an online help system, syntax highlighting, The :q! command quits Vim, and discards all file changes since the last
write.
and various other tools to improve productivity.
On most modern systems, if you type vi filename, you'll
Customizing Vim with Configuration Files
Vim is highly customizable, and its behavior can be altered using configuration files.
likely get the vim editor, especially if vim-enhanced is The two main files are:
installed. However, users can manually invoke vim by 1. /etc/vimrc: This file affects all users on the system.
2. ~/.vimrc: This file affects only the individual user.
typing vim filename. In these files, you can set preferences like:
if vim-minimal is installed If vim-enhanced is installed
Default tab spacing (for example, set ts=4 for a tab width of 4 spaces).
vi filename vim filename
Syntax highlighting.
Line numbering.
Change the Shell Environment: If you have a file path stored in a variable, you can use the
In the Bash shell, variables are used to store values that variable in commands like ls or rm:
Expl
can be used in commands and scripts. These variables can file1=/tmp/tmp.z9pXW0HqcC
be set for a particular shell session, modified, exported ls -l $file1 # Shows file details
rm $file1 # Removes the file
as environment variables, and used by other programs.
1. Shell Variables Curly Braces:
A shell variable holds a value and can be used to simplify If you need to use a variable next to other characters (e.g., a
command execution or configure the shell's behavior. string with additional characters), it's a good idea to enclose the
Setting a variable: To assign a value to a shell variable, use the variable name in curly braces . This avoids ambiguity.
following syntax: [user@host ~]$ VARIABLENAME=value Expl
Variable names: They cannot start with a digit. echo Repeat ${COUNT}x # Prints: Repeat 40x
2. Listing Shell Variables
To list all variables currently set in the shell, use the set 4. Shell Behavior and Built-in Variables
command. This lists both shell variables and functions. You can Some shell variables are pre-set by Bash and control
use less to view the output one page at a time: [user@host ~]$ set | less
the shell's behavior. For example:
3. Variable Expansion HISTFILE: Specifies where the shell history is
To retrieve the value of a variable, use variable expansion, which
saved.
involves preceding the variable name with a dollar sign ($). This is
HISTFILESIZE: Defines how many commands to
typically done with commands like echo.
keep in history.
Expl
COUNT=40
PS1: Defines the shell prompt appearance.
echo $COUNT # Prints: 40
5. Environment Variables 6. Making Variables Permanent
An environment variable is a special type of variable To set variables permanently, you can modify shell
that is inherited by programs run from the shell, initialization files (such as .bashrc or .bash_profile)
allowing you to configure their behavior. You can set Interactive Shells:
environment variables using the export command. These are shells where you interact with the system (e.g.,
Setting an environment variable: when you open a terminal). For interactive shells,
Expl variables are usually set in the ~/.bashrc file.
export EDITOR=vim # Sets the default text editor Login Shells:
These are shells that are started when you log in (locally
Some common environment variables: or via SSH). You can modify the ~/.bash_profile file to set
LANG: Sets the system language and locale (e.g., variables that should only be applied after login.
en_US.UTF-8 for US English). For system-wide settings, you might use
PATH: Lists directories where executables are /etc/profile or /etc/bashrc.
located. When you run a command, the shell looks for 7. Shell Aliases
the command in each of these directories. An alias is a shortcut for a command. If you regularly use
HOME: Points to the current user's home directory. a long command, you can create an alias to simplify it.
Expl To make aliases permanent, add them to the ~/.bashrc f.
export PATH=$PATH:/home/user/sbin
# Adds /home/user/sbin to the PATH
8. Unsetting Variables and Aliases