0% found this document useful (0 votes)
2K views7 pages

RHEL 9 Admin Guide for RHCSA 9 Exam

The document discusses various Linux system administration tasks including managing repositories, users, file permissions, logical volume management, performance tuning, job scheduling, and basic shell scripting. Some key points: - It describes how to add/disable Yum repositories, create users and groups, set file permissions using octal and symbolic notations, and manage access control lists. - For LVM, it explains how to create physical volumes, volume groups, logical volumes, and file systems on top of logical volumes. - It also covers configuring scheduled jobs using cron, anacron, and systemd timers, as well as tuning the system using tuned profiles. - Finally, it provides examples of basic shell
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)
2K views7 pages

RHEL 9 Admin Guide for RHCSA 9 Exam

The document discusses various Linux system administration tasks including managing repositories, users, file permissions, logical volume management, performance tuning, job scheduling, and basic shell scripting. Some key points: - It describes how to add/disable Yum repositories, create users and groups, set file permissions using octal and symbolic notations, and manage access control lists. - For LVM, it explains how to create physical volumes, volume groups, logical volumes, and file systems on top of logical volumes. - It also covers configuring scheduled jobs using cron, anacron, and systemd timers, as well as tuning the system using tuned profiles. - Finally, it provides examples of basic shell
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
  • File Access and Logical Volume Management
  • Repositories and Users
  • System Management

REPOSITORIES

File: /etc/[Link].d/
See enabled repositories
#dnf repolist enabled
Disable all repositories
#dnf config-manager –disable <repoID>
Create Yum repositories with the dnf config-manager command.
#dnf config-manager –add-repo=”[Link]
Check repo was added: #dnf repolist enabled

USERS
File: /etc/passwd | /etc/shadow | /etc/group | /etc/gshadow | /etc/[Link]
Create users:
#useradd bob
The following configuration variables in /etc/[Link] change the behavior of this tool:
CREATE_HOME; PASS_MAX_DAYS (number) maximum number of days a password may be used.
To change the expiration of a password after X days, edit:
#vi /etc/shadow
To change home dicretory of a users edit:
#vi /etc/passwd
Create groups:
#vi groupadd trainers
#vi usermod -aG trainers bob

FILE ACCESS
r=4; w=2; x=1; rwx=7; rx=5 | Default for d = 0777 (drwxrwxrwx) | Default for f = 0666 (-rw-rw-rw-)
umask = 0002 clears the write bit for other users | 0077 clears all the group and other permissions of newly created files

Special permission Effect on files Effect on directories

u+s (suid) File executes as the user that owns No effect


the file, not the user that ran the file.
g+s (sgid) File executes as the group that owns Files newly created in the directory have their group owner set to
the file. match the group owner of the directory.
o+t (sticky) No effect. Users with write access to the directory can only remove files that
they own; they cannot remove or force saves to files owned by
other users.
To create a shared folder where regular users can read-write-delete their files but cannot delete others files and a HEAD user can
delete any file:
#mkdir /groups/trainers
#chown bill:trainers /groups/trainers
#chmod g+s /groups/trainers
#chmod o+t /groups/trainers

Add read access only to a group other than the group owner of a folder/File | to verify the file acl was added
#setfacl -m g:consultants:rx /groups/trainers
#getfacl /group/trainers

LOGICAL VOLUMES MANAGEMENT LVM


File: /etc/fstab
Check device of physical HD
#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sr0 11:0 1 1024M 0 rom
nvme0n1 259:0 0 20G 0 disk
├─nvme0n1p1 259:1 0 1G 0 part /boot
└─nvme0n1p2 259:2 0 19G 0 part
├─rhel-root 253:0 0 17G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
nvme0n2 259:3 0 5G 0 disk

Check where is mounted


#fdisk -l

Create partition and label it as Linux LVM


#fdisk /dev/nvme0n2
:n | :p | :1 | :default | :default | :type | :8e (for Linux LVM type) | :w

Create physical volume and verify


#pvcreate /dev/nvme0n2p1  note p1 as partition 1
#pvdisplay

