Description:

  • Based on CompTia Linux+ Student Guide (exam XK0-005)
  • Linux namespace:
    • net:
    • icp:
    • cgroup:
      • memory management for processes
      • limit, kill/slow down if use too much
    • mount: manage disk
    • PID: processes managment
    • users:
  • Kernel startup:
    • Reads /etc/fstab and mounts the specified partitions to the listed mount points

1. Introduction:

Identify Linux Characteristics:

Bash interaction with Linux:

Use help:

Troubleshoot

  • Identify the problem.
  • Determine the scope of the problem.
  • Establish a theory of probable cause/question the obvious.
  • Test the theory to determine the cause.
  • Establish a plan of action.
  • Implement the solution or escalate the issue.
  • Verify full system functionality.
  • Implement preventive measures.
  • Perform a root cause analysis.

2. Administering users and group

Manage user accounts:

User configuration file:
  • User accounts are stored in text files. Admins dont edit these files directly but use commands to manage user accounts
  • User data are stored in: (each value is separated with a colon)
    • etc>passwd: all users have read permissions
      • user name
      • password as x
      • userID
      • groupID
      • comment: usually user full name
      • home directory path
      • default shell path
      • ex: vscode:x:1000:1000::/home/vscode:/bin/bash
    • etc>shadow: only root can access
      • username
      • hashed password
      • days since last pw changed, count from jan 1 1970
      • days before pw may be changed
      • days before pw must be changed
      • days until user is warned to change pw
      • days after pw expire that account is disabled
      • days until account expire
      • unused fields
System and User Profiles
  • Shell features such as command history are unique to each user and stored in the individual user’s home directories.
  • As a sysadmin, you can use a few different files to set the system up the way your institution prefers.
    • Use etc>profile to set system-wide environment variables and startup programs for new user shells.
    • Use etc>bashrc to establish system-wide functions and aliases for new user shells.
  • Users can customize their preferred settings as well.
    • The ~/.bash_profile sets user-specific environment variables for new Bash shells, and ~/.bashrc runs when noninteractive shells are launched.
  • The user-specific configuration files take precedence over system files
  • Sysadmin can store files in the etc>skel directory and have those files copy automatically to the home directory of any new user.
    • for pre-populating configuration files such as .bashrc with suggested settings for users or for distributing documents all users should have access to.
Account Management Commands
Account configuration commands:
Pluggable authenication models:

Manage group accounts

Group configuration files:
  • Group info are stored in etc>group
  • groupname:pw:groupid:user1,user2,..
  • every user in Linux must have a primary group
  • A file belongs to both user and a group
Group management commands:
  • groupadd
  • groupmod
  • groupdel
    • only delete group, not the members
    • cannot remove a primary group of a user, must delete user first
    • be sure to search for files/resources owned by that group before deleting the group
  • More used commands: addgroup, delgroup
Add user to group:

Configure Privilege Escalation

Privilege escalation:
  • root = system administrater
  • Login as user identity then change to root
    • good practice to log in with non-root account
  • Standard uer has privileges to manage their own data but not system data/config
  • Understand a disabled root account:
    • Many linux distributions disable root user account by default
      • instead assign users to be able to escalate to root
    • An admin account is created and has privileges delegated via sudo command instead
Elevate priviledges with su
Escalate with sudo
  • Delegation is done in the etc>sudoers file by using the visudo command
    • a mistake in this file can render it impossible to gain root privileges on the server
    • visudo helps verify the syntax for the file
  • check sudo privileges by sudo -l
  • The wheel group:
    • In Ubuntu, its called sudo group
    • Distros allow administrative functions based on membership in the wheel group.
    • Members of the wheel group exercise the administrative privileges of root with less potential for damaging the system.
  • sudoedit command
    • Appropriate for files that need to be edited with elevated privileges
    • ex: %editors ALL = sudoedit /path/to/file
    • Any member of the editors group could then enter the following command to edit a file: sudoedit /path/to/file
PolicyKit Rules:
  • different way of delegating privileges than sudo does.
  • The polkitd daemon works with systemd to permit administrators to delegate more granular control to users than sudo allows.
  • Unlike sudo, polkit does not grant full root access to a process but instead grants specific access to defined actions.
  • Configure polkit rules:

Troubleshoot user and group issues:

