FE Notes Tips

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

CHAPTER 1: Linux properties & distributions

(Feb 22 Q1)
LINUX PROPERTIES (Advantages)
1. Free and Open Source:
-Cost-free, available for download from the Internet without registration fees.
-Open-source nature allows users to access and modify the source code freely.

2. Portability and Hardware Compatibility:


-Highly portable across various hardware platforms
-Adaptable to new machines with freely available documentation.
-This flexibility extends to embedded systems like car CPUs.

3. Continuous Operation:
-Designed for continuous operation without frequent reboots.
-Automated tasks during off-peak hours contribute to higher availability.
- Suitable for environments with limited system monitoring.

4. Secure and Versatile:


-Built on the strong UNIX security model, Linux provides secure environment adaptable to diverse
use cases.
-This versatility extends beyond internet security, meeting high standards in many applications.

5. Scalability and Efficient Resource Usage:


-Scalable from palmtops to petabyte storage clusters.
-Users can tailor the system by adding or removing packages.
-Whether powering supercomputers or recycling old hardware, it efficiently adapts to diverse
computing needs.

6. Short Debug Times:


-Benefits from a large developer community, ensuring rapid bug discovery and resolution.
-With thousands of contributors, bugs are often fixed within hours of detection, leading to a highly
responsive development cycle.

LINUX DISTRIBUTION (Brief Explanation)


1. Linux distribution is a complete operating system that user can use.
2. Has at least one version of kernel, installation system, basic drivers, utilities, and networking tools.
3. Has software package system for managing, selecting, and updating software.
4. Package systems like RPM or source code are used for installing and maintaining software
packages in the distribution
5. Offers a ready-to-use, functional environment with everything a user needs for a working system.
EXAMPLES of LINUX DISTRIBUTION
1. Ubuntu: User-friendly & popular. Based on Debian. Widely used for desktop and server.

2. Debian: Stable and versatile. Strong open-source principles. A foundation for other distributions.

3. OpenSUSE: Has community and enterprise versions. Features YaST tool for easy system
configuration.

4. Fedora: Cutting-edge distribution, sponsored by Red Hat. A testing ground for new distribution.
Emphasizes the use of latest software.

5. Linux Mint: Based on Ubuntu. Elegant and user-friendly desktop experience. Includes multimedia
program for enhanced usability.

LINUX ADVANCED SECURITY SYSTEM (Brief explain)


1. UNIX Security Model: Built on the robust UNIX security model known for its reliability.

2. Open-Source Collaboration: Open-source nature allows a large community to promptly identify


and fix security issues.

3. Security Updates: Distributions provide frequent security updates to patch vulnerabilities


proactively.

4. User Permissions: Limits access with specific user and process permissions. Ensures protection
against unauthorized access.

5. Firewall Defense: Offer powerful firewall tools for admins to set network traffic rules. Adds extra
layer of defense.

6. Flexibility & Customizability: Linux's flexibility enables tailored security measures

ARCHITECTURE of LINUX SYSTEM (2 structure)

1. Applications: Software programs or applications that users interact with, providing various
functionalities.

2. Shell: The shell interprets user commands and facilitates communication between the user and
the kernel.

3. Kernel: The core of the operating system that manages hardware resources and ensures proper
interaction between software and hardware components.
4. Hardware: Physical components like terminals, printers, and disks that the kernel manages for the
system's overall operation.

5. Utilities: Additional tools and programs that assist in various tasks, enhancing the functionality of
the system.

1. User Commands: Executable programs and scripts that users run to perform tasks on the Linux
system.

2. Shell: The shell interprets user commands, finding and starting their execution. Bash is a popular
shell among several available.
3. Kernel: Manages hardware resources for the entire system, ensuring efficient communication
between software and hardware components.

4. File Systems: Organize and store data on storage devices, providing a structured way to access and
manage files.
5. Device Drivers: Enable the operating system to communicate with hardware devices, ensuring
proper functionality and interaction.

6. Hardware: Physical components of the computer, including devices like CPU, memory, and
storage. The kernel manages these resources for the entire system.

THEORY (Based on A1)


a. Brief history of Linux:
- Origins: Created in 1991 by Linus Torvalds as a Unix-like operating system kernel. (unix – old os)
- Open Source: Allows a global community to contribute and improve it.
- Evolution: Evolved into a versatile and widely used operating system.

b. Operating system design:


- Follows Unix-like design + features a multi-user, multitasking environment.
- The kernel manages system resources and serves as the core component.
- The modular design allows for customization and scalability.

c. Development and distribution:


-Linux development involves a collaborative effort from a global community of developers.
-Various Linux distributions package the Linux kernel with additional software and tools.
- Ubuntu, Fedora, Debian are popular Linux distributions.