Create Volume Group and verify


#vgcreate <vgfiles> /dev/nvme0n2p1
#vgdisplay

Create Logical Volume named lvfiles in vgfiles group, allocate 100% of free space
#lvcreate -n <lvfiles> -l 100%FREE <vgfiles>

Create File System on new logical volume of type ext4


#mkfs.ext4 /dev/vgfiles/lvfiles

Mount volume on folder /files and make mount persistent. Reboot to verify is persistent
#mkdir /files
#mount /dev/vgfiles/lvfiles /files
#df -hT (to get the files system and type to add to /etc/fstab)
#vi /etc/fstab add line: /dev/mapper/vgfiles-lvfiles /files ext4 defaults 00

PERFORMANCE TUNING
Check if tuned is installed, if it’s running, make it enabled and change profile to bets throughput
#rpm -qa | grep tunned
#systemctl status tunned
#systemctl enabled tuned
#systemctl start tuned
#tuned-adm list
#tuned-adm profile network-throughput
#tuned-adm active

JOB SCHEDULING
Files: /etc/crontab | files in folder /etc/cron.d/ | /etc/[Link]/| /etc/[Link]/ | /etc/
[Link]/ | /etc/[Link]/
One time for user at, atq #echo "date >> /home/student/[Link]" | at now +3min
Periodic tasks for Users #crontab -e ADD to file */2 * * * Mon-Fri /usr/bin/date >> ~/my_first_cron_job.txt

For recurring system Jobs:


Always place crontab file on /etc/crond/ folder to avoid overwriting

The /etc/anacrontab file ensures that scheduled jobs always run and are not skipped accidentally because the system
was turned off or hibernated.
System timers located: /usr/lib/systemd/system/[Link]
To modify copy timers to /etc/systemd/system/[Link]
To reload timer #systemctl daemon-reload
To enable timer #systemctl enable --now [Link]
Timer that triggers temporary file clean up [Link]

Diagram

Create a scheduled job to run at the top of every hour and send a message “hello” to the system-logging mechanism
#crontab -e
ADD LINE TO FILE AND SAVE: 59 * * * * logger -p [Link] "hello"

MAKE system journal PERSISTENT


#mkdir /var/log/journal
#vim /etc/system/[Link]
EDIT LINE: Storage=persistent
#systemctl restart systemd-journald
#reboot

MAKE THE INSTALL DISK THE DEFAULT REPO


File: /etc/[Link].d/[Link] | /mnt/disk/[Link] |
Mount the media disc
#mount /dev/sr0 /mnt/disk
Copy repo file from media to /etc/[Link].d/[Link]
#cp /mnt/disk/[Link] /etc/[Link].d/[Link]
Edit [Link] and make it look like:
root@server4 ~]# cat /etc/[Link].d/[Link]
[InstallMedia]
name=Red Hat Enterprise Linux 9.1.0
mediaid=None
metadata_expire=-1
gpgcheck=1
cost=500
enabled = 1
baseurl = [Link]
gpgkey = [Link]
[InstallMedia-AppStream]
name=Red Hat Enterprise Linux 9.1.0 Apps
mediaid=None
metadata_expire=-1
gpgcheck=1
cost=500
enabled = 1
baseurl = [Link]
gpgkey = [Link]

Clean and check repo works


#dnf clean all
#dnf update

EDIT SYSTEM CLEAN UP /tmp FILES