Troubleshoot User Management Issues:
  • Only authorized users may create, modify, or remove user and group accounts. The root user can do this, as can anyone else delegated such privileges via sudo.
  • Halt any active processes associated with the user. If the delete attempt fails, check for any running processes belonging to the user.
    • The ps command can be helpful for identifying processes.
    • killall command to halt or kill all processes for the user is: sudo killall -u {username}
  • Be sure to add the -r option to the userdel command if you want the user’s home directory deleted when the account is created.
Troubleshoot User Login Issues
  • If the account exists, confirm that a password is set.
    • Display the contents of etc>shadow, and verify a hashed password exists.
    • Use the passwd command to set a password if one did not exist.
  • If the account exists and a password is set, the user may have forgotten the correct password.
  • If the account exists and a password is set, the password may be expired.
  • If the account exists and a password is set, the account may be locked. Unlock the account by using the chage command.
Use User Login Commands:
  • The lastlog command displays the last login times for accounts.
    • This information allows administrators to know who was logged in at any given time.
    • The lastlog utility uses its own log file (usually found at var>log>lastlog).
  • The last command displays the contents of the wtmp file, which includes every login and logoff event on the system.
    • The output can be filtered by timestamp and even displays information for remote users.
    • The wtmp file is usually found at var>log>wtmp

3. Configure permissions

Configure standard permissions

Understand permission concepts
  • Principle of least privilege
  • There are 3 access levels:
    • read (r)
    • write (w)
    • execute (x)
  • Access identity:
    • User (u)
    • Group (g)
    • Others (o)
  • Only 1 user and 1 group is associated with a resource
    • by default, creator’s group is assigned as group owner, but can be changed
View permission
Default permissions:
  • Default permission of non-executable file is 666, umask command minus 2 or 4 to remove permission of according group
Absolute and symbolic mode:
  • chmod command
    • Only owner of the file/dir or sysadmin can change permissions of the object
  • Absolute mode:
    • base 8, 0 to 7 for 3 set of 3 permissions each
    • each set can be 4 digit, signifying any advanced permissions to be defined (or none or 0 )
  • Symbolic mode:
    • context: u/g/o/a (user, group, others, all 3)
    • op: +/-/=
    • attributes: r/w/x
    • ex: chmod 750 filea is chmod u=rwx,g=rx,o= filea
      • chmod u+x,g-x,o-x
Configure ownership
  • chown command for changing user and group owner
  • chgrp command for changing group owner
  • Other than the superuser, no other user can change the permissions of an object that is owned by someone else
Configure attributes:

Configure special permissions

Understand user and group ID
Understand Sticky Bit

Access Control List

4. Implementing File Management:

Linux File System:

Filesystem Hierarchy Standard
Display file metadata:
  • stat command
  • file command
  • file name:
    • up to 255 bytes
    • cannot contain NULL (\0) and the forward slash (/)
    • may not be a single dot . or two dots ..
Absolute path and relative path:
  • A path defines the series of directories to be traversed to find a specific file (or subdirectory)
  • absolute path defines the directories to traverse, starting from the root of the filesystem
  • relative path is dependent upon the user’s current location in the filesystem

Use file system command:

File management:
Display fules:
Display strings
  • grep command
  • Pipe character, |:
    • takes the output of one command and makes it the input of another.
    • One of the most common uses of pipe is in combination with grep command
Redirectors
  • Text stream:
    • a stream of one or more lines of text that applications can read from or write to a particular device or system component.
    • There are three stream types:
      • Standard input, or stdin, is a text stream that acts as the source for command input.
        • e.g. mouse and keyboard
      • standard output, or stdout, is a text stream that acts as the destination for command output.
        • By default, standard output from a Linux command is directed to the CLI.
      • standard error, or stderr, is a text stream that is used as the destination for error messages.
        • By default, the standard error stream prints error messages at the CLI.
  • Redirection is the process of accepting input data from a source (other than the keyboard) and sending output data to a destination (other than the display device)
  • Redirection is commonly used to accept input from files or send output to files using the stdin, stdout, and stderr streams
  • Redirector ops:
    • >: redirect stdout to a file
      • ex: ls > file.txt overrides the file with ls content
    • >>: append stdout to a file
    • 2>: redirect stderr to a file
    • 2>>: append stderr to a file
    • &>: redirect both stdout and stderr message to a file
    • <: read input from a file
    • <<(string): Provide input data from the current source, stopping when a line containing the provided string occurs. When placed in a script, this is called a here document.
