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

Module 5 – Linux System Administration

Module 5 covers Linux System Administration, focusing on file editors like Vi, the 'sed' command for text manipulation, and user account management. It details commands for creating, modifying, and deleting user accounts, as well as switching users and monitoring user activities. Additionally, it introduces Linux Directory Services for account authentication and various system utility commands.

Uploaded by

Gaurav Dubey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views26 pages

Module 5 – Linux System Administration

Module 5 covers Linux System Administration, focusing on file editors like Vi, the 'sed' command for text manipulation, and user account management. It details commands for creating, modifying, and deleting user accounts, as well as switching users and monitoring user activities. Additionally, it introduces Linux Directory Services for account authentication and various system utility commands.

Uploaded by

Gaurav Dubey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Module 5 – Linux System Administration

 Linux File Editors (vi text editor)


Vi edit Modes
The Vi editor has two modes: Command and Insert. When you first open a file with Vi, you
are in Command mode. Command mode means you can use keyboard keys to navigate,
delete, copy, paste, and do a number of other tasks—except entering text.
To enter Insert mode, press i. In Insert mode, you can enter text, use the Enter key to go to a
new line, use the arrow keys to navigate text, and use vi as a free-form text editor. To return
to Command mode, press the Esc key once.
In Vi's Command mode, almost every letter on the keyboard has a function.
To save a file, you must first be in Command mode. Press Esc to enter Command mode, and
then type :wq to write and quit the file. The other, quicker option is to use the keyboard
shortcut ZZ to write and quit. In Vi, write means save, and quit means exit. If you’ve made
mistakes along the way while editing and want to back out (abandon) all non-saved changes,
enter Command mode by pressing Esc and typing :q! This command quits without saving
any changes and exits Vi.
Note: Always make a copy of an existing file prior to editing with Vi or any editor. This is
especially critical when editing system and configuration files
Vi shortcuts
The best way to learn Vi is to create a new file and try it out for yourself. Feel free to use the
common keyboard shortcut list below to help you learn Vi’s extensive vocabulary. This list
of shortcuts is by no means exhaustive, but they will enable you to edit files and learn Vi in a
short amount of time.
 $ vi <filename> — Open or edit a  I — Insert text at the beginning of
file. the current line.
 i — Switch to Insert mode.  b — Go to the beginning of the
 Esc — Switch to Command mode. word.
 :w — Save and continue editing.  e — Go to the end of the word.
 :wq or ZZ — Save and quit/exit vi.  x — Delete a single character.
 :q! — Quit vi and do not save  dd — Delete an entire line.
changes.  Xdd — Delete X number of lines.
 yy — Yank (copy) a line of text.  Xyy — Yank X number of lines.
 p — Paste a line of yanked text  G — Go to the last line in a file.
below the current line.  XG — Go to line X in a file.
 o — Open a new line under the  gg — Go to the first line in a file.
current line.  :num — Display the current line’s
 O — Open a new line above the line number.
current line.  h — Move left one character.
 A — Append to the end of the line.  j — Move down one line.
 a — Append after the cursor’s  k — Move up one line.
current position.  l — Move right one character.
 “sed” command
