Module 1: Performing Basic System Management Tasks

Lesson 1: Understanding RHEL

Lesson 2: Installing RHEL

Module 2: Basic Tasks

Introduction to working with linux and the command line.

Lesson 3: Using the Command Line

Learning objectives:

  • Working with Bash shell
  • GNOME graphical environment
  • Virtual terminals
  • Basic linux commands
  • Cockpit

3.1 Working with the Bash Shell

  • Shell is how a user interfaces with the operating system - bash is the default
  • Can also have a graphical shell - from within you can run bash
  • Bash has many features that making working with it easier
    • Tab completion
    • History
    • Variables to store settings
    • Scripts to automate tasks
  • User must authenticate before gaining access to a shell

3.2 Exploring the GNOME Graphical Environment

  • Button in upper right opens frequently used and search, plus show all apps
  • Mr. Beep Boop says to go to power settings and disable screensaver because this is a VM and he says typing a password is annoying.
  • Terminal window, we have our shell prompt - student@rhcsa1. You can type commands here! wow!
  • Best use case for graphical env is to open multiple terminals simultaneously

3.3 Using Virtual Terminals

  • Terminal is the environment that runs a shell - in graphical environment you can have multiple on one screen
  • In the text-based environment you need virtual terminals using Ctrl[-Alt]-Fn key sequences
  • who or w will show you who is active on which terminals
  • chvt can change between virtual terminals

3.4 Starting with Linux Commands

  • Commands are used with arguments or options which can further specify the use of the command or modify behavior
  • You can usually use --help to get a basic overview of the command and its usage
  • If the help output is too long, we can pipe the output to lessls --help | less which is a pager. Then you can use arrow keys or press space to page
  • Linux commands are case sensitive

3.5 Using Cockpit

  • Cockpit is a web based interface for working with our rhel system - runs on port 9090.
  • Not recommended for most of rhcsa, but become familiar with it.
  • Overview of things like storage, resource usage, etc.

Lab

  • Log into the graphical interface using default account
  • Open a terminal and type who to find out which users are active
  • Use the command who --help to get a usage overview

Lesson 4: Using Essential Tools

Learning objectives

  • Using man
  • Finding the right man page
  • Using Lightspeed to get help
  • Using an editor
  • Understanding and exploring vim

4.1 Using Man

  • No Internet access during RHCSA Exam - so man is your best bet
  • man pages often have examples
  • You can search for text using a /
  • Fixed sections
    • 1 - executable programs or shell commands
    • 5 - file formats and conventions
    • 8 - system administration commands
    • learn more with man man

4.2 Finding the right man page

  • All man pages are indexed in the mandb
  • man -k to search the mandb based on a keyword
  • Use grep to filter the results

4.3 Using Lightspeed to Get Help

  • Useless on RHCSA exam because we have no Internet access
  • Integrated AI in RHEL 10
  • Must have a registered system
  • dnf install command-line-assistant
  • AI Slop

4.4 Using an Editor

  • Most linux config is done by editing text files
  • Common options on Linux include nano and vim

4.5 Understanding vim

  • vi vim
  • vim has different modes - command is the default
  • Insert mode to enter text

4.6 Exploring vim

  • Honestly this is boring to me because I use vim all day every day. My dude covered
    • esc to get to command mode
    • i to enter insert mode, or o or a to open newline/append
    • :wq write and quit
    • dd to delete the current line

Lab

  • Locate the man page that shows how to set a password
  • Use the man page for useradd to create a user with name anna
  • Set the password for user anna to password
  • Use vim to create a file with the name users, make sure it contains alex, alexander, linda, and belinda on separate lines

Lesson 5: Understanding the Bash Shell

Learning Objectives

  • I/O Redirection and pipine
  • History
  • Using keyboard shortcuts
  • Introduction shell expansion
  • Escaping special characters
  • Variables
  • Aliases
  • Tuning the environment using startup files

5.1 Using I/O Redirection and Piping

  • STDIN, STDERR, STDOUT to work with command input and output
    • > is for redirecting output to a file
    • >> will append instead of replacing a file
    • 2> will send STDERR to a file or /dev/null 2> /dev/null
    • < Redirecting to STDIN
  • When piping, STDOUT of first command is used as STDIN for second command
    • ps auxf | grep -i ssh