Command modifiers:
  • Manipulate the commands, not the output.
  • Background a command &:
    • Normally, when a command is executed, it consumes the shell until it completes.
    • ./job.sh & executes the line in background
  • Chain commands
    • Piping |
      • process of combining the standard I/O streams of commands
      • use stdout of 1 command as stdin of another
    • ;
      • If the semi-colon character is placed between commands, they are run one after another, regardless of whether the previous command completed successfully.
    • &&
      • If the logical AND is placed between commands, the following command is only run after the previous command completed successfully. Useful for commands that rely on each other’s success.
    • ||
      • If the logical OR is placed between commands, the following command is only run if the previous command fails.
    • !
      • If the bang is placed in a command expression, it negates the expression. Used as a way of stating “except this.“
      • if ! [ -f /path/to/file ]; then
          echo "File does not exist."
          fi
  • tee command
  • xargs command

Find file locations:

Search commands:
File manipulation commands
  • echo command
  • printf command
  • tr command
  • wc command
  • sort command
  • cut command: extracts the specified lines of text from a file
  • paste command: used to merge lines from text files horizontally. Each line of an initial file is a row in the first column; using paste, you specify a second file, and every line of the second file becomes a row in a newly created second column.
    • By default, the paste command uses a tab space delimiter to separate each column. You can use the -d option to specify a different delimiter.
  • diff command: used to compare text files. The command displays the two files and the differences between them.
    • the output suggests how you can change one file to make it identical to the other. Each symbol has a special meaning. The less-than symbol (<) with a line after it means that line should be removed from the first file because it doesn’t appear in the second. The greater- than symbol (>) with a line after it means that line should be added from the second file.
  • awk command: performs pattern matching on files. It is based on the AWK programming language.
    • The awk keyword is followed by the pattern, the action to be performed, and the file name.
  • sed command: to modify text files according to various parameters. The sed command can also be used for global search and replace actions.
    • Stream EDitor
    • ex: sed 's/apple/orange/' file.txt

5. Authoring text files:

Edit text files:

Manage text files:

Archive and Extract with tar command
Copy In and Copy Out with cpio command
Copy and convert with dd command
Compress files
Compress folder:
Confirm file integrity
  • Good to perform integrity check to ensure backup files have not changed
  • Use

6. Manage software

Software management

Compiling source code:
  • There are 2 ways software applications are managed: Red Hat-based and Debian Linux-based
Package managementCompiling software
Software installed are precompiledSoftware is compiled at user’s device
not experiementalmore optimized for hardware and kernels as options can be chosen
complicated
Software packages
  • Package manager: install; maintain; tracker version, location, documentation; remove software and has a database that can report information about packages
  • Repository: a storage location for software packages
    • 3 location types:
      • Local repositories: easy installation but version control is hard
      • Centralized internal repositories: These repositories are stored on one or more systems within the internal LAN and managed by the Linux administrator.
      • Vendor repositories: These repositories are maintained on the Internet, often by the distribution vendor.
Red hat vs Debian package manager:
Software dependencies:
  • Modern package managers install supporting applications automatically, ensuring that a single installation command provides the user with everything needed to run the program.

Manage RPM software packages and repo

Red Hat Package Managers
  • Packages for Red Hat–derived distributions use the .rpm file extension
  • Both RPM and YUM are superseded by Dandified Yum (DNF), which includes all the same functionality as both with additional plugins and features
  • rpm command
  • yum command
  • dnf command
Repositories
  • Sysadmin can control available repositories include:
    • software version control: avoid beta by default
    • application installation control
    • Vendor control
    • bandwidth control
  • Admin use config files to inform package managers which repo are allowed and where they can be found in local network or internet
Manage config files for RPM repos
  • Sysadmins often prefer to maintain an internal repository on a local server that is referenced by all other Linux systems. This provides complete control over software availability and versions.
  • For yum command
  • .rpmnew file is created when .rpm file is installed and a customized configuration file is found
  • .rpmsave: a copy of admin’s modified configuration file

Manage debian-based software packages