d. Uses of Linux: Servers, Embedded Systems, Desktops, Development


SHELL SCRIPT (based on assignment)

You are tasked with creating a shell script that provides various system management functionalities
through a user-friendly menu. The script allows users to perform operations:

Question: Implement a shell script with the following options:


Option 1: Allows users to list the contents of a directory.
Option 2: View running processes on the system.
Option 3: Change permissions of a specific file.
Option 4: Move a file or directory from one location to another.

The script includes a menu where users can enter a choice (1-4) to execute the corresponding option.
After completing an operation, users are asked whether they want to continue or exit the script.

#!/bin/bash

while true; do
# Display menu
echo "System Management Menu"
echo "1. List contents of a directory"
echo "2. View running processes"
echo "3. Change permissions of a file"
echo "4. Move a file or directory"
echo "5. Exit"

# Prompt user for choice


read -p "Enter your choice (1-5): " choice

case $choice in
1)
# Option 1: List contents of a directory
read -p "Enter the directory path: " directory
ls -l $directory
;;

2)
# Option 2: View running processes
ps aux
;;

3)
# Option 3: Change permissions of a file
read -p "Enter the file path: " file
read -p "Enter the new permissions (e.g., 755): " permissions
chmod $permissions $file
;;

4)
# Option 4: Move a file or directory
read -p "Enter the source file/directory path: " source_path
read -p "Enter the destination path: " destination_path
mv $source_path $destination_path
;;

5)
# Option 5: Exit the script
echo "Exiting the script."
exit 0
;;

*)
# Invalid choice
echo "Invalid choice. Please enter a number between 1 and 5."
;;
esac

# Ask user whether to continue or exit


read -p "Do you want to continue? (yes/no): " continue_choice
if [ "$continue_choice" != "yes" ]; then
echo "Exiting the script."
exit 0
fi

done

Meaning.

#! = begins the code


/bin/bash = path to run
echo = display/output
read -p = enter input (‘choice’ is a variable)
$ = call variable
case $choice in = case statement – expression - ‘in’ keyword
esac = ends the case
*input*) = case input
# = comment
;; = break case
DIRECTORIES & FILES

(Feb 23 Q6)
FILE PERMISSION + OCTAL
ls – l command: Displays the contents of the current directory + assigned permissions for each file or
subdirectory

i. rwxr--r--
- Octal: 744
- Meaning: The owner has read (4) + write (2) + execute (1) permissions, and the group and others
have read (4) permissions.

ii. r-xr-xr-x
- Octal: 555
- Meaning: The owner, group, and others have read (4) + execute (1) permissions.

iii. rwxr-xr-x
- Octal: 755
- Meaning: The owner has read (4) + write (2) + execute (1) permissions, and the group and others
have read (4) + execute (1) permissions.
FILE OWNERSHIP

Q: Change the ownership of a file named "file.txt" to a user named "user1" in Linux. Provide the
command to do so.

A: chown user1 file.txt

CHANGE FILE OWNERSHIP WITH CHOWN AND CHGRP

The user root can use the chown command to change the user and group affiliation of a file by using
the following syntax:

chown new_user.new_group file

To change the owner, but not the group


chown new_user file

To change the group, but not the user


chown .new_group file

Change the group affiliation of a file with the chgrp command:


chgrp new_group file

Normal users can use the chown command to allocate a file that they own to a new group:
chown .new_group file
TEXT EDITORS
1. vi: Classic and powerful text editor with different modes for editing and commands.

2. emacs: Versatile text editor with many features, known for flexibility.

3. xemacs: Variant of Emacs with graphical enhancements for X Window System.

4. xedit: Simple text editor for basic tasks in the X Window System.

5. gedit: Default text editor for GNOME desktop, easy for everyday use.

6. kwrite: Default text editor for KDE desktop, simple and efficient.

UMASK (user mask)

Definition:
-In Linux, `umask` is a command that controls default file permissions for new files and directories. The
`umask` value subtracts from the maximum permissions to determine the default permissions.

How it works:
- The umask value is subtracted from the maximum permission setting (usually 666 for files and 777
for directories).
- The result is the default permission that newly created files or directories will have.

Example:
- If the umask is set to 022, it means the default permissions for files will be 666 - 022 = 644, and for
directories, it will be 777 - 022 = 755.

Setting a specific umask value:


- To set a specific `umask` value, you use the `umask` command followed by the octal value. For
example, to set the `umask` to 022: umask 022
PROCESSES

1) DAEMON – THEORY

Definition: A daemon process in a computer system is a background process that runs independently
of any direct user interaction.