5.2 Exploring History

  • Recently used commands can be viewed by typing history
  • Also kept in ~/.bash_history
  • HISTSIZE and HISTFILESIZE vars used to define number of entries kept
  • Up arrow key to scroll backwards through history
  • CTRL-R reverse search to find a pattern in history
  • !nn repeats based on history from its number
  • !a repeats the last command that starts with the letter a
  • history -w syncs from memory to history file
  • history -c clears the history
  • history -d nn removes line nn from current history

5.3 Using Keyboard Shortcuts

  • CTRL-c quits the current interactive process
  • CTRL-d sends an end-of-file character to current interactive process
  • CTRL-a moves to beginning of line
  • CTRL-e moves to the end of the line
  • CTRL-l clear screen
  • CTRL-u remove current line

5.4 Introducing Shell Expansion

  • Globbing, such as ls *
  • or ls a?*
  • Brace expansion - touch file{1..9}
  • Tilde expansion - cd ~
  • Command sub: ls -l $(which ls)
  • Var sub: echo $PATH

5.5 Escaping Special Characters

  • In expansion, special characters are interpreted by the shell, such as $ - but sometimes you need to type that.
  • Double quotes suppress globbing and shell expansion
  • Single quotes take away special meaning of chars
  • \ escapes just the next character

5.6 Applying Variables

  • In scripting, separate site specific data from generic code
  • env will show current values in environment
  • [export] key=value
    • export means valid in this shell and sub shells
  • To make vars persistent, put them in bash startup files

5.7 Using alias

  • Use to define custom commands - type alias to see all that are already set
  • Define your own with alias key=value

5.8 Tuning the Bash Environment

  • /etc/profile is the generic bash startup file for a login shell
  • /etc/bashrc processed while opening any shell
  • ~/.bash_profile for user specific settings
  • ~/.bashrc is user specific /etc/bashrc
  • To source a file is to include it in your current shell - immediately

Lab

  • Managing Bash configuration
    • Set a var color to the value red and ensure this setting is available every time your current user account logs in (in .bash_profile export color=‘red’)
    • Also create an alias that runs the command ls -ltr while executing the dir command (in ~/.bashrc alias dir=‘ls -ltr’)
    • Ensure that the Bash history file can grow to a maximum size of 2500 entries (edit .bash_profile, export HISTFILESIZE=2500)

Module 3: Performing Basic System Management Tasks

Lesson 6: Using Essential File Management Tools

6.1 Exploring the Filesystem Hierarchy

  • Directories are standardized per FHS, maintained by the Linux Foundation man hier
  • Starting point of filesystem is the root directory
  • Different devices may be integrated using mounts
  • Distributions can deviate from FHS
  • /usr/bin, /usr/sbin “program files”
  • /etc for configuration
  • /var for dynamically created files, including logs
  • /boot includes kernel and other requirements for starting system
  • /dev device interface files

6.2 Using Essential File Management Commands

  • ls
  • mkdir
  • cp
  • mv
  • rmdir
  • rm

6.3 Finding Files

  • which looks for binaries in $PATH
  • locate uses a database, but requires updatedb to update said database
  • find is the most flexible - find files based on many criteria
    • -type f (files), -type d (dirs)
    • -size +100M
    • -exec examples
    • find /etc/ -name '*' -type f | xargs grep "127.0.0.1"

6.4 Mounting Filesystems

  • To access a device, it must be connected to a directory - known as mounting
  • Different types of data may live on different devices for multiple reasons
    • security
    • management
    • mount options
  • mount /dev/sdb1 /mnt example of the mount command
  • mount to show all mount points, findmnt gives more details
  • lsblk to give an overview of real devices and their mountpoints
  • Pointer to a file in a different location - kind of like a shortcut. There are hard and symbolic links (soft links)
  • inode contains all the properties of a file - every file has one - inode references block
    • multiple names per inode is what a hard link is - must exist on the same device
    • Cannot hard link a directory
  • Gain some flexibility with a symlink - instead of pointing to an inode, it points to a name
    • When creating a symlink, use full path so that if you copy it it does not become invalid

6.6 Archiving Files

  • tar is the tape archiver (old!)
  • By default, tar does not compress data
    • But we can add it with -z, -j, -J

6.7 Working with Compression

  • Wide range of compression solutions for Linux - used independently or as a part of the tar command
  • gzip(-z)
  • bzip2(-j)
  • xz(-J)