Linux 'sed' command stands for stream editor. It is used to edit streams (files) using regular
expressions. But this editing is not permanent. It remains only in display, but in actual, file
content remains the same.
Primarily, it is used for text substitution; additionally, it can be used for other text
manipulation operations like insert, delete, search, and more. The sed command allows us to
edit files without opening them. Regular expression support makes it a more powerful text
manipulation tool.
Overview of sed command
It is a Unix utility that transforms and parses text with a compact and simple programming
language. It was integrated from 1973 to 1974 by Lee E. McMahon of Bell Labs and is
present today for almost every operating system. The sed command was based on the
scripting aspects of the earlier qed (quick editor) and the ed interactive editor. It was the
earliest tool for supporting regular expressions, and remains active for text processing, most
importantly with the substitution command. Famous alternative tools include Perl and AWK
for "stream editing" and plaintext string manipulation.
Operation Mode of sed Command
The sed command is a text processing line-oriented utility: it line by line reads text from a
file or input stream into an internal buffer known as the pattern space. All line reads begin a
cycle. The sed command uses one or multiple operations which have been described by a sed
script to the pattern space. It operates a programming language using about 25 commands
that describe the operations over the text.
Usage of sed Command
Substitution command
The below example represents the most command and typical use of the sed command, i.e.,
substitution. The usage was the actual motivation for the sed command:
sed 's/regexp/replacement/g' inputFileName > outputFileName
Other commands of sed
Other ways are also possible for simple processing with some 25 sed commands. For
instance, below uses the d option for filtering out lines that only include spaces and the line
character end: sed '/^ *$/d' inputFileName
o The above example uses a few of the below regular expression metacharacters:
o The caret (^) is the same as the starting of the line.
o The dollar symbol ($) is the same as the completion of the line.
o The asterisk (*) is the same as the more or zero previous character occurrence.
o The plus symbol (+) is the same as the one or multiple previous character occurrences.
o The question mark (?) is the same as the more or zero previous character occurrence.
o The dot symbol (.) is exactly the same as one character.
sed as a filter
Often, the sed command is used as the filter inside a pipeline under Unix:
$ generateData | sed 's/x/y/g'
The generateData program generates data, and the sed command makes a small change by
substituting x in place of y.
File-based sed scripts
Often, it's helpful to put many sed commands, a single command per each line, inside a script
file and use the -f flag to execute the commands from the file:
sed -f subst.sed inputFileName > outputFileName
Syntax:
sed [OPTION]... {script-only-if-no-other-script} [input-file]...
Options:
The following are some command line options of the sed command:
-n, --quiet, --silent: It forcefully allows us to print of pattern space.
-e script, --expression=script: It is used to add the script to the commands to be executed.
-f script-file, --file=script-file: It is used to add the contents of script-file to the commands
to be executed.
--follow-symlinks: it is used to follow symlinks when processing in place.
-i[SUFFIX], --in-place[=SUFFIX]: it is used to edit files in place (creates backup if
SUFFIX option is supplied).
-l N, --line-length=N: It is used to specify the desired line-wrap length for the `l' command.
--posix: it is used to disable all GNU extensions.
-E, -r, --regexp-extended: It allows us to use the extended regular expressions in the script
(for portability use POSIX -E).
-s, --separate: it is used for considering files as separate rather than as a single and continues
the long stream.
--sandbox: It is used to operate in sandbox mode.
-u, --unbuffered: It is used for loading the minimal amounts of data from the input files and
flushes the output buffers more often.
-z, --null-data: It is used to separate lines by NUL characters.
--help: it is used to display the help manual.
--version: It is used to display version information.
 User account management
Managing user accounts in Linux involves various tasks such as creating new users,
modifying existing user accounts, and deleting users. Here's a basic overview of how it's
done:
1. Creating a New User: The `adduser` or `useradd` command is used to create a new user
in Linux. For example:
bash
sudo adduser username
2. Setting Password: Once the user is created, you'll want to set a password for the user.
You can use the `passwd` command for this:
bash
sudo passwd username
3. Modifying User Account: You can modify various aspects of a user account using the
`usermod` command. For instance, to change the username:
bash
sudo usermod -l newusername oldusername
4. Changing User Password: To change the password for a user, you can use the `passwd`
command followed by the username:
bash
sudo passwd username
5. Deleting User Account: If you need to remove a user account, you can use the `userdel`
command. Be careful, as this will delete the user's home directory by default:
bash
sudo userdel username
6. Granting Administrative Privileges: To grant administrative privileges to a user, you
can add the user to the `sudo` group. This allows the user to perform administrative tasks
using sudo:
bash
sudo usermod -aG sudo username
7. Viewing User Information: You can view information about users using the `id`
command or `cat /etc/passwd`. This will display details such as username, user ID (UID),
group ID (GID), home directory, and default shell.

These are the basic commands for managing user accounts in Linux. Depending on your
specific requirements and distribution, there may be additional options or tools available for
user management. Always ensure you have the appropriate permissions and understand the
implications of the actions you take when managing user accounts.
 Switch users and Sudo access
In Linux, switching users and using `sudo` for administrative tasks are common operations
that help manage system resources securely. Here's how you can do both:
Switching Users:
1. su Command: The `su` command allows you to switch to another user account. By
default, if you don't specify any username, it switches to the root user.
bash
su [username]
For example, to switch to the user named "john":
bash
su john
2. su with Dash: If you want to simulate a full login for the user (source their login
environment), use `-` after `su`.
bash
su - [username]
This ensures that the environment variables and paths are set up as if you had logged in
directly as that user.
3. exit Command: To return to your original user account, simply type `exit`.

Using sudo:
`sudo` is used to execute commands with administrative privileges. Users need to be granted
permission to use `sudo` via the `/etc/sudoers` file, typically by being added to the `sudo`
group.
1. Running a Single Command: You can use `sudo` followed by the command you want to
execute with elevated privileges.
bash
sudo [command]
For example:
bash
sudo apt update
2. Running a Shell with Elevated Privileges: You can also start a shell with elevated
privileges.
bash
sudo -i
This will start a root shell, allowing you to execute multiple commands with elevated
privileges without prepending each with `sudo`.
3. sudo su: Although not recommended due to potential security risks, you can also switch
to the root user shell directly using `sudo su`.
bash
sudo su
This essentially switches to the root user's shell until you exit from it.
 Monitor users
Monitoring users in Linux can involve several aspects, including tracking user activities,
resource usage, login/logout times, and more. Here are some methods you can use:
1. Monitoring User Activities:
a. Using the `last` Command:
The `last` command displays a list of last logged in users and their login/logout times.
bash
last
b. Using the `who` Command:
The `who` command displays who is currently logged in and what they are doing.
bash
who
2. Monitoring Resource Usage:
a. Using `top` Command:
The `top` command displays real-time information about system resources, including CPU,
memory, and processes. It can help identify users consuming significant resources.
bash
top
b. Using `htop` Command:
Similar to `top`, `htop` provides a more user-friendly interface for monitoring system
resources.
bash
htop
3. Monitoring User Commands:
a. Using `history` Command:
The `history` command shows the command history of the current user, which can help track
their recent activities.
bash
history
4. Monitoring Login Attempts:
a. Using `auth.log` File:
The `/var/log/auth.log` file records authentication activities, including successful and failed
login attempts.
bash
cat /var/log/auth.log | grep "user"
5. Monitoring User Processes:
a. Using `ps` Command:
The `ps` command displays information about active processes, including those owned by
specific users.
bash
ps -u username
6. Monitoring File System Activities:
a. Using `auditd` (Audit Framework):
The `auditd` service can be used to monitor file system activities, such as file access,
modifications, and deletions.
7. Monitoring Network Activities:
a. Using `tcpdump` Command:
The `tcpdump` command captures and displays network traffic, which can help monitor
network activities associated with specific users.
bash
sudo tcpdump -i any -n host [user_ip_address]
 Talking to users (users, wall, write)
In Linux, you can communicate with other users who are logged into the system using
various commands such as `write`, `wall`, or simply by sending messages through the
terminal. Here's how you can do it:

1. Using `write` Command:


The `write` command allows you to send messages to another user who is logged into the
system.
bash
write [username] [terminal]

2. Using `wall` Command:


The `wall` command is used to send a message to all users who are currently logged into the
system.
bash
wall [message]

3. Sending Messages via Terminal:


You can also send messages to users who are logged into the system by directly typing
messages on the terminal and pressing Enter. These messages will appear on the terminals of
other users.

Note:
- To use the `write` command, the recipient user must have allowed messages from you.
They can enable or disable message reception using the `mesg` command.
- Using `wall` and sending messages via terminal typically require appropriate permissions,
such as being a superuser or having write access to certain system files.

These commands can be useful for system administrators or users collaborating on a shared
system to communicate important information or coordinate tasks. However, ensure to use
them responsibly and respect other users' privacy and workflow.
 Linux Directory Service - Account Authentication
Linux Directory Service refers to a centralized system used in Linux environments to
manage user accounts, groups, and authentication. One of the most common
implementations of this is LDAP (Lightweight Directory Access Protocol).
Here's a breakdown of how it works:

1. LDAP Server: An LDAP server, such as OpenLDAP, is set up to store directory


information. This information includes user accounts, group memberships, and other relevant
data.

2. Client Applications: Linux machines and applications can be configured to use LDAP for
authentication. This means that instead of maintaining user account information locally, they
query the LDAP server to authenticate users and authorize access.

3. PAM (Pluggable Authentication Modules): Linux systems use PAM to provide a


flexible framework for authentication. PAM can be configured to use LDAP for
authentication, allowing users to log in with their LDAP credentials.

4. NSS (Name Service Switch): NSS is used to provide system-wide configuration for
managing various sources of naming information, such as users, groups, hosts, etc. NSS can
also be configured to query LDAP for user and group information.

5. Configuration: To set up LDAP authentication, administrators need to configure both the


LDAP server and the client machines. This involves installing and configuring LDAP server
software, configuring client machines to use LDAP for authentication via PAM and NSS,
and ensuring that the LDAP server contains the necessary user and group information.

6. Security: Security considerations are paramount when setting up LDAP authentication.


This includes securing the LDAP server itself, encrypting communication between clients
and the LDAP server, and properly configuring access controls to ensure that only
authorized users can access the directory information.

Overall, LDAP provides a centralized and scalable solution for managing user accounts and
authentication in Linux environments. It simplifies administration tasks by centralizing user
account information and provides a single point of authentication for multiple systems and
applications.
 System utility commands (date, uptime, hostname, which, cal, bc etc.)
Here are some common system utility commands in Linux:
1. `date`: Displays the current date and time.
$ date
2. `uptime`: Shows how long the system has been running, including the current time, the
number of users, and the load average.
$ uptime
3. `hostname`: Prints the name of the current host system.
$ hostname
4. `which`: Locates the executable file associated with a given command.
$ which command_name
5. `cal`: Displays a calendar of the current month or any specified month/year.
$ cal [month] [year]
6. `bc`: An arbitrary precision calculator language. It can perform mathematical calculations
interactively or as part of a script.
$ bc
7. `top`: Provides dynamic real-time information about running processes, system memory,
and CPU usage.
$ top
8. `ps`: Reports a snapshot of the current processes.
$ ps
9. `df`: Shows disk space usage of file systems.
$ df
10. `du`: Estimates file space usage.
$ du [options] [files or directories]
 Processes and schedules (systemctl, ps, top, kill, crontab and at)
In Linux, various commands and tools are used for managing processes and schedules.
Here's a brief overview of each:
Sure, let's delve a bit deeper into each of these commands:

1. systemctl:
- Usage: `systemctl [command] [service]`
- Description: Used for controlling systemd services on modern Linux distributions.
Common commands include `start`, `stop`, `restart`, `enable`, `disable`, and `status`.

2. ps:
- Usage: `ps [options]`
- Description: Provides information about processes currently running on the system.
Options can be used to filter the output and display specific information about processes,
such as their PID, CPU and memory usage, user ownership, etc.

3. top:
- Usage: Simply type `top` in the terminal.
- Description: An interactive task manager that displays real-time information about
system processes, CPU usage, memory usage, and more. It continuously updates the display
and allows users to interactively manage processes.

4. kill:
- Usage: `kill [options] [PID]`
- Description: Used to terminate processes by sending them signals. The default signal sent
by `kill` is SIGTERM (15), which gracefully terminates the process. `kill -9` sends the
SIGKILL signal, which forcefully terminates the process.

5. crontab:
- Usage: `crontab [options]`
- Description: Used to manage user-specific cron jobs. Cron jobs are scheduled tasks that
run at specific intervals. The `crontab` command allows users to create, edit, list, and delete
their cron jobs. Jobs are defined in a cron table (`crontab`) file.

6. at:
- Usage: `at [options] time`
- Description: Used to schedule one-time tasks to be executed at a specific time in the
future. Unlike cron jobs, `at` jobs are executed only once at the specified time. The `at`
command allows users to specify the time when the command should be executed.

These commands and utilities are fundamental to managing processes and scheduling tasks
in a Linux environment, providing users with control over system resources and automation
capabilities.
 System Monitoring Commands (top, df, dmesg, iostat 1, netstat, free etc.)
1. top command
The top command is super useful for monitoring what processes are using the most CPU and
memory on your Linux system. It gives you a dynamic real-time view that updates
frequently to show any changes. To use it simply open a terminal type “top” and hit enter.
You then see a table with different columns like CPU and MEM usage percentages, process
IDs, user accounts running each process, and the actual command names.
Command:
top
This command continuously updates a screen, displaying various system metrics. Processes
are sorted by default based on CPU usage in descending order, presenting the most resource-
intensive processes at the top for quick monitoring and identification.

System Activity and Running Process & Their Up-time


2. vmstat command
The vmstat command helps monitor your Linux system’s memory and CPU usage over time.
It gives you snapshots of important statistics like memory, swap, IO, and CPU activity.
Command:
vmstat
As it runs you can see if any resources become constrained over time or if abnormal changes
are indicating a potential issue. Generally higher IO wait means disk bottlenecks while a
higher system/user CPU could mean an intensive application process.

Checking System Activity using vmstat Command


3. free command
The free command in Linux is used to display information about the system’s memory
usage. When you run the free command without any options, it provides details about the
total, used, and free physical and swap memory on your system.
Command:
free

System’s available Space and Cache Using free Command


4. iostat command
The iostat command reports statistics about disk input and output operations and CPU
utilization on Linux systems. It’s useful for monitoring disk performance and throughput.
This will help identify high disk utilization. Generally below 60% CPU idle time means
potential cpu CPU-constrained disk throughput. And increasingBusy% or long ServiceTime
may indicate a struggling drive.
Command:
iostat

Disk Performance and Activity using iostat Command


5. netstat command
The netstat command is super handy for monitoring network connections and activity on
your Linux machine. You can use it to see open ports, established connections, listening
services, packet statistics, and more. This helps you understand what’s happening on your
network.
Command:
netstat
This will display a table of network connections, protocols, connection states, processes
using each connection, and more.

Network Connections, Open Ports, Packets & Protocols using netstat Command
\

6. iotop command
The iotop command is great for monitoring disk I/O usage on a Linux system. It shows a live
view of the processes doing the heaviest disk read and write operations at any given moment.
Command:
sudo iotop
It will display columns with the I/O bandwidth used by each process, similar to how the top
shows CPU usage. It also calculates totals and percentages of disk activity. The main goal is
to identify processes that may be slowing your system down from disk I/O overloading.
Higher batch counts on the right often relate to heavier disk usage.

Display columns with the I/O bandwidth used by Each System Process
7. htop command
The htop command is a handy interactive process viewer that’s like an upgraded top version.
You see a real-time table of running processes with their CPU and memory usage, similar to
the top.
 Color coding so you can easily spot high-usage processes.
 Ability to scroll vertically and horizontally to see full commands, environment
variables, etc.
 Tree view to see parent-child process relationships.
 Easier process sorting and priority config.
 Send signals like pause, and kill directly in the interface.
Command:
sudo htop

Running processes with their CPU and memory usage


8. atop command
The atop tool is useful for monitoring overall Linux system performance over time. It shows
historical usage and trends for CPU, memory, disk I/O, network, and processes.
 Charts showing usage graphs over defined periods.
 Ability to sort/filter data with commands.
 Inspection of exact moments of peak usage.
 Sends warnings about abnormal resource usage.
Command:
atop
This can help to solve system-level data with application logs when troubleshooting issues.

Linux system performance and CPU, memory, disk I/O, network, and processes
9. nmon command
The nmon command stands for Nigel’s performance Monitor. It’s a handy tool for graphing
and monitoring live system statistics like CPU, memory, disks, network, processes, and
temperatures.
Command:
nmon
This will bring up an interactive interface showing graphs and measurements updating in
real-time on the terminal. It logs everything for later analysis.
Nmon Tool Interface

Use these keys to get the results you want from the Table:
 C: Shows CPU statistics and charts.
 N: Shows network statistics and charts.
 D: Shows disk statistics and charts.
 M: Shows memory statistics and charts.
 P: Shows detailed process statistics and charts.
 T: Shows temperature/sensor readings.
 /: Zooms graphs out/in on the time axis.
 R: Provides resource monitoring advice.
 s: Saves logs to CSV files for later analysis.
 c: Configuration menu to customize stats intervals, durations, etc.
 q: Quits and exits nmon.

10. iftop command


The iftop command is super useful for monitoring network usage and bandwidth in real-
time. It displays a table of the connections and traffic going through your network interfaces
much like the top displays process activity. iftop makes it easy to identify bandwidth-hungry
applications, unusual traffic spikes indicating issues, and general network usage patterns.
Command:
sudo iftop

Connected Devices on our Network with their IP addresses.


 OS Maintenance Commands
Here are some commonly used OS maintenance commands in Linux:
1. shutdown: This command is used to shut down or reboot the system. It provides options
to specify the time of shutdown or reboot and can also broadcast a message to all users
logged in.
Examples:
shutdown -h now # Shut down the system immediately
shutdown -r +5 # Reboot the system in 5 minutes

2. reboot: This command simply reboots the system immediately.


Example:
reboot # Reboot the system immediately

3. halt: The halt command stops all processes on the system and powers off the computer.
Example:
halt # Halt the system immediately

4. init: This command is used to change the runlevel of the system. However, modern Linux
distributions often use systemd or other alternatives to manage system initialization and
service management.
Example:
init 0 # Shut down the system
init 6 # Reboot the system

5. poweroff: This command powers off the system immediately.


Example:
poweroff # Powers off the system immediately

6. systemctl: If your Linux distribution uses systemd, you can use systemctl to manage
system services, including starting, stopping, enabling, or disabling them.
Example:
bash
systemctl poweroff # Shuts down the system
systemctl reboot # Reboots the system

These commands are essential for system administrators to manage system shutdowns,
reboots, and maintenance tasks.
 System logs monitor (/var/log)
Monitoring system logs in Linux, located in the `/var/log` directory, is crucial for
maintaining system health, diagnosing issues, and detecting potential security threats. Here's
a comprehensive guide on how to effectively monitor system logs in Linux:
1. Understanding Log Files:
- Linux systems generate various log files in the `/var/log` directory, each serving a
specific purpose. Common log files include:
- `syslog`: General system log capturing messages from system services, daemons, and
the kernel.
- `messages`: Similar to `syslog`, contains system messages including kernel and service
logs.
- `auth.log`: Records authentication attempts and related information.
- `kern.log`: Kernel-specific logs.
- `apache2/access.log` and `apache2/error.log`: Apache web server access and error logs.
- `mysql/error.log`: MySQL server error log.
- Other application-specific logs based on installed software.

2. Viewing Log Files:


- Command-line tools such as `cat`, `less`, `tail`, or `more` can be used to view log files.
cat /var/log/syslog
less /var/log/messages
tail -f /var/log/syslog # to continuously monitor the log file

3. Searching Log Files:


- Utilize tools like `grep` to search for specific patterns or keywords within log files.
grep "error" /var/log/syslog

4. Real-time Monitoring:
- Monitor log files in real-time using the `tail` command with the `-f` option.
tail -f /var/log/syslog

5. Log Rotation:
- Log files can grow large over time, consuming disk space. Use the `logrotate` utility to
rotate and compress log files periodically, managing disk space efficiently.

6. Analyzing Log Files:


- Regularly analyze log files to gain insights into system performance, security incidents,
and application errors. Identify trends and anomalies to take proactive measures.

7. Customizing Logging:
- Configure logging behavior by modifying configuration files like `/etc/rsyslog.conf` or
`/etc/syslog-ng/syslog-ng.conf`. Customize log levels, destinations, and formatting to suit
specific requirements.
 Changing System Hostname (hostnamectl)
To change the system hostname in Linux using `hostnamectl`, you can follow these steps:

1. Check Current Hostname:


Before changing the hostname, it's a good practice to check the current hostname:
hostnamectl

2. Set New Hostname:


To set a new hostname, you can use the following command, replacing `newhostname`
with the desired hostname:
sudo hostnamectl set-hostname newhostname

3. Verify the Change:


After setting the new hostname, verify that the change has taken effect:
hostnamectl

4. Reboot (Optional):
Sometimes, a system reboot might be required for the changes to fully take effect. You can
either reboot your system or restart the `systemd-hostnamed` service:
sudo systemctl restart systemd-hostnamed

5. Verify Again:
After rebooting or restarting the service, verify the hostname once more to ensure it
persists after a reboot:
hostnamectl

By following these steps, you can effectively change the hostname of your Linux system
using `hostnamectl`.
 Finding System Information (uname, cat /etc/redhat-release, cat
/etc/*rel*, dmidecode)
To find system information on a Linux system using the specified commands, you can open
a terminal and execute each command individually:
1. uname: Displays basic system information like kernel version, architecture, etc.
uname -a

2. cat /etc/redhat-release: Specifically, outputs information about the Red Hat release,
applicable to Red Hat-based systems like CentOS, Fedora, or RHEL.
cat /etc/redhat-release

3. cat /etc/*rel*: Displays release information from various Linux distributions. It looks for
files in the /etc directory that contain "rel" in their names.
cat /etc/*rel*

4. dmidecode: Provides detailed hardware information from the system's DMI (Desktop
Management Interface) table. This command usually requires root privileges.
sudo dmidecode

By running these commands, you'll gather comprehensive system information, including OS


version, distribution, hardware details, and kernel information.

 System Architecture (arch)


In Linux, the `arch` command retrieves the machine hardware architecture of the current
system. It provides a straightforward way to determine whether your system is running on a
32-bit or 64-bit architecture. To use it, simply enter:
arch
Upon executing this command, you'll receive output indicating the architecture of your
system, which typically will be either `x86_64` for 64-bit systems or `i686` for 32-bit
systems. Other possible outputs may include `arm`, `arm64`, `ppc64`, `ppc64le`, `s390x`,
depending on the underlying hardware architecture.
 Terminal control keys
In Linux terminals, various control keys are used for different purposes to manage processes,
navigate, edit commands, and perform other tasks efficiently. Here are some commonly used
terminal control keys:

1. Ctrl+C: Sends an interrupt signal to the currently running process, typically stopping it.
It's often used to terminate a running command or program.

2. Ctrl+Z: Suspends the currently running process, returning control to the shell. You can
later resume the suspended process in the foreground or background using the `fg`
(foreground) or `bg` (background) commands.

3. Ctrl+D: Sends an end-of-file (EOF) marker to the shell, indicating the end of input. If
typed at the beginning of a line, it will log out of the current session (similar to typing `exit`).

4. Ctrl+A: Moves the cursor to the beginning of the line.

5. Ctrl+E: Moves the cursor to the end of the line.

6. Ctrl+K: Deletes all text from the cursor position to the end of the line.

7. Ctrl+U: Deletes all text from the cursor position to the beginning of the line.

8. Ctrl+W: Deletes the word before the cursor position.

9. Ctrl+R: Initiates a reverse search through command history, allowing you to search for
previously entered commands.

10. Ctrl+L: Clears the terminal screen, similar to typing `clear`.

11. Ctrl+T: Swaps the current character under the cursor with the previous one.

12. Ctrl+Y: Pastes text that was previously deleted using Ctrl+U, Ctrl+K, or Ctrl+W.

13. Ctrl+S: Suspends terminal output (XOFF), useful for temporarily stopping terminal
output. Pressing Ctrl+Q resumes output (XON).

14. Ctrl+Q: Resumes terminal output (XON) after it has been stopped with Ctrl+S.

These are just a few of the many control keys available in Linux terminals, but they cover
some of the most commonly used ones for navigation, editing, and process management.
 Terminal Commands (clear, exit, script)
In Linux, terminal commands are fundamental for navigating and interacting with the
system. Here are explanations for the commands you mentioned:

1. `clear`: This command is used to clear the terminal screen, which means it removes all the
previous commands and output from the terminal window. It's useful when the terminal
becomes cluttered, and you want to start with a clean slate.
Example:
clear

2. `exit`: This command is used to exit the current shell or terminal session. When you type
`exit` and press Enter, it terminates the current shell session and returns you to the previous
shell or logs you out of the system if you're in the main shell session.
Example:
exit

3. `script`: This command is used to record everything displayed on the terminal during a
session. It can be helpful for logging purposes or to capture the output of a series of
commands for later reference. When you run `script`, it starts recording the session to a file
specified or defaults to `typescript`.
Example:
script mysession.log
This will start recording the session into a file named `mysession.log`. To stop recording,
simply type `exit` or press `Ctrl + D`.

These commands are quite handy for managing your Linux terminal sessions efficiently.
 Recover root Password (single user mode)
Recovering the root password in Linux using single-user mode involves booting into a
special mode where you have root access without needing the root password. Here's a
general procedure to do this:

1. Boot into GRUB menu: Restart your computer and when the GRUB menu appears
(usually after the BIOS/UEFI screen), select the Linux kernel you want to boot into but don't
press Enter yet.

2. Edit boot options: Press the "e" key to edit the boot parameters for the selected kernel.

3. Modify kernel parameters: Find the line that starts with "linux" or "linuxefi" and add
"init=/bin/bash" at the end of that line. This tells Linux to boot directly into a bash shell
instead of starting the usual init process.

4. Boot into single-user mode: Press Ctrl+X or F10 to boot with the modified parameters.

5. Remount the root filesystem: When the bash prompt appears, the root filesystem is
typically mounted as read-only. Remount it as read-write with the command:
mount -o remount,rw /

6. Change the root password: Now you can change the root password with the `passwd`
command:
passwd

7. Reboot: After changing the password, reboot the system:


reboot

After rebooting, you should be able to log in as root using the new password you set.
It's worth noting that accessing the system in this way can potentially pose a security risk, so
it's important to take appropriate precautions and ensure physical security of the machine.
 SOS Report
An SOS report (or Supportability and Operating System Report) in Linux is a diagnostic data
collection utility used primarily in Red Hat-based distributions like Red Hat Enterprise
Linux (RHEL) and CentOS. It gathers comprehensive information about the system's
hardware, software, configuration, and logs, which can be useful for troubleshooting issues
or requesting support from vendors.
To generate an SOS report:
1. Install the sos package: If the `sos` package is not already installed on your system, you
can install it using your package manager. For example, on RHEL/CentOS, you can use the
following command:
sudo yum install sos

2. Run the sosreport command: Once installed, you can generate the SOS report by
running the `sosreport` command as root:
sudo sosreport

3. Follow the prompts: The `sosreport` command will prompt you for additional
information, such as whether to include additional logs or specific subsystem data. You can
generally accept the defaults unless you have a specific reason to include or exclude certain
information.

4. Wait for the report to be generated: Depending on the size and complexity of your
system, generating the SOS report may take some time. Once complete, the report will
typically be saved as a compressed archive file (e.g., `sosreport-<hostname>-
<timestamp>.tar.xz`) in the current directory.

5. Share the report: You can share the generated SOS report with your support provider or
analyze it yourself to troubleshoot issues.

The SOS report contains a wealth of information, including system configuration files,
hardware information, kernel parameters, network configuration, logs, and more. This
comprehensive data can be invaluable for diagnosing and resolving issues on Linux systems.
 Environment variables
The environment variables are dynamic values that are stored within a system and used by
applications launched in shells or sub-shells. These variables have a name and their
respected value. The environment variable customizes the system performance and the
behavior of an application.

The environment is the track for a computer application to interact with the system. The
environment variable can have information about the default applications of the system, the
system locale, the path of the executable file and the keyboard layout setting, and more. The
environment variable makes an app available as per the system.
Common Environment Variables
Some standard environment variables are as follows:

1. PATH: Defines the directories where the system looks for executable files. When you type
a command in the terminal, the system searches for the executable file in these directories.
For example:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

2. HOME: Specifies the current user's home directory.


HOME=/home/user

3. USER or LOGNAME: Contains the username of the current user.


USER=user

4. SHELL: Defines the default shell for the user.


SHELL=/bin/bash

5. LANG or LC_ALL: Specifies the system's default locale. It determines the language and
cultural conventions used by the system and applications.
LANG=en_US.UTF-8

6. EDITOR or VISUAL: Specifies the default text editor to be used by command-line


programs.
EDITOR=nano

7. TMPDIR: Defines the directory where temporary files should be stored.


TMPDIR=/tmp

8. LD_LIBRARY_PATH: Specifies additional directories to search for shared libraries (.so


files) when executing a program.
LD_LIBRARY_PATH=/usr/local/lib:/usr/lib

9. DISPLAY: Defines the X display server to which GUI applications should connect.
DISPLAY=:0.0
10. TERM: Specifies the terminal type being used.
TERM=xterm

11. PS1: Defines the prompt string for the shell.


PS1=\u@\h:\w\$

12. PWD: Contains the current working directory.


PWD=/home/user

These environment variables play a significant role in configuring and customizing the
Linux environment, affecting how processes execute and interact with the system.

You might also like