Debian package managers
Manage APT repository configuration files
  • Sysadmins customize which repositories APT accesses. Repositories are exposed to APT in the etc>apt>sources.list file and in the /etc/apt/sources.list.d/ director
  • /etc/apt.conf: The file contains settings that are loaded when APT starts and controls installation priorities, proxies, and other settings. Depending on the distribution, the configuration file may be found at etc>apt.conf, etc>apt>apt.conf, or along other paths.

Compile from source code

Commands
  • 3 step process
    • the system mus be checked and compile instructions must be created
      • uses a configure script to ensure the necessary dependencies and compilers are available. The configure script creates a makefile containing the instructions for compiling the software.
      • ./configure
    • source code is compiled to machine language
      • In most cases, once the makefile is created, simply issuing the make command without arguments will compile the application. The make command automatically looks for the makefile in the current directory.
    • new software is installed
      • The make install command installs the program, placing the appropriate files in the appropriate locations (configuration files, log files, and so on). The software is now available and ready to run
Remove compiled software
  • The makefile includes all directories and files created during the installation process. Examine this file, and remove each file and directory specified in the makefile.

Acquire software:

wget command and curl command

Run software in a sandbox

Sandbox:
  • A sandbox is a virtual machine or container that isolates the application from the rest of the system and mediates communication between hardware resources and the program
  • An althernative is the chroot command, tells an application that a given dir is the highest point in filesystem, its still used today
Sandbox software:
  • Snaps
  • flatpak command
    • users can manage software on a system-wide or per-user basis
    • Repositories called “remotes” store software distributed as flatpaks
  • App image
    • AppImage applications are distributed and managed as a single file containing everything needed to run the application. Application developers decide what distributions to support and then ensure that all needed dependencies and libraries are included with the AppImage file. AppImage applications are standalone components, and while they can be installed in the traditional manner, they do not have to be. They can be accessed and run as mounted drives

7. Administering Storage

Understand storage

Storage
  • Traditional Hard Disk Partitioning versus LVM Deployment:
    • The basic process for adding storage to a system is to install the drive, partition it, add a filesystem, and then mount it.
    • In addition to traditional partitioning, technologies such as a Logical Volume Manager (LVM) permit the aggregation of storage space from multiple disks, providing flexibility and scalability options.
  • back to this soon
Storage interfaces
  • SATA: Serial Advanced Technology Attachment
  • SCSI: Small Computer Systems Interface
  • SAS: Serial Attached SCSI, upgraded SCSI
Types of partitions:
  • On a Linux server, these partitions may store different types of operating systems, applications, or data files.
  • Drive Partition
  • Linux supports FUSE
Set disk quotas
  • Storage quotas are configured on a per-user basis.
  • File systems that implement storage quotas can have a soft limit, a grace period, and a hard limit.
  • Once a user exceeds the soft limit, they will be placed in the grace period, the default setting for which is seven days.
  • Do this by editing the etc>fstab file to add the options usrquota and grpquota to the relevant file system.
  • A quota report contains the following details:
    • The name of the user/group.
    • The total number of blocks (in kilobytes) that are being used by the user/group on a file system.
    • The user’s/group’s storage soft limit.
    • The user’s/group’s storage hard limit.
    • The grace period.
    • The total number of inodes that have been used on a file system by the user/group.
    • The soft limit on inodes.
    • The hard limit on inodes.

Deploy storage:

Deploy a traditional hard drisk drive:
  • After add the drive physically, use these commands to check
  • Most references to the storage media includes a path. All hardware devices are mapped to the /dev directory.
  • Storage disks are displayed there using the sd* string
    • sda means storage disk a
    • sdb3 means third partition of storage disk b
Partition the drive:
  • Considerations such as MBR vs. GPT must be taken into account, and then you’ll partition the space using fdisk or parted. After creating the partitions, update the system with partprobe and confirm the partitions in the proc>partitions directory.
  • Partition Design:
    • If the partition where the root of the filesystem (/) resides fills, the system will crash. To prevent this, directories such as /home and /var (for logs), which are at risk for filling, are placed on separate partitions from /.
    • Linux use Memory Swap, Linux moves data between memory and the hard drive if the memory is in danger of being fully consumed. A dedicated swap partition is often set aside that is 1.5 times the quantity of the total RAM.
  • fdisk command
  • parted command
  • Whether you used fdisk or parted to create partitions on the new disk, the next step is to update Linux with the new information.
    • partprobe command
    • /proc/partitions file
      • stores Partition information which is recreated each time the system boots or the partprobe command is run.
      • The dynamic nature of this file means that it reflects changes to the system’s configuration (changes that are detected during system startup or via the partprobe command).
  • blkid command
    • The Universally Unique ID value of a partition is a more reliable identifier for the partition than the path /dev/sdb2 since the path is changeable.
    • example: blkid /dev/sda1 returns UUID, block_size, type