Files: /usr/lib/tmpfiles.d/*.conf | /run/tmpfiles.d/*.conf |/etc/tmpfiles.d/*.conf
Check current timer of [Link]
#systemctl cat [Link]

Change configuration file to run every hour


#vi /usr/lib/systemd/system/[Link]
Change line : [Timer] -> OnUnitActiveSec=1h

Ensure system loads new configuration


#systemctl daemon-reload

Activate the new timer and verify if change took effect


#systemctl enable --now [Link]
#systemctl cat [Link]

Using stratis add a 3G disk to volume named myvol and ensure it is mounted persistently and automatically when
booting.
Ensure stratis is installed
#rpm -qa | grep stratis
Install stratis
#dnf install stratis
#dnf install stratis-cli

Enabled ans start stratisd service


#systemctl enable stratisd
#systemctl start stratisd

Check the HD is added, create stratis pool and extend the pool
#lsblk
#stratis pool create <myvol> </dev/nvme0n2>
#stratis pool add-data <myvol> </dev/nvm0n3>
#stratis pool list

Create new file system and verify


#stratis filesystem create <pool-name> <file-system-name>
#stratis filesystem list

Mount volume, create snapshot and make it persistent


#mkdir /myvol
#mount </dev/stratis/myvol/myvolfs > /myvol
#stratis filesystem snapshot <poolname> <file system name> <snapshot name>
#echo "UUID=<from filesystem list> /myvol xfs defaults,[Link]=[Link] 0 0" >> /etc/fstab
BASIC SHELL SCRIPTING
Write a file that prompts for input if not input received, the checks if input is file or folder and prints long list properties
of each:
#!/bin/bash
ARG=$1
while [ ${#ARG} -eq 0 ] #while length of ARG is 0
do
echo "PLEASE ENTER ARGUMENT"
read ARG
done

if [ -e "$ARG" ] #if ARG exists


then
if [ -d "$ARG" ] #if ARG is a folder
then
echo "IT IS A FOLDER"
ls -ld "$ARG"
else
echo "IT IS A FILE"
ls -ltr "$ARG"
fi
else
echo "$ARG doesn't exist"
exit 6
fi

Find all files that have the SUID permission set and write results to file in home folder.
#find / -type f -perm -u+s -fprint /home/student/[Link]

Create user lisa and change the max password days to 30, also ensure she changes password at first login
#useradd lisa -K PASS_MAX_DAYS=30 OR
#useradd lisa THEN #chage -M 30 dbuser1
#chage -d 0 lisa

Allow lisa to change anyone’s password except root | sudoers line syntax User Host = (Runas) Command
Command dnf is the latest version of YUM dnf links to dnf-3

Channel 2 is the error channel


Channel 0 is the input channel
#!/usr/bin/bash
#
USR='student'
OUT='/home/student/output'
#
for SRV in servera serverb
do
ssh ${USR}@${SRV} "hostname -f" > ${OUT}-${SRV}
echo "#####" >> ${OUT}-${SRV}
ssh ${USR}@${SRV} "lscpu | grep '^CPU'" >> ${OUT}-${SRV}
echo "#####" >> ${OUT}-${SRV}
ssh ${USR}@${SRV} "grep -v '^$' /etc/selinux/config|grep -v '^#'" >> ${OUT}-${SRV}
echo "#####" >> ${OUT}-${SRV}
ssh ${USR}@${SRV} "sudo grep 'Failed password' /var/log/secure" >> ${OUT}-${SRV}
echo "#####" >> ${OUT}-${SRV}
done
Command r on top interface changes process priority. The lowest the value the more processor time the process
gets.

Find what package provides a program


dnf provides <seinfo>

Restore the file TYPE to the correct context


restorecon <filename-or folder>

firewall-cmd --list-all-zones
firewall-cmd –add-service=http
systemctl start httpd

SELinux commands
getenforce = See SELinux status
getenforce 0 = disable SELinux enforcement
getenforce 1 = enable SELinux enforcement
ls lZd /<directory> = shows file properties including SELinux file types

less /etc/selinux/targeted/contexts/files/file_contexts = shows what types are SELinux files


semanage fcontext -a -t httpd_sys_content_t ‘/virtual(/.*)?’ = permanently edits the context type of /virtual
folder and content
man semanage-fcontext = see examples to see types

Reset Root Password


Reboot OS
Interrupt countdown, select the Rescue kernel boot-loader and push “e” to edit it
Use the cursor keys to navigate to the line that starts with linux, Press end to go to end of the line
Add [Link] to the end of the line and press ctrl+x to reboot
After reboot press enter
#mount -o remount,rw /sysroot
#chroot /sysroot
#passwd root to change root password
Ensure SELinux relabels the system after reboot by issuing the command
#touch /.autorelabel
Type exit twice to reboot

Repair File System Issues when booting


Reboot OS
Interrupt countdown, select the Default boot-loader and push “e” to edit it
Use the cursor keys to navigate to the line that starts with linux, Press end to go to end of the line
Add [Link]=[Link] to the end of the line and press ctrl+x to reboot
The system reboots and asks for root password, enter root password
Mount devices mount, and check that the root folder / is mounted as rw, if not, remount it
#mount -o remount,rw /
#mount -a
Check if error ocurrs, if so, edit /etc/fstab and delete the device with issues
#vim /etc/fstab
Reload systemctl and mount all drives
#systemctl daemon-reload
#mount -a
#reboot now

Instructor email
Barbara Stamatakis
bstamata@[Link]
virtualtraining@[Link]

Common questions

Powered by AI

The /etc/anacrontab file ensures scheduled jobs always run by keeping track of jobs that need to be executed after the system was off, thus preventing them from being skipped. This is especially useful for systems that are not always powered on, as it enables jobs to catch up as soon as the system is back up.

First, check if 'tuned' is installed and running. Use 'rpm -qa | grep tuned' to verify installation and 'systemctl status tuned' to check its status. Start and enable it with 'systemctl start tuned' and 'systemctl enable tuned'. Use 'tuned-adm profile network-throughput' to set the system for optimized network performance, and verify with 'tuned-adm active'.

First, mount the installation disc to a directory, such as '/mnt/disk'. Then, copy the repository file from the media to '/etc/yum.repos.d/redhat.repo'. Edit the file to set 'enabled=1', adjust the 'baseurl' to point to the mounted path, and ensure 'gpgcheck=1'. This configuration lets it serve as the default repository for software management.

First, create a partition labeled as Linux LVM and use 'pvcreate' to make it a physical volume. Then, use 'vgcreate' to create a volume group with this physical volume. Next, create a logical volume with 'lvcreate' within this group. Format the logical volume with a filesystem, such as ext4, using 'mkfs.ext4'. Mount it to a directory, then add an entry to '/etc/fstab' with the volume's details to ensure it mounts persistently on reboot.

To adjust the system timer for clearing temporary files, edit '/usr/lib/systemd/system/systemd-tmpfiles-clean.timer' and modify the '[Timer]' section to set 'OnUnitActiveSec' to the desired interval, like '1h' for hourly cleaning. Afterward, reload the systemd configuration with 'systemctl daemon-reload', enable and start the timer with 'systemctl enable --now systemd-tmpfiles-clean.timer', and verify changes using 'systemctl cat system-tmpfiles-clean.timer'.

ACLs allow specifying permissions beyond the owner, group, and others model by allowing distinct permissions to multiple users or groups on files and directories. To verify ACL settings, use the 'getfacl' command on the directory, such as 'getfacl /group/trainers', which lists all applied ACL permissions.

SUID (set user ID) allows a file to be executed with the permissions of its owner rather than the user who runs it, but has no effect on directories. SGID (set group ID) on a file makes it execute with group permissions, while on directories, it ensures newly created files have the directory's group ownership. The sticky bit on directories restricts deletion of files to their owners, regardless of other permissions.

In the sudoers file, add an entry with the syntax 'User Host = (Runas) Command' that specifies the user, hosts, and command they can run. Specifically, to allow a user to change others' passwords except for root, ensure the line specifies they can't switch to root using a negation or exclusion clause. For example, 'lisa ALL = (ALL:ALL) ALL, !/usr/bin/passwd root' would allow password changes with the password command for any user except root.

While in rescue mode, after mounting the root filesystem as read/write, use 'chroot' to change into the sysroot and 'passwd root' to change the root password. For SELinux to relabel, create an empty file '/.autorelabel' and exit the chroot environment twice to reboot the system. This initiates SELinux relabeling on reboot.

To make system journal entries persistent, create the directory '/var/log/journal' and edit the '/etc/system/journal.conf' file to set 'Storage=persistent'. Restart the systemd-journald service and reboot to apply the changes.

You might also like