Characteristics:
- No User Interaction: Usually run without direct user involvement.
- Background Operation: Operate in the background, performing tasks or services.
- Long-Running: Designed to be long-running processes.

Examples: Web Servers, System Services

Purpose:
- Continuous Operation: Ensure that certain functions or services are available continuously.
- Efficiency: Contribute to the efficient operation of the system by handling tasks independently.

In summary, daemons are background processes in a computer system that operate independently
to provide continuous services or perform various tasks.

2) FOREGROUND VS BACKGROUND

Foreground:
- User Interaction: Processes run in the active, visible part of the computer screen where users interact
directly.
- Blocking: Often block the user interface, and user may need to wait for their completion before doing
other tasks.
- Examples: Running a command in the terminal without using backgrounding techniques, or
interacting with a graphical application directly.

Background:
- No Direct User Interaction: Processes run independently of direct user interaction, often without
blocking the user interface.
- Non-blocking: Allow users to continue interacting with the system while the processes run.
- Examples: Running a process in the background in the terminal using '&' or using background services
like daemons or background jobs.
Key Difference:
- Visibility:
FG are visible and interact directly with the user.
BG operate independently, not directly interacting with the user interface.
- User Engagement:
FG require user engagement.
BG allow users to continue working on other tasks.

END A PROCESS
killall command kills all processes with an indicated command name
kill command kills only the indicated process

terminate in control manner: kill -15 <pid>

forcefully terminate it/stop: kill -9 <pid>

CRON JOB

Syntax: Minute Hour Day_of_Month Month Day_of_Week Command_to_Run

Minute (0-59): The minute when the task should run.


Hour (0-23): The hour when the task should run.
Day_of_Month (1-31): The day of the month when the task should run.
Month (1-12 or names): The month when the task should run.
Day_of_Week (0-6 or names): The day of the week when the task should run (Sunday is 0 or 7).

EX 1: Original Cron Job: Run a script every day at 3:30 PM.

30 15 * * * /path/to/your/script.sh

Translation:

Minute: 30
Hour: 15 (3:30 PM)
Day_of_Month: Any day (*)
Month: Any month (*)
Day_of_Week: Any day of the week (*)
Command_to_Run: /path/to/your/script.sh

EX 2: Original Cron Job: Run a backup script every Sunday at midnight.

0 0 * * 0 /path/to/backup-script.sh

Translation:

Minute: 0
Hour: 0 (midnight)
Day_of_Month: Any day (*)
Month: Any month (*)
Day_of_Week: 0 (Sunday)
Command_to_Run: /path/to/backup-script.sh
EX 3: Original Cron Job: Run a cleanup script every weekday at 2:30 PM.

30 14 * * 1-5 /path/to/cleanup-script.sh

Translation:

Minute: 30
Hour: 14 (2:30 PM)
Day_of_Month: Any day (asterisk *)
Month: Any month (asterisk *)
Day_of_Week: 1-5 (Monday to Friday)
Command_to_Run: /path/to/cleanup-script.sh

NETWORK CONFIGURATION
Open SSH (secure shell) THEORY

-Definition:
A cryptographic network protocol that provides a secure way to access and manage network devices
and systems over an unsecured network.

-Key Features:
Secure Communication:
- Encrypts data transmitted over the network, ensuring confidentiality.
- Uses strong authentication methods, including passwords and public-key cryptography.

Remote Access:
- Allows users to log into remote machines and execute commands as if they were directly interacting
with the local machine.
- Provides a secure alternative to traditional methods like Telnet.

File Transfer:
- Supports secure file transfer between systems using SCP (Secure Copy) or SFTP (Secure File Transfer
Protocol).

Port Forwarding:
- Allows the creation of secure tunnels for forwarding network connections.

Tunneling:
- Supports tunneling of other protocols, enhancing security for various applications.

Authentication:
- Uses key-based authentication, improving security over password-based methods.
- Supports two-factor authentication for an added layer of security.

Configuration:
- SSH configuration is managed through the `ssh_config` and `sshd_config` files.
- Various options allow users to customize the behavior of SSH connections.
-Use Cases:
Server Administration: Remote management of servers and network devices.
Secure File Transfer: Securely transfer files between local and remote systems.
Tunneling: Establish secure tunnels for accessing services on remote machines.
Automated Tasks: Used in scripts and automated processes for secure communication.
Git and Version Control: Often used for secure access to Git repositories.

Commands:
ssh: Command to establish an SSH connection to a remote server.
scp: Command for secure file copying between local and remote systems.
sshd: SSH server daemon responsible for accepting connections.

SSH is a crucial tool for secure remote access, file transfer, and tunneling. It plays a significant role in
secure system administration and communication across networks.

You might also like