Add Filesystem to a partition:
Manually test mount:
  • Storage capacity is added to the FHS by a process called mounting. Capacity can be manually attached by using the mount command and detached by using the umount command
  • To mount the partition, first create a directory. The directory is referred to as a mount point.
    • create a new directory, and then issue the mount command:
    • mkdir /projects
    • mount /dev/sdb2 /projects
Test storage:
Automatically mount new storage
  • automate the process to occur during the system’s boot phase so that the space is immediately available to users.
  • systemd.mount file:
    • systemctl command is used to display and change settings within systemd.
    • systemctl -t mount: to display mounted partition information
    • steps:
      1. Get UUID by blkid command
      2. create systemd unit file by nano
      3. restart systemd service: systemctl deamon-reload
      4. start filesystem: systemctl start projects.mount
      5. enable filesystem: systemctl enable projcts.mount
  • etc>fstab
Manage Filesystem
Logical volume manager storage:
Deploy a logical volume manager
  • Once the disks are partitioned, create the LVM structure. First, you’ll designate the drives as LVM Physical Volumes (PV), then you’ll aggregate them into a Volume Group (VG), and finally, you’ll allocate Logical Volumes (LV). The Logical Volumes will be configured with filesystems
  • Deploying lvm:
    • create PV:
      • pvcreate /dev/sdb
      • pvcreate /dev/sbc
      • pvdisplay
    • create vg:
      • vgcreate ubuntu--vg /dev/sdb /dev/sbc
      • vgdisplay
    • create lv:
      • lvcreate --name ubuntu--lv --size 500G ubuntu--vg
      • lvdisplay
  • Resize LVM storage:
    • pvcreate command add more storage to the PV and VG
    • LV is then extended with the additional capacity
    • Once space is added to LV, file system must be resized to format and take advantage of the increased capacity (use ext or xfs tool)

Manage Other Storage Options

Linux Unified Key Setup
RAID
Network-attached Storage
Storage-area Network
  • Fibre Channel devices attached to server with fcstat command
  • Multipathing: Provide multiple connections between a server and its SAN storage devices.
    • The benefit is fault tolerance (in the event one path becomes unavailable) and performance (load balancing across paths).
    • multipathd command
Network file system for SAN
  • NFS and SMB protocols provide communication between network clients and the filesystem.
  • These operate on a higher level than iSCSI and Fibre Channel, which govern the communication between the hosting server and connected SAN storage.

Troubleshoot storage:

Disk performance:
  • IOPS (IO Operations per sec) by iostat command and ioping command
    • The ioping command generates a report of device I/O latency in real time. It will continuously “ping” the specified device with requests and print information about each request at the command line.
  • Input Output Scheduling
    • modern linux system uses CFQ by default
    • Set schedular on a particular device by modifying scheduler file in sys>block>device_name>queue>scheduler
      • ex: echo noop > /sys/block/sda/queue/scheduler
      • not permanent, most modify in bootloader
Capacity:
Filesystem issues:
  • Use fstrim command to proactively removes data instead of only marking space as available

8. Manage devices, processes, memory and kernel

Gather hardware info:

Hardware information tool:
Devices in dev> directory:
  • devices are represented with device files
  • The udev device manager provides plug-and-play functionality by generating device files when the system boots for whatever hardware devices it detects.
    • Note that the device files are not the same thing as the device drivers.
  • udev device manage, udevadm command:
    • detect hardware changes, remove/add hardware
  • ls -l /dev shows first field file type (device type)
  • 3 special device files:
    • dev>null is a special file is a writeable location that is used as a target for generated data that should be discarded. This data may be error messages that are redirected to /dev/null by using the 2> redirector.
    • dev>zero file is a way of filling storage capacity.
      • For example, to create a one MiB file named foo.txt, run the following command:
        • dd if=/dev/zero of=foo.txt count=1024 bs=1024
    • dev>urandom
Display CPU info
Display memory info:

Manage processes:

Process
Manipulate processes:
List running process and open files:
  • top command
    • For CPU:
      • us, user : time running un-niced user processes
      • sy, system : time running kernel processes
      • ni, nice : time running niced user processes
      • id, idle : time spent in the kernel idle handler
      • wa, IO-wait : time waiting for I/O completion
      • hi : time spent servicing hardware interrupts
      • si : time spent servicing software interrupts (wait for I/O access)
      • st : time stolen from this vm by the hypervisor (on virtual machine)
  • htop command, simplier version
  • ps command
  • lsof command
  • systemd-analyze command, systemd-analyze blame displays the processes that take the most time during boot
  • sar command
    • displays system usage reports based on data collected from system activity. These reports consist of various sections, each of which include the type of data and the time of data collection.
  • uptime command
Process states:
  • Process State
    • The sleeping state indicates a process awaiting access to resources. The state is a normal consequence of resource sharing. The sleep state has two substates: interruptible and uninterruptible.
    • Interruptible: The process waits for a specific time slot or event before attempting to enter the running state.
    • Uninterruptible: The process waits for a specific time-out value before attempting to enter the running state.
  • pstree command to see parent-child processes
Set priorities for CPU processes:
  • nice command
    • sudo nice -<priority> ./program.sh
    • used when start a process
  • renice command
    • change priority of a runnig process
  • processes are laucnhed with priority from -20 to 19, lower is more prioritized
    • most are 0 by default
Job control:
  • Normal process run in foreground (consume the shell until done), a job runs in background
    • run by adding & at the end, ex backup.sh &
  • jobs command display processes they are running in background
  • fg command: move a background job to foreground using %
    • ex: foreground the script with job nb 1, fg %1
  • bg command: move foreground process to background job
  • Jobs can also be managed by using the Ctrl meta key. The following key combinations are useful for managing jobs:
    • Ctrl+Z - Pauses a job temporarily, often so it can be moved to the background.
    • Ctrl+D - Exits the program and logs the user out of the current session.
    • Ctrl+C - Stops a running process.
  • nohup command
    • command prevents a process from ending when the user logs off (close terminal)
    • nohup <command/script?

Manage memory:

Virtual Memory
Memory Swap
  • mkswap command, it is not active when created
  • swapon command, enable devices and files for paging and swapping
    • -e, —ifexists: Silently skip devices that do not exist. The /etc/fstab mount option nofail may also be used to skip non-existing device.
    • -a: activate all
  • swapoff command: disable
    • -a: disable all
Memory exhaustion

Manage Linux Kernel

Kernel:
Manage Kernel Modules
  • kernel module management commands:
  • modprob command
    • add or remove modules from a kernel
    • Also capable of loading all dependent modules by reading modules.dep file
  • depmod command
    • searches the content of lib>modules>‘kernel_version’> for each module
    • builds the modules.dep file by aggregating all instances of symbols being exported and used.
    • A module can export a ‘symbol’ so it can provide services for other modules
  • Module directory:
    • usr>lib> contains shared libraries and binaries for general programs and software packages
    • usr>lib>modules> contains the modules of different kernel versions installed
    • etc>modprobe.conf: settings that apply persistenly to all the modules loaded on the system.
      • It is used to configure modules and their dependencies and to specify module aliases.
      • An alias is an alternative name to use for a module.
      • deprecated in newer linux distro, modprobe.d is used
    • etc>modprobe.d>
      • Other than creating aliases, these files can tell modprobe to run additional modules with specific options when your chosen module is loaded into the kernel.
      • This enables the chosen module to leverage another module’s functionality without actually loading it into the kernel.
    • Files ending in .conf in the etc>modprobe.d> directory can use one of several commands (only inside the file).
      • alias <alternative_name> <mod_name>: Specify alias for module
      • blacklist <mod_name>: ignore internal aliases, which occur when modules define their own alias
      • install <mod_name> <command>: Run the specified command without inserting the module into the kernel
Kernel updates and parameters:
  • Can also change kernel params while running
  • proc>sys> lists the configurable params
    • crypto
    • debug
    • dev
    • fs
    • kernel
    • net
    • user
    • vm: virt mem
  • sysctl command