Lab

  • Use tar to create a compressed archive of all files in /etc and /opt in your homedir
  • Create a symlink to the archive in /tmp
  • Remove archive - now what?

Lesson 7: Managing Text Files

7.1 Exploring Common Text Tools

  • more was the original file pager - less came along to bring some more advanced features and is the commonly used pager today
  • Use head or tail to see only a given number of lines in a text file (default, 10 lines)
    • tail -f to follow and show new output as it appears
  • cat dumps the file contents to screen - can show all non printable characters using -A.
  • tac is reverse of cat - why? idk.
  • cut can filter output
  • sort will sort output of previous command
  • tr for translate - lowercase, uppercase, etc.

7.2 Using grep

  • Excellent to find text in files or output - ps auxf | grep ssh
  • okay it’s grep

7.3 Applying Regular Expressions

  • pattern used by grep and other tools
  • Always put regex between single quotes because of shell interpretation issues
  • Globbing is not the same as regex
  • man 7 regex
  • grep -E for extended regex

7.4 Awk

  • Text processing utility that can perform actions on selectors - a few use cases today, a bit antiquated.

7.5 Sed

  • sed is the stream editor - from 70s!
  • Used to search and transform text

Lab

  • Use head and tail to display the fifth line of the file /etc/passwd (head -5 /etc/passwd | tail -1)
  • Use sed to display the fifth line of the file /etc/passwd (sed -n 5p /etc/passwd)
  • Use awk in a pipe to filter the last column of the results of ps aux (ps aux | awk ‘{print $NF}’
  • Use grep to show all lines from all files in /etc that have lines that contain the text ‘root’ (grep -r “root” /etc)
  • Use grep to show all lines from all files in /etc that have exactly 3 characters (grep -r ($…^) /etc)
  • Use grep to find all files that contain the string alex, but make sure alexander is not inclued in the result (grep ‘alex\b’ users)

Lesson 8: Using root Privileges

8.1 Understanding the root user

  • user account with UID 0 exists to perform admin tasks - called root by default
  • root user operates in kernel space so it has unlimited access to all parts of the system
  • While installing RHEL 10, root user can be activated or not - for security we often do not set a password for this user and use another administrative user
  • To activate the root user we simply have to set a password
  • Additional measures are possible to restrict root user access to a system
    • Avoid working as root, use an administrative user instead with sudo privileges
    • Restrict root login for ssh

8.2 Switching User with su

  • Two ways to work as the root user, one is more modern
    • su command is used to switch user account from a shell - specifically su - which will load environment of the target user (best practice)
    • Using su - root is bad practice
    • Use sudo -i instead so you don’t need the root password

8.3 Performing Administrator Tasks with sudo

  • Behind sudo is sophisticated configuration to limite what users can do with sudo - maintained in /etc/sudoers
  • Use visudo while editing sudoers file to prevent errors from breaking system
  • Basic use of sudo is sudo <command> - only works if allowed in /etc/sudoers
  • To open a root shell, sudo -i
  • While using shell metacharacters, sudo needs a special approach

8.4 Managing sudo configuration

  • configuration is managed through /etc/sudoers - do not edit directly, only use visudo
    • Can also use drop in files in /etc/sudoers.d to avoid files being ovewritten during package updates
  • Users that are a member of the group wheel get full sudo access by default
    • Thanks to %wheel ALL=(ALL) ALL
    • To add a user to the wheel group, usermod -a -G wheel <user>
    • Do not enable %wheel ALL=(ALL) NOPASSWD: ALL as this provides full root access without any password. DANGEROUS
  • Add access for specific tasks lisa ALL=/sbin/useradd, /usr/bin/passwd
  • You can add specific args to further limit access %users ALL=/bin/mount /dev/sdb, /bin/umount /dev/sdb

8.5 Using ssh to login remotely

  • By default, all RHEL servers are running a secure shell server (sshd)
    • Verify using systemctl status sshd
  • Firewall rule is also enabled by default for port 22/tcp
  • Root access is often denied or restricted to pubkey authentication only
  • scp is part of ssh and is used to copy files securely

Lab

  • Use useradd linda to create a user linda
  • Create sudo config to allow linda to perform useradd, usermod, userdel and change passwords, but not the root password
  • Ensure that the user only needs to enter a password for sudo every 60 minutes

Lesson 9: Managing Users and Groups

Lesson 10: Securing Files with Permissions

Lesson 11: Managing Network Configuration