Kernel panic
  • kernel panic can happen for many reasons and at any point during operation, but it is usually experienced during the boot process. Common causes include the following:
    • The kernel itself is corrupted or otherwise improperly configured.
    • The systemd program is not executed during boot, leaving the system unusable.
    • The kernel cannot find or otherwise cannot mount the main root file system.
    • Malfunctioning or incompatible hardware is loaded into the kernel on boot.
Kernel message and log
  • dmesg command
    • Display MESsaGe or Driver MESsaGe
    • print any message that have been sent to the kernel’s message buffer during and after system boot
  • Can also see message buffer from var>log>dmesg
Manage application crash:
  • Address application issues by considering some of the following questions:
    • Did the application compile correctly?
    • Did you modify any parameters before compiling?
    • Did you configure any nonstandard settings during or after the installation?
    • Is the application fully up-to-date and patched?
    • Have you examined the application’s log file (if it exists)?
  • Use journalctl command to view log from sources more than just rsyslog
    • sudo journalctl -u ssh to view journal entries for ssh

9. Managing services:

Manage system services:

Linux Service vs Daemon:
Init System:
  • parent of all processes in linux with PID 1
  • a configuration file and initiates processes listed in it
  • Init daemons:
    • SysVinit (older)
      • Has runlevels
      • Runlevel Purpose
        • 0 Halt or shut down the system.
        • 1 Start single-user mode.
        • 2 Start multi-user mode at CLI without networking.
        • 3 Start multi-user mode at CLI with networking.
        • 4 Unused
        • 5 Start multi-user mode with GUI and networking.
        • 6 Restart the system
      • The etc>inittab file stores details of various processes related to system initialization on a SysVinit system. It also stores details of the runlevels in use.
        • The init daemon reads from this file to determine what runlevel to boot into, what daemons to start, and what to do if the runlevel changes.
        • each line has format id:rstate:action:process
      • managed with service command and chkconfig command
    • systemd
systemctl command
systemd unit file

Configure common system services:

Configure rsyslog
Display and forward logs:
  • OS logs are at var>log
  • Remote log forwarding from linux machine A to machine B:
    1. In machine B, allow UDP listening, uncomment:
      • # provides UDP syslog reception
      • #module(load="imudp")
      • #input(type="imudp" port="514")
    2. In machine B, set template for incoming logs (%HOSTNAME% variable means the logs will be organized based on the hostname of the sending server`)
      • $template DynamicFile,"/var/log/%HOSTNAME%/forwarded-logs.log" *.*-?DynamicFile
    3. In machine A, allow port 514/udp
    4. restart rsyslogd
    5. In machine A, test with logger TEST and check in machine B’s var/log
Configure networktime
Configure Scheduling:
Configure webserver:
Configure NFS
  • systemctl enable/start nfs-server
  • To display the available directories on the remote file server, use the showmount -e {server} command
  • mount the remote /media/projects directory to the local /media/share directory, type: mount -t nfs4 192.168.2.10:/media/projects /media/share
  • enable firewall
Configure printing

Configure localization settings:

Manipulate system settings:
  • localization is the process of adapting system components for use within a language or culture other than the one that the system was originally designed for
  • date command prints date based on etc>localtime
    • there are different date format, example: %V is week
Configure localization:
Troubleshoot timezone configurations
  • The usr>share>zoneinfo> directory is a container for all of the regional time zones that you can configure the system to use.
    • Subdirectories in this container usually organize languages by region; for example, the Africa subdirectory includes time-zone files for specific countries or cities within the continent.
  • On debian, timezone is stored at etc>timezone. On red-hat, it is in user>share>zoneinfo

10. Network settings

Network

  • linux kernel controls 4 layers in OSI model
    • application
    • Transport
    • Internet
    • Network interface

Network settings:

Network interface:
Network manager
Network config files:
Use ethtool
Dynamic IP addressing components:
Config Name resolution
route command

Configure remote admin access

Config SSH
Configure key-based authentication:
  • The standard auth in SSH is password challeng (user name and password)
    • can be guessed, found, intercepted
    • automated process will stop to ask for password
  • Key-based auth generated public-private key pair
    • private key remains on server
    • public key is stored on the remote system
  • ssh-keygen command to create key pair, add to ssh-agent by default
  • ssh-add command to manually add an existing key to agent
  • SSH tunneling: wrap SSH around another TCP-based network connection
    • SSH port fowarding: tunnel an application thru SSH to secure the transmission
      • Local fowarding: client listens for connection on a port then tunnel any active connection to a remote server using SSH
        • example: VNC server traffic over port 5900 will be forwarded to port 22
      • Remote forwarding: SSH server forwards inbound client traffic to another system on a different port.
      • Dynamic Port Forwarding: Uses the SSH connection as a SOCKS proxy to forward traffic dynamically. A range of ports is used rather than a single port, as with standard forwarding
Other Cli remote-access tools:
Data transfer tools
  • scp command purely for transferring files, sftp can transfer files and manage files and directories.
  • sftp command can list, create, and remove directories on the remote system. The sftp command also supports resuming file transfers, whereas scp does not
  • rsync command copy differences between files
    • but doesnt provide encryption
Remote GUI tools:

Troubleshoot network

Identify network config issues:
  1. display current config with ip addr, verify address and subnet mask
  2. route
  3. ping, traceroute, tracepath
Test remote systems:
  • nmap command to reports connectivity, listening ports, firewall status, operating system identification and other values
  • openssl command identify connection to webservers that use SSL
Identify network interface errors:
  • iftop command displays bandwidth usage information for the system, identify a NIC or protocol is consuming the most bandwidth
  • iperf command test the maximum throughput an interface will support
    • must be installed on both endpoint
  • tracepath command report network path between the source and destination computers, including any routers the connection uses
    • simplier than traceroute command
  • traceroute command output each hop along the path the packets take
Troubleshoot high network latency:
Clear ARP cache

11. Configure network security

Configure Firewall:

With iptables and nftables:
With firewalld:
With Uncomplicated Firewall
Troubleshoot common firewall issues:
  • Check the firewall rules to ensure that they are not blocking a port that your system needs.
  • Check whether the default deny-all rule for incoming connections is processed before permit rules.
  • Consider whether you have confused inbound versus outbound traffic.
  • Ensure rules exist that match the traffic type.
  • Check whether you’ve blocked or allowed the incorrect transport layer protocols (TCP, UDP, or both).
  • Ensure application-layer firewalls are properly configured to manage packets whose contents match a specific application-layer protocol (e.g., HTTP, FTP, SSH).
  • Be sure you have reloaded the firewall after configuration changes.

Monitor network traffic:

Use basic network-monitoring tools:
Test connectivity with path:
Test connectivity with sockets:
  • netstat command
    • network statistics
    • gather infor about TCP connections to the system
    • also user of connection, listing ports, NIC,…
    • optionss:
      • -v: verbose
      • -i: interface
      • -c: continuous
      • -l: show ports
  • ss command
    • socket state
    • similar to netstat command but simpler
    • Expression:
      • {dst|src} [=] HOST: Test if the destination or source matches HOST. See HOST SYNTAX for details.
    • Options:
      • -l: show listing sockets
      • -a: show all listen/non-listening ports
      • -t: display TCP only
      • -u: display UDP only
  • lsof command with -i
  • netcat command
Analyze network traffic:
Map the network:
Troubleshoot connectivity issues:
  1. ip addr —Does the local host have the correct IP configuration?
  2. ping <destination> and back
  3. traceroute, tracepath —Is traffic moving along the expected network path? Is it blocked at a specific router or firewall device?
  4. ss, netstat, lsof -i —Display current connections and listening ports.
  5. firewall-cmd --list-services —View what traffic may be filtered by the local firewall.
  6. Wireshark or tcpdump —Identify what network traffic is moving in a given network subnet.
  7. Nmap —Scan hosts or networks for configurations.

12. Manage linux security

Harden a linux system

Hardening servers:
  • To mitigate threats
  • Principle of least privilege
  • Practices:
    • Security
    • UEFI boot
    • Firewall
    • SSH
    • Disable/remove unused/insecure services
    • Secure service accounts
    • Stronger pw
    • Tune kernel parameters
    • Automate updates
Security Goals:
Understand encryption:
  • Cryptography can be used for data in transit and also when at rest
  • Goal: confidentiality, integrity, and non-repudiation
    • Non-repudiation ensures that a sending party cannot deny the origin of a transaction. The sender encrypted the data in a manner that only the sender is capable of, proving the source.

Manage certificates:

Digital Certificate
  • SSL
  • often used as auth as well
Manage PKI certs:
Integrity check

Authenication

Methods:
PAM

Configure SELinux or AppArmor:

13. Implement scripts

14

15

16