Rhcsa Ex200 Cert Prep 1 Deploy, Configure And Man
- RHCSA is useful for someone with 1 year + of Linux
- Uses Enterprise Linux Version 8.
- Can use CentOs Enterprise Linux 8.
- Rock Linux
- AlmaLinux OS
- Course uses VMs.
- Guest Vms on top of Hypervisor and then Linux Host
- RHCSA Objectives
- Deploying systems
- Configure networking
- Schedule recurring tasks
- Install Linux as virtual guest
- Configure system time services
- Install and update software.
- Update kernel packages
- Modify system bootloader.
- Miscellaneous
- How use redirection.
- Use grep and regular erxpressions to analyse text.
- Archive and compress files.
- Create and edit etxt.
- File Management.
- Operate running systems
- Interrupt boot process to gain access.
- Manage processes
- Read log files and journals
- Access a virtual machine’s console.
- Start and stop virtual machines.
- Red Hat Split its services into
- Red Hat Advanced Server
- Fedora
- Fedora Linux
- Managed by Fedora project.
- Independent community-governed projec .
- Sponsored by Red Hat.
- 35 percent all contributions are from Red Hat employees.
- Red Hat has legal liability.
- Not identical structure to Enterprise Linux
- Fedora is upstream and all bug fixes are placed into Red Hat Enterprise Linux 8.
- Cent Os is a clone, founded in 2004.
- Nearly identical to RHEL.
- Not supported by Red Hat.
- CentOs fixes are also backported to RHEL.
- Cent Os is a clone, founded in 2004.
- Nowadays, CentOs Stream is upstream of RHEL and receives fixes from Fedora.
- December 8th 2020, CentOS support terminated, then became upstream of RHEL (called CentOS Stream).
- CentOS Stream has similar software packages.
- Similar to Enterprise Linux.
- December 8th 2020, CentOS support terminated, then became upstream of RHEL (called CentOS Stream).
- Deploying systems
- Red Hat Developer Subscription for individual is available.
- Rocky Linux
- Created by one of the original founderse of CentOS.
- AlmaLinux
- Created by Cloud Linux Team.
- Rocky Linux
- Enterprise Linux Virtualisation
- Kernel-based Virtual Machine (KVM)
- Overallocation of physical resouces.
- Can provide more resources to VMs, than exist on the physical machine.
- Non-overcommitting virtual storage.
- For example, 100GB Physical Disk with 10, 10GB VMs.
- Usually computers do not use all of their disk space:
- Overcommitting virtual storage.
- For example, 100GB Physical Disk, with 2 out of the 10 VMs using 10GB and the rest using only 2GB.
- Supports up to 240 virtual cpus
- Passes CPU instructions to host CPU.
- CPU instructions run full speed in guest VM.
- A total of 36GB of Disk Space Required.
- We would allocate 50GB of Disk Space.
- If run out of room, we can always add more space.
- More efficient when overcommitting.
- Can overcommit with CPUs, RAM and Disk Space
- More efficient when overcommitting.
- Agent on guest to communicate with hypervisor
- Disk I/O throttling.
- Storage is comprised of Resource Pools.
- Pools comprised of local and non-shared and remote shared disks.
- Network-shared drives are required, if want to migrate VMs from one host to another quickly.
- Pools comprised of local and non-shared and remote shared disks.
- CentOS has Management Tools
- Virtual Machine Manager - GUI
- virsh - CLI
- Manages and monitors KVM and Guest VMs
- Virtual CPU hot add
- Add virtual CPUs while the KVM is running.
- Nested Virtualisation.
- Run a hypervisor inside of a guest VM, to run more VMs on it.
- Virtualisation Management Stack
- The level stack is shown below:
- Virt-Manager + virsh
- libvirt API
- KVM Hypervisor
- Linux Host OS
- Virt-Manager is a GUI Tool
- virsh - CLI Tool
- libvirt API Manages
- Virtual CPUs.
- VM memory.
- Virtual storage.
- Virtual networking
- Management Tools do not need to be on the same physical host that the VMs are running on.
- Virtualised
- Para-virtualisaed
- Paravirtualised Device
- Talk directly to the hypervisor.
- No translation required.
- Paralised device drivers need to be installed in the guest OS.
- Paravirtualised network device - virtio-net
- Paravirtualised block device - virtio-blk
- Paravirtualised controller device - virtio-scsi (hard disk controllers)
- Paravirtualised serial device - virtio-serial
- Paravirtualised graphics card - QXL
- Paravirtualised Device
- Emulated
- Devices present themselves as real devices.
- Makes the guest believe it is actually a real piece of hardware.
- Loads the driver appropriately.
- Emulation layer translates instructions to the real physical device (in this case, an emulated network device to a physical device).
- Emulated are slower than paravirtualised, due to the additional translation step.
- Example devices are:
- Intel i440FX host/PCI bridge
- PS/2 Mouse and Keyboard
- Intel HDA sound device
- Intel e1000 network adapter.
- And more.
- Example devices are:
- Makes the guest believe it is actually a real piece of hardware.
- Devices present themselves as real devices.
- Physically Shared Devices
- Physical device attached to the virtual machine.
- Passed through by the hypervisor.
- For example, a PCI card can be passed directly to a VM.
- Ohter hosts/VMs will not have access to it.
- Makes them run at full speed.
- Not as flexible as other devices such as paravirtualised.
- Makes them run at full speed.
- Ohter hosts/VMs will not have access to it.
- For example, a PCI card can be passed directly to a VM.
- Physical shared devices are:
- USB device
- PCI cards
- SCSI cards
- PCI Express Function passthrough
- A PCI card that has multiple functions, can have each of those separate functions passed through into a VM.
- Passed through by the hypervisor.
- Physical device attached to the virtual machine.
- Shared
- CPU is virtualised with hardware
- Overallocation of physical resouces.
- Quick Emulator (QEMU)
- Kernel-based Virtual Machine (KVM)
- Setting up Virtualisation on CentOS 8
- qemu-kvm
- Provides user-level KVM emulator and facilitates communication between hosts and virtual guest machines.
- libvirt
- Server-side and host-side libraries - interacting with hypervisors and host systems.
- virt-manager
- Graphical tool for administrating virtual machines.
- libvirt-client
- Provides client-side APIs and libraries for accessing libvirt servers.
- Contains virtsh commandline tool to access the tools from the command line.
- Can install a
yumpackage group for the virtualisation.sudo yum group install "Virtualization Client"
sudo yum group list hidden- Can see the list of hidden groups, including the
Virtualization Clientgroup.
- Can see the list of hidden groups, including the
- The
Virtualization Clientgroup pulls in the following packages:gnome-boxesvirt-installvirt-managervirt-viewer- `qemu-img
libvirtlibvirt-pythonlibvirt-client
- Then start the
libvirtddaemon:- `sudo systemctl start libvirtd
sudo systemctl enable libvirtd
- qemu-kvm
- For Virtual Machines
- A minimum of 1.5GB of RAM and 1 CPU core.
- Disk space should be 10+ GB in size.
- macvtap
- Acts as a phyiscal network bridge.
- Allows remote access from another guest.
- enp is Ethernet wired connection.
- wlp is Wireless.
- Bridge works fine.
- Can’t access guest VM via Host, as currently configured.
- Workaround is to create a new network later on, that both the host and guest reside on.
- Some wirelss network adapters don’t support this.
- Workaround is to create a new network later on, that both the host and guest reside on.
- For installation setup, can set the hostname as
- OS(host1).localnet.com
- Kickstart File
- File used to automate installs.
- Instruction file on how to install the OS.
- Created by Red Hat.
- Used by non-RHEL environments.
- Supported by Debian and Ubuntu.
- It does the following:
- Creating partitions.
- Creating users.
- Preparing network settings.
- Installing software.
- Other configs.
- Saved as;
- /root/anaconda-ks.cfg
- In case we want to repeat the installation.
- Saved as;
- A typical kickstart file has the following:
xconfig --startxonboot- Starts the X Window Server
eula --agreed- Automatically agrees to the end user licence agreement.
text- Just performs a text install.
- `network –bootproto=dhcp –device=enp0s3 –onboot=off –ipv6=auto –no-activate
network --bootproto=dhcp --hostname=centos8ks.localnet.com- Network configuration and hostname.
repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream- Sets up appstream repository.
ignoredisk --only-use=vda- Only installs to
/dev/vda
- Only installs to
cdrom- Installs from an optical disk.
firstboot --enable- Runs first boot wizard.
services --disabled="chronyd"- Disables services, in this case
chronyd
- Disables services, in this case
keyboard --vckeymap=us --xlayouts='us'- Set up keyboard map,
lang en_US.UTF-8- Sets up installed language.
rootpw --iscrypted $6$/UKAvAmubwCKS4XN$ae4/1.5/VLxKeLYqS1XHj7n65cW301xea.tCkk.zzQxUVz13r/0/Q.sTze/I4rvaMjaYjUAsm49hVNkxoVYG//- Sets the root password as
password - The password has to be encoded with a SHA512 hash, before being added to the kickstart file.
- Sets the root password as
timezone America/Los_Angeles --isUtc --nontp- Sets the timezone.
user --groups=wheel --name=user1 --password=$6$nAkGQnSxiY7uR4f/$xMgMOM13oTEosIck0NLYuB6qW.mc2JhE9YkbcghP1imkgQDcrHB7YfRRV.RwpxWGx2h4t78knUR7Ni51z4ldP0 --iscrypted --gecos="user1"- Creates a user called
user1and makes it admin by adding it to thewheelgroup.
- Creates a user called
bootloader --location=mbrautopart --type=lvmclearpart --none --initlabel- Sets the bootloader and partition scheme as
lvm - Any existing partitions are also cleared.
- Sets the bootloader and partition scheme as
%packages@^workstation-product-environmentkexec-tools%end- Names of packages and package groups to install.
%anacondapwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notemptypwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyokpwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty%end- These change the default password policies.
- Kickstart Prerequisites
- ISO image or Network share with OS install files.
- Local NFS share
- FTP Server
- HTTP Server
- VM Disk Image
- Kickstart File
- Kickstart Delivery Method
- Getting the Kickstart file to the installer.
- If a Kickstart file is hosted on a webserver:
--extra-args="ks=http://192.168.122.1/ks.cfg"
- If FTP Server:
--extra-args="ks=ftp://192.168.122.1/ks.cfg"
- Inject kickstart file into guest VM’s ramdisk:
--initrd-inject=ks.cfg --extra-args="ks=file:/ks.cfg"- Holds RAM and other essential drivers that the system boots from.
- Stores it in the root filesystem.
- Can pass the kickstart file to the installer, without setting up an FTP or web server.
- Can even install without a network at all.
- ISO image or Network share with OS install files.
- File used to automate installs.
virt-installcommand.- Configures the installation enviornment.
- DVD Disk Image.
- Hard drive Image.
- Kickstart File.
- An example command list:
sudo virt-install--name centOS-ks- Good way to remind yourself installed via kickstart file.
--memory 2048- In older files, this can also be seen as
--ram, which is the same thing.
- In older files, this can also be seen as
- `–disk path=PATH_HERE/centOS-ks.qcow2,format=qcow2,size=10
- 10GB in size.
- qcow2 is CoW format, where we can create snapshots.
- Also allows thin-provision disk images, so hardware can be over-subscribed.
- I.E create disk images larger than physical storage.
- Only some VMs use all of the space.
- Can create disk image ahead of time with:
- `sudo qemu-img create -f qcow2 -o size=10G centos8-ks.img
- This method is more manual, but provides more flexibility with disk options.
- `sudo qemu-img create -f qcow2 -o size=10G centos8-ks.img
- A good way to practice is to modify the virt-install file and practice creating virtual machines to perfect it.
- If run the same command line more than once,
virt-installwill complain.--location=PATH_TO_MEDIA/*.iso- Can make the path shorter, using the
$HOMEvariable.
- Can make the path shorter, using the
--no-graphics- Specifies a non-graphical install.
--initrd-inject=$HOME/PATH_TO_KICKSTART_FILE.cfg- If quotes are around the path name, such as
"PATH_TO_KICKSTART_FILE"this helps with spaces in the directory names. - Inject kickstart file into guest VM’s RAMDISK.
- If quotes are around the path name, such as
- `–extra-args=”ks=file:/centos8-ks.cfg ip=dhcp console=ttyS0, 115200n8”
- Extra arguments that get passed to the Linux kernel during install.
ks=file- Tells the installer to use the file at the above location.
consolesets up a way to see the output.- Configures a
serialconsole, using a/dev/ttyS0device. - The
115200is how many bits per second it transfers, thenis No Parity and8is data bits.
- Configures a
--os-variant=rhel8.1- Allows installation time optimisations by KVM.
osinfo-query oscommand gets a list of KVM OS variants.- Can see these variants in:
/usr/share/osinfo/osasXMLfiles.
- If run the same command line more than once,
- To add graphics,
- Click
Add Hardware- Then
Video–>QXL–>Finish - Then click
Graphics–>Spice Server–>Finish- In later versions of distros, this is done foe you and no need here.
- Then
- Click
- If KB/Mouse don’t work:
Add HardwareVirt-manager, this is already done for you.Input–>Generic Keyboard & Mouse
sudo virsh list- Lists the running VMs.
-
`sudo virsh help less - Shows the commands.
- To only see sub-commands that are part of a domain for example.
sudo virsh help domain
- Important Sections
Domain Monitoring- `Host and Hypervisor
- Gets information on the host and KVM hypervisor as well.
Networking- Can also implment network filters as well.
Node Device- Passthrough physical devices to VMs with these commands.
SnapshotStorage Pool- Can create storage pools and the volumes that go inside them.
sudo virsh- Access
virshwithout having to type insudoevery time. - Commands can be used in interactive or non-interactive modes.
list --all- Shows all VMs whether they are running or not.
- To get info on a specific VM, you can use something like:
- `dominfo centos-ks
- Access
- Onec run
sudo virsh- Enables interactive mode.
list --all- Shows all VMs.
- `shutdown centos8-ks
- Shuts down a VM
- `start centos8-ks
- Starts a VM.
console centos8-ks- Attach to the console.
- If you open a VM that already has an active Virtual Manager console session, you will be given an error.
- To close the sesion use,
ctrl + ]
- To automatically start a VM.
autostart centos8-ks
- To clone a VM.
sudo virt-clone --auto-clone --original rhhost1 --name rhhost2--auto-clone- Takes care of a lot of the other arguments we can add.
- VM Checklist
- Virtual Graphics Card
- tty0 and ttyS0 Console Added.
- acpid enabled
- Allows to be able to shutdown and startup the VMs.
- For the VMs to communicate with each other, they need to use the same Macvtap Device.
- Change passwords on kickstart file created VMs.
- Virtual Box should use Bridged Network Adapter devic.
- Linux Boot Process
- Firmware Stage.
- Executes code in BIOS for legacy systems.
- Executes code in UEFI firmware for UEFI-neabled systems.
- Starts bootloader - Bootloader Stage
- For enterprise Linux:
- Firmware executes boot loader (usually grub 2).
- Grand Unified Bootloader
- Bootloader reads its config file.
- BIOS –>
- /boot/grub2/grub.cfg
- UEFI –>
- /boot/efi/EFI/redhat/grub.efi
- BIOS –>
- Executes the Kernel.
- Grub has older kernel entries listed, if you need to boot into one for example.
- Kernel Stage
- Kernel loads ramdisk into ram.
- ramdisk is a temporary root file system.
- Includes device drivers, modules, config file and even kickstart files.
- ramdisk is a temporary root file system.
- Kernel unmounts ramdisk and mounts root filesystem.
- Starts the Initialisation Stage.
- Kernel loads ramdisk into ram.
- Initialisation Stage.
- Grandfather process runs.
- Older versions used to be the Init Process.
- Init was replaced by Upstart.
- Now replaced by systemd
- Older versions used to be the Init Process.
- systemd then starts all system services.
- Starts login shell and GUI interface.
- systemd Targets.
- Similar to Init Run Levels.
- A target is a specific system configuration.
- For Enterprise Linux, the default target is
graphical.target. - Systems can be booted into different targets.
- For instance, rescuing a system after a crash.
- The Emergency Target does not mount the root filesystem.
- It still requires a password to access.
- Grandfather process runs.
- Boot Loader Stage.
- Kernel Stage.
- Initialisation Stage.
- In GRUB, if you edit one of the entries, the line with
linuxis the line to do with the kernel and its parameters.- Press the
endkey to go to the end of the line.- Then a space between the other parameters that are there.
- Then add
systemd.unit=emergency.target - Then
ctrl+xto finish booting. - If boot process freezes at
Probing EDD- Using graphical process.
- In that case, go to
View—>Text Consoles–>Serial 1 - After maintenance is complete, press
ctrl+dto continue booting. - After editing the Kernel boot parameter again, can add to the end of the
linuxline –>rd.break- Boots the system into
read-onlymode on/sysroot - Can log in without a password.
- Should mount this
read-write - Can do so with:
mount -o remount,rw /sysroot
chroot /sysroot- Can temporarily use another directory as slash using the above method.
- Reset the root users password while in
chrootwith:passwd
- Then need
SELinuxto re-write security context on all files during next reboot.- To do so, in
/we create a hidden file.touch /.autorelabel
- Exit out of the
chrootshell withexit. - Can exit out of password recovery mode by typing
exitagain.SELiunxthen relabels the security context on all files.
- To do so, in
- Boots the system into
- Press the
- In GRUB, if you edit one of the entries, the line with
- Firmware Stage.
- To make any Kernel changes persistent in
grub.sudo grub2-set-default 1- Kernel numbering starts with
0. - Therefore the second Kernel would be
1and so forth. - If we reboot now, it will boot into the second Kernel by default.
- Kernel numbering starts with
- Can revert the above change by running
sudo grub2-set-default 0again.
- To persistently boot into another
systemdtarget, we can use anothersystemctlcommand.systemctl get-default- Usually says this is the
graphical.target
- Usually says this is the
systemctl set-default multi-user- The above configuration then sets the default target as
multi-user.
- The above configuration then sets the default target as
- To set it back again, type
systemctl set-default graphical
- systemd Services
- Sit in the background waiting for requests.
- Web servers
- File servers
- Mail servers
- Network servers
- Authentication servers
- System service is called a
daemon.- Name is from programmers at MIT.
- Took from Maxwell’s Daemon.
- A being from a thought experiment, that constantly works in the background.
- From Greek Mythology.
- Genius or deity, regarded as a good spirit.
- Linux services therefore have naming conventions, such as:
httpdsmbdsshddhcpd
- Most older Linux systems used
Sys V initfor the job of background services.- From the 1980s.
- Starts one service, that then runs all other processes.
- Had multiple Runlevels.
- Each run level would determine when services are started.
- For example:
Runlevel 3cupshttpdip6tablesiptables
- Could switch between run levels whilst the system was running.
- Issues with
Sys V init- Only started services one after another, which was not fast.
- All services ran independently of each other.
- If services were restarted, it would temporarily lose network access - causing downtime.
- Other replacement attempts for
Sys V initare:LaunchdUpstart
- Sit in the background waiting for requests.
- systemd manages system services, as well as:
- devices
- system timers
- targets
- systemd equivalent to runlevels.
- systemd objects are called “units”.
- For each unit, there is a unit file for configuration.
- This course only focuses on
service unitsandservice unit files.
- Command used to look at these units is
systemctl. - To view the unit files:
systemctl list-unit-files -at service- Shows all enabled service unit files.
enabledbeing starting automatically.- Adding the
-aflag, showsenabledanddisabledservice unit files.
- Does not show you the running status of services.
- If a service is in
staticstate, it means it is notenabledand has no provisions to be enabled. - Some services are not meant to start automatically.
- Next command is
systemctl list-units -at service-ashows enabled running and enabled non-running services.
sub- Means
sub column
- Means
systemctl list-units -t service --state running- All services files end with
.service - Shows all
runningservice files.
- All services files end with
systemctl cat SERVICE_NAME- Shows the
[unit]file which shows the service dependencies, such as forrsyslog–>;Requires=syslog.socket [service]includes what the command executes, usingrsyslog, this would be:ExecStart=/usr/sbin/rsyslogd -n $SYSLOGD_OPTIONS- and what happens when the command fails:
Restart=on-failure
- Can also get the status
systemctl status SERVICE_NAME
- Shows the
sudo systemctl enable, disable stop, status, start, restart SERVICE_NAMEcommands that you already know.sudo systemctl is-active SERVICE_NAME- Checks whether a service is active or not.
- Check if service is enabled with:
sudo systemctl is-enabled SERVICE_NAME
- If want to restrict a service from running.
- Either automatically or manually.
sudo systemctl mask SERVICE_NAME- If you then try to start the service, it will error out, saying that the
SERVICE_NAME is masked.
- If you then try to start the service, it will error out, saying that the
- Can reverse this with
sudo systemctl unmask SERVICE_NAME
- Network Settings in Linux
- Important things to setup are:
- Hostname
- Name resolution
- IP Address
- Network Mask
- Default Gateway
- Configuring the Hostname
- Edit
/etc/hostname - Or using
hostnamectlcommand.- Preferable using the command, sorts out all instances where a hostname is required and saves it to the
/etc/hostnamefile afterwards.
- Preferable using the command, sorts out all instances where a hostname is required and saves it to the
- Edit
- Name Resolution
- Require the hostname to resolve to an IP address.
- Two ways to handle Name Resolution:
- Static Name Resolution:
- Edit
/etc/hosts- The file contains IP addresses and then the alias associated with those IP addresses.
- Edit
- Dynamic Name Resolution using DNS
- Add DNS Server to
/etc/resolv.conffile.- The file contains the text
nameserverand then the associated IP address afterwards.
- The file contains the text
- Can also use
Network Manager, either from the CLI or GUI.
- Add DNS Server to
- Static Name Resolution:
- Legacy Network Interface Naming
- Ethernet was named
eth0 - Wireless was
wlan0- The number assigned, was the order the computer scanned them.
- This meant the device could change, depending on how the machine saw the hardware.
- Nowadays with the naming of Network Devices:
- Named based on firmware or BIOS info.
- Onboard devices.
- PCI-E Hotplug Devices
- Devices named by physical location.
- PCI-E Slot.
- PCI Card Slot.
- Allow traditional - unpredictable naming.
- When using predictable naming, this can be something like
Interface Type: Firmware–> therefore its name would beInterface Name: eno1 - An
Interface Type: PCI-E Slot–>ens1 - For
Interface Type: PCI Slots–>enp1s0p1in this case isPCI Bus 1ands0isSlot 0.
- Invalid Firmware Information would have an
Interface Nameofeth0for example.- This is a generic name.
- Named based on firmware or BIOS info.
- Ethernet was named
- Network Configuration Commands on CentOS:
ip- Live config only.
nm-clinm-tuituimeansText Interface Tool
nm-connection-editor- This is a graphical tool.
- GNOME/Other DE Network Config GUI.
- To see IP settings hit
ip addr.- Any changes here will only be in the live config, a reboot will lose the changes.
- Reverts back to whatever is in the config files.
nmtui- Allows you to edit IPs, network mask, gateway and default name servers.
- The GNOME or Other DEs gives a graphical editor, that is not as powerful as
nm-connection-editoror other CLI tools.
- Legacy Red Hat Static Configuration
- Would have edited a
/etc/sysconfig/network-scripts/ifcfg-eth0file- Can still use this configuration today and it supersedes anything that is in
network manager.- Should let
network managermake the required configs and only overwrite it if necessary.
- Should let
- Can still use this configuration today and it supersedes anything that is in
- Would have edited a
- Important things to setup are:
-
ifcfg-eth0Configuration looks like this:
- Sys V init Process Tree:
.
- Midnight is
0 - If there is an
*- The cron job runs every hour.
- The third column is the day of the month.
- Valid values are
1to31. *means it runs every day of the month.
- Valid values are
- The fourth column is the month of the year.
- Valid values are
1to12orJANtoDEC - An
*means it runs every month.
- Valid values are
- The fifth column is the day of the week.
- Valid values are
0to6.0is Sunday and6is Saturday.
- Can specify three letter abbreviations such as
SUN
- Valid values are
- The sixth column is the command to run.
- The above example runs
- Useful website to generate Cron Tabs is
@crontab-generator.org - Cron should usually be installed by default.
- If it is not installed run:
sudo yum install -y cronie crontabs
- Need to make sure it survives reboots.
- Start the service:
sudo systemctl start crond
- Enable it:
sudo systemctl enable crond
- To edit a user’s crontab, go to
crontab -e- Opens in the default text editor.
- Can add the following configuration (no need for other text):
0 1 * * * rsync -a ~/Documents/ ~/Documents.bak- Runs the program once per day at 1:00AM.
- To verify, we can use
cront -l
- To remove the
crontabentirely.crontab -r
- To login as a particular user:
su - USERNAME
- Good way to add Cron Jobs as a specific user:
su - USERNAME- Run the command you want to run.
- Then add it to the cron tab.
- If you have a script that you want to run hourly and not fiddle with configuration:
- Copy the script to
/etc/cron.hourly- Directories for Hourly, Daily, Weekly and Monthly
- To see all of these directories, type
ls -d /etc/cron.* ls -dlists the directories, instead of the everything in the directory.
- Cron reparses the CronTab files every minute and loads them into memory.
- No need to restart it.
- Copy the script to
- Stored in a
- To go to a specific part of a
manpage, use for exampleman NUMBER PROGRAM- For Crontab:
man cronman crontabman 5 crontab- Can check the file format with the above
man 5 crontabcommand.
- Can check the file format with the above
- For Crontab:
- As a System Admin, have to limit whom can run Cron Jobs.
The Allow Files/etc/at.allow/etc/cron.allow- Allows access to the above services.
The Deny Files/etc/at.deny/etc/cron.deny- Denies access to the above services.
- Deny files’ job is to deny users by name from using a particular service.
- The
AllowFile Overrides theDenyfile. - Pluggable Authentication Module –> PAM.
- Provides a modular authentication system for all Linux services.
/etc/security/access.conf- For instance, the file looks like:
#- : ALL : ALL-:ALL EXCEPT root:cron- The file has columns:
access control,usernamesandservice - The
-used above, means we are taking permissions away from all users, except forroot. - For the service, we have specified
cron. - It disallows all users except
rootto createcronjobs.
- The file has columns:
access.conffile provides more power.- Can find out more via
man access.conf
- Can find out more via
- User Access Files:

- AT User Access Files:

- input-output redirection
- Unnamed Pipe
- Command –> STDOUT –> (PIPE) –> STDIN
- Redirect is the same.
- Source destination is the file system.
- Command –> STDOUT –> Disk
- Source destination is the file system.
- Output to the screen:
- ls -lR / –> STDOUT, STDERR –> Display
- STDOUT
- Successful output of command.
- STDERROR
- Used for error messaging.
- STDOUT
- ls -lR / –> STDOUT, STDERR –> Display
- Redirection allows the splitting of STDOUT and STDERR.
- Can redirect either or both outputs to the disk.
- Files also have
STDIN- If want to redirect file to a command.
- Once command has processed the output, re-output it to the disk.
- Redirect STDOUT to a file and overwrite
- ls > /home/out.txt
- One
>overwrites a file or creates it if it does not exist. - To append to a file, use two
>>.
- If
STDOUTis the first output, thenSTDERRORis the second output.ls 2> /home/lsout.err- The
2>redirectsSTDERROR.- Overwrites the file if it exists or creates if it doesn’t.
- To append to an existing file, we use
2>>
- The
- To redirect ALL outputs from a command:
ls &> /home/lsout.txt- If all outputs from a command are redirected.
- Nothing shows up on the display.
- To append, similarly add
&>>instead.
- If want to redirect file to a command.
- Can append both into the
STDINof a command and then back out to a file again. An example is:sort < /home/lsout.txt > /home/sorted.txt- Redirects the sorted output back to a different file.
- Cannot redirect over the original file, as it will cause a conflict.
- Send output to a file and a screen.
- Can use
tee- It splits (or tees) the output and sends it to a file and the screen.
- An example would be
ls | tee lsout.txt
- Another good example:
find /etc | sort | tee etcsort.txt | wc -l- Shows all files in
etc
- Shows all files in
- To shows the errors:
find /etc 2> etcerr.txt | sort | tee etcsort.txt | wc -l- Only shows the output in the screen as
line count
- Only shows the output in the screen as
/dev/nullis bottomless pit.- Nothing shows on the screen, if commands are redirected.
- An example:
find /etc &> /dev/null- If we want to hide the output of a command, we can redirect to
/dev/null.
- If we want to hide the output of a command, we can redirect to
- Can use
- Unnamed Pipe
- Grep
-v- Shows inverted searches (the opposite of your search criteria)
-c- The number of lines that match.
-o- Only characters that matched (not the entire line)
-r- Recursively grep.
-E- Extended Regular Expressions (egrep)
- Pipe to grep
find / -name *.txt | grep apachefindstarts from/and looks for any files that have.txtas an extension.
- To make search criteria more strict, can employ
Anchors^- Search from beginning of the line.
- Anchor to beginning.
$- Anchor to end.
- For example,
grep -v '^$' /path/to/file.txt- The above command anchors to the beginning and end.
- Does not amtch anything in the middle.
- Loosk for blank lines.
- Combined with
-v, it only shows non-blank lines.
- Matching Characters
.- Matches one character of any type.
*- Matches 0 or more of the previous character.
.*- 0 or more rof any one character.
- Character Sets
user[abc]- Matches either
usera,userboruserc
- Matches either
user [a-z]- Matches
usera,userbetc.
- Matches
- Match everything that is not in the character set:
User[!0-9]- This would match
usera,userbetc.
- This would match
- Character Class
- Matches certain type of characters.
[:digit:]- Matches Numbers.
[:upper:]- Upper case characters
[:lower:]- Lower case characters
[:alpha:]- Upper and lower case
[:alnum:]- Upper and lower case, plus numbers.
[:space:]- Spaces, Tabs and Newlines.
[:graph:]- Printable characters, not including spaces.
[:print:]- Printable characters (including spaces)
[:punct:]- Punctuation
[:cntrl:]- Non-printable control characters.
[:xdigit:- Hexadecimal characters.
- Matches certain type of characters.
- Character Class Placement
grep 'user[0-9]' file.txtgrep 'user[[:digit:]]' file.txtgrep 'user[[:digit:][:spaces]]' file.txt- Matches users 0-9 or a user that has a trailing space with no number.
- Negating Character Classes
grep 'user [![:digit:]]' file.txt- Placing a
!before a character class negates it.
- Placing a
- Extended Regular Expressions
sed -r,egrep,awk,bash [[=~]]- Bash has a built-in regular expressions operator.
- Similar to REGEX from before.
.–> One character.*–> 0 or more of the previous character.?–> 0 or 1 of the previous character.+–> 1 or more of the previous character.- Mathes 1 or more of the previous character.
{2}- Two of the previous character.
{2,4}- Two to four of the previous character.
(ab)- Match group of characters.
(ab){2}- Two of the previous group.
(cat|dog)- Match
catordog
- Match
- Another good example of REGEX:
grep '^http.*tcp.*service$' /etc/services- Has the result of:
**http-wmap 8990/tcp # webmail HTTP service****https-wmap 8991/tcp # webmail HTTPS service**
- Anchors to the beginning of the line.
- Only shows lines starting with
http
- Only shows lines starting with
- Has the result of:
- Using
egrepegrep '^http.*(tcp|udp).*service$' /etc/services- Finds the following:
http-wmap 8990/tcp # webmail HTTP servicehttp-wmap 8990/udp # webmail HTTP servicehttps-wmap 8991/tcp # webmail HTTPS servicehttps-wmap 8991/udp # webmail HTTPS service
- Finds the following:
- Archive Files using
tartar- Tape Archiver
- Does not compress files.
- Good
tarcommand:sudo tar --xattrs -cvpf etc.tar /etc- The
--xattrspreserves extended attributes, access control lists and SELinux security context. -c- Creates an arrchive
v- For verbose
p- Save ownership and permissions.
f- File Name of the archive.
- The last argument is the items you want in the archive.
- The
- Main compression tools on Linux are:
gzipbzip2xz
- To add the option:
sudo tar --gzip --xattrs -cvpf etc.tar.gz /etc- Archives the diretory and then calls the
gzipcompressor.
- Archives the diretory and then calls the
- For
bzip2sudo tar --bzip2 --xattrs -cvpf etc.tar.bz2 /etc
- Last compressor is
xz(newest compressor) -sudo tar --xz --xattrs -cvpf etc.tar.xz /etc - In order of least to most compressed:
- gzip
- bzip2
- xz
- To view files in a tar archive:
tar -tf etc.tar- Lists all of the files in the archive.
- Can also do that with compressed files with:
tar --gzip -tf etc.tar.gz
- To extract archives, use
-xsudo tar --xattrs -xvpf etc.tarx- Extract
p- Permissions
f- File Name
- If you want to extrac this somewhere else:
sudo tar --xattrs -xvpf etc.tar -C /home/howard/
- Compress files and archives
- Compressor can be used separately with
tar.]- If not concerned about metadata like file ownership, permissions or timestamps.
- Some compressors do not work well with recursive directories.
- Best to use
tarin that case.
- Best to use
gzip FILE_NAMEgunzip FILE_NAME.gz
bzip2 FILE_NAMEbunzip2 FILE_NAME.bz2
xz FILE_NAMEunxz FILE_NAME.xz
zip FILE_NAME.zip FILE_NAME- Leaves the original file and creates a separate archive.
- Roughly the same size as gzip/
unzip FILE_NAME.zip
- Compressor can be used separately with
- Create files and directories
- Good course on VIM from LinkedIn Learning is
Linux: System Information and Directory Structure Tools echo "A New line" >> TEXTFILENAME.txt- Adds a new line to the end of the text file.
- Creating parent directories:
mkdir -p ~/parent/childfind ~/parent/child- Outputs the absolute path to the file directory.
- Can use brace expansion:
mkdir ~/{dir1,dir2,dir3}- Creates multiple directories.
ls -d ~/dir?- Shows the directory metadata with
-d ?globs for the last digit.- Shows
/home/dir1, /home/dir2etc.
- Shows
- Shows the directory metadata with
- Good course on VIM from LinkedIn Learning is
- Copy Files and Directories:
- An example
cp -pf --verbose SOURCE DESTINATION- If want to send multiple files, just separate them with spaces.
- SOURCE and DESTINATION paths can either be relative or absolute.
- Relative Paths
- Start from where you are/
- Absolute Paths
- From root or top level directory.
- There can only be one destination path.
touchis primarily for changing timestamps.- If the file does not exist however, it creates an empty file instead.
treemay not be installed by default.sudo yum install -y treetreegives a graphical visualisation of the file structure.
- If run same
cpcommand again, it will overwrite the existing file without warning.- Can provide a check using the
-iflag.- Example:
cp -i file1.txt dir1/file1-copy.txt
- Example:
- Can provide a check using the
- To copy directories.
cp -R dir1 dir2
- Good flags for
cp-a- archive - preserves all file attributes, including ownership, permissions and extended attributes and is recursive.
-b- backup - makes a backup of the destination file before overwriting.
n- no clobber - prevents overwriting files if they exist.
u- update - only moves a file if it’s newer than the destination.
- Data Blocks
- When files are copied, the data blocks are copied to a new location.
- Then the original data blocks are removed.
- If on the same HDD,
- Linux just updates the files location in the file system.
- No data is actually being moved, so it is fast.
- Linux just updates the files location in the file system.
- If on the same HDD,
mvMove command- Example:
mv -bf --verbose SOURCE DESTINATION- Can use file globbing to match file names.
- With all commands, if using single flags, can link multiple of these together.
- Relative and absolute paths are fine.
- There is only 1 destination path.
- Do not have to specify recursive, to move whole directories with
mv.mv dir mvdir2
- Useful options:
-b- Backuop of the destination file before overwriting.
-n- No clobber - prevents overwriting files if they exist.
-u- Update - only moves a file it itt’s newer than the destination.
- Example:
- Remove files and directories.
- Linux has no recycle bin.
mkdir dir{1,2}- Brace Expansion to create two directories called
dir1anddir2
- Brace Expansion to create two directories called
touch file{a,b,c,d}.txt- Makes multiple files called
filea,fileb,filecandfiled
- Makes multiple files called
rm -i fileb.txt- Adds interactivity to check if you want to remove the file or not.
- To delete a directory with
rmdirrmdir dir2rmdironly deletes empty directories.
- To delete a directory with files in it, you have to use the
recursiveoption withrm.rm -Ri dir1
- Asterix wildcard can remove everything here.
- File Globbing - can use different patterns:
file[cd].txt- Matches both
filec.txtandfiled.txt
- Matches both
file{c,d}.txt- The above is brace expansion
- Matches both
filec.txtandfiled.txt- Does the same as above.
file?.txt- Matches file
filec.txtandfiled.txt, but also matchesfilea.txtandfileb.txt
- Matches file
- This one uses an Extended Glob:
- Extended Globbing needs to turned on.
file+(cld).txt- The meaning is one or more
(c|d).txt - This matches
ccc.txtas well.
- The meaning is one or more
ls file[cd].txt- Then matches both files.
rm file[cd].txt
- Create Hard and Soft Links
- Good idea to make shortcuts to files and directories.
- An example,
- Link in home directory called
~/Netdrivethat points to/media/network/server/bob/files
- Link in home directory called
- Hard Links
- For example, making a link between directory
dir1andfile.txt ln file.txt filelink.txt- The file attributes are also exactly the same, including the timestamp.
- The reason is because they are exactly the same file.
- When Hard Links are create, it gives the system file blocks another name for them to point to.
- For example:
inode 3890775- is referenced by
/home/bob/file.txtand/home/bob/filelink.txt - They point to the same data blocks.
- is referenced by
- Hard Links do not take up hardly any space on the disk.
- Completely transparent to the OS and applications.
- All Hard Links have to be removed, before the data blocks are freed.
- If do
ls -l, this shows the amount of inodes being used.rwxrwxrwx 2 USERNAME USERNAMEetc, the2includes the amout of inodes.- If these are both the same for the hard link and the file, then it is a good way to check the hard links.
- Can check the indodes that a file is using with the
statcommand.stat file.txt- Shows the links that the file has and the Inode number.
- Using the same
statcommand onfilelink.txt- The Inode and Links displayed are exactly the same.
- Hard Link Negatives:
- Cannot link to directories.
- Cannot link across filesystems.
- Hard to indentify.
- Due to looking similar to the target file.
- Hard Link Positives:
- Take up practically no space.
- Don’t break when the target is deleted.
- Symbolic Links
- A file that points to another file.
ln -s file.txt filesymlink.txt- If do
ls -l- The leftmost character i.e.
lrwxrwxrwxis anl, showing that it is a symbolic link.- Permissions are also
rwxrwxrwx- When you access the link, it makes sure to pass you into the real file.
- Permissions on the real file arer enforced.
- If delete the original file and then run
ls -lagain.- The symbolic link becomes red.
- The Hard Link is fine and the inode number goes to 1.
- The symbolic link becomes red.
- When you access the link, it makes sure to pass you into the real file.
- Permissions are also
- The leftmost character i.e.
- Symbolic Link Negatives:
- Take up a small amount of space.
- Break if the target is deleted.
- Take up a small amount of space.
- Symbolic Link Positives.
- Can link across filesystems.
- Can link to directories.
- Easy to identify.
- A file that points to another file.
- For example, making a link between directory
- Introduction to vim.
- Insert Mode
- Command Mode –> send commands via shortcut keys.
- EX Mode –> Types commands on the bottom line.
- Can write to a new file in VIM with
:w newfile.txt - VIM processes EX Mode commands from left to right.
- Can write to a new file in VIM with
- Editing Text in VIM.
- redo =
ctrl + r - To cut a line:
ctwice inCommand Mode
- To cut a letter:
clinCommand Mode
- To cut a word:
cwinCommand Mode
pinCommand Modeto thenputorpastethe line.- To copy
yank- One letter is:
yl
- One word is:
yw
- One line is:
yy
- One letter is:
- To delete text:
dl- Delete a letter.
dw- Delete a word.
- It does not actually delete it, it just moves it into a buffer until you paste it.
- Delete leaves you in
Command modecutplaces you intoInsert mode
- Can
yankor do any other command multipe times with5yy
- redo =
- Locate, read and use systesm documentation
ls --help--help- Is built into most Linux commands.
shift + page upto go through the output.
cd --helpdoes not work.- The reason, is because
cdis built into the Bash shell. - It doesn’t exist as a separate command on the disk.
- The reason, is because
- For commands built into the shell.
- Use the
helpcommand.help cdfor example.
- Use the
- The documentation for the
helpcommand is usually brief. manpages.- All
manpage belong in certain categories.- For example, if you do
man lsand then check the top left-hand sorner, it wiill sayLS (1)
- For example, if you do
- All
- Can also see the
man man-pagesfile.- This then explains each of the categories, for example
1 Commands (Programs),2 System calls.man 1 intro- Shows the intro page for man page - category one.
man -f- Used to find man pages.
- For example
man -f crontab- Shows all of the
manpages relatedcrontab - Category 1
commands - Category 1p (P is for POSIX compliant commands)
- Category 5 is for file formats.
- POSIX is a standard, that most Unix systems try to follow.
- Linux can have a non-POSIX compliant command, as well as a compliant one.
- Shows all of the
- For example
- Used to find man pages.
- Can spcify a
manpage category with:man 5 crontab
- For an exhaustive search, that would be
man -k crontab- Shows related words like
anacrontab
- Shows related words like
- Another place we can get information is through
infopages.- Not all commands have
infopages.info crontab
- Shows more lines than
mandoes. - Most GNU tools have very long
infopages.infosupports hypertext.- A hyperlink in an
infopage is a name followed by a colon.- Can move cursor over it and press
enterto go to that page. - To go back to the previous page, press the
lkey. - If you scroll down to the bottom, taken to the next page.
- Scrolling to the top, takes us to the previous page.
- Can get additional help by pressing
?inside any document.
- Can get additional help by pressing
- Can move cursor over it and press
- Not all commands have
- This then explains each of the categories, for example
- Locate and interpret System Log Files
- Messages are related to kernel, applications or services.
- Logs specifically also for cron jobs and so on.
- Enterprise Linux has two logging systems:
rsyslog- Compatible with
sysklogd - Handles perisstent logs.
- Logs are text files.
- Can log across a network as well.
- Using TCP or UDP protocols.
- Compatible with
journald- Not persistent by default.
- Part of systemd.
- Journal logs do not survive a reboot.
- Logs are binary.
- Logs are only stored in RAM.
- Very fast to write and search through.
sudo systemctl start rsyslog- Starts the service.
- Then run
sudo systemctl enable rsyslog- So it starts afte boot.
- To check the configuration file for Rsyslog:
less -N /etc/rsyslog.conf-Nturns line numbering on.
- The file has a
RULESsection.- Where each type of data is logged.
- There are two columns in a rule:
- Selector on the left, for example
authpriv.crit - Action on the right, for example
/var/log/secure - rsyslog rule - selector facility.
- Facility is on the Left and Priority is on the Right.
- For example:
authpriv.crit- The
authpart is the Facility. - The
privpart is the Priority.
- The
- The action in this case is
/var/log/secure - Line 46 is
*.info;mail.none;authpriv.none;cron.none /var/log/messages- It means log anything except mail of level
infoor higher.- Don’t log private messages.
*is the Facility and uses an Asterix that matches everything.infois Priority.- Selectors are
mail.none;authpriv.none;cron.none /var/log- For
mail, authpriv and cron, the priority of these is set to none.- All messages will be ignored.
- The Action to write is
/var/log/messages
- For
- It means log anything except mail of level
- Selector on the left, for example
/var/log/messages- Contains all system messages.
- The go-to file for troubleshooting a system.
- To invert the search.
sudo grep -v 'systemd' /var/log/messages- Will show all of the messages that do not have
systemdin them. - If want to filter out more messages, can create a logical OR, as well as changing
greptoegrepwith more criteria. sudo egrep -v 'systemd|NetworkManager' /var/log/messages- Shows all of the messages that do not have
systemdorNetworkManagerinside of them. tail -fis also a good option.
- Shows all of the messages that do not have
- Will show all of the messages that do not have
- Back in the configuration file for
rsyslog,authpriv.*is where we see login information, including failure as well. - Line 65 specifies the boot messages. This is
local7.*and the action is in/var/log/boot.log - Can see lines at the bottom (line 78) for examples on how to do the configuration remotely as well.
- The logs are rotated and this is done via
/etc/cron.daily - If you ever want to write a message to the system log file.
- You can use a
loggercommand for this. logger "Linux is so worth it!"- You can then see this in
/var/log/messages
- You can then see this in
- You can use a
- To invert the search.
- Messages are related to kernel, applications or services.
- Reading the System Journal
- Along with systemd, also comes journald
- Stores a binary log file in
/var/run- Virtual file system in RAM.
- Everything disappears after a reboot, so it is not persistent.
- The journal also has a fixed size, because it is located in RAM.
- Journal is structured and indexed, therefore searches are quick.
- Can use
rsyslogfor persistent logging.- Can forward journal data to rsyslog.
- Typing in
journalctlwithout arguments provides all of the journal entries.- To view journal entries only from the kernel, use
journalctl -k
- To view journal entries only from the kernel, use
- For
crond, we can usejournalctl /sbin/crond - To specify by systemd unit, we use
journalctl -u crond journalctl -f- Follows the journal.
- To restart
journaldusesudo systemctl restart systemd-journald- To check the logs, can go to
/var/log/journal
- To check the logs, can go to
- Once
journaldhas been configured to be persistent.- Can show previous entries before a reboot occurred.
sudo journalctl -b -1- If a reboot has not happened, nothing will appear.
- Can also specify time ranges:
journalctl --since "2015-01-10 17:15:00"journalctl --since "2015-01-10" --until "2015-01-11 03:00"journalctl --since 09:00 --until "1 hour ago"
- Install from a software repository.
- Index of packages.
- Contains meta-data about packages.
- The description of the package.
- Who packaged them.
- Contents of the package.
- Public Key.
- Imported by the client.
- Verifies the integrity of the packages.
- Server on Network or Internet.
- Uses FTP or HTTP protocols.
- Can be hosted on Windows, macOS and Linux.
- Best is if host and clients are on similar OSs.
- The tools for building the packages may not be available on alternative operating systems.
- For example, RPM packages on a Debian machine.
- Internet connection and DNS are required to connect.
- Package Database Contents
- Updates with various meta-data, such as:
- Installed File Location
- File sizes
- Ownership
- Checksums
- Package Summary
- Package Description
- Advantages of using software repos
- Easy to install software.
- Resolves dependencies
- Handle package signatures
- Negatives
- Slower to install
- Requires working network
- Requires working name resolution
- Updates with various meta-data, such as:
- Linux Repository Management Systems
- Query package database.
- Upgrade and List files and packages.
- Check Package Dependencies.
- Repository-based Package Managers
- APT
- Yum
- Zypper
- Urpmi
- From Mandriva
- Maintains list of available software.
- Calculates dependencies.
- Uses local package manager to install packages.
- The actual software is installed with
dpkg/rpm.apt/yum- Download
- Search
- Manage dependencies
- The actual software is installed with
- Advantages of Repo Package Managers
- Upgrade entire OS.
- Full Support cryptographic signatures.
- Stops hackers embedding malware, due to the key sending of packages and repositories.
- Can add third party repositories as well.
- Query with RPM
- Query database.
- Query package.
- Query a file.
- Looking through package database, looking for a reference to the file.
- Only works for files that belong in its database.
- To query the db with
rpmwe use the following commands:rpm -qa-qtells RPM to query.ameans all packages.- Shows all installed packages.
- If you pipe into
sortwithrpm -qa | sort- Provides you with an alphabetical list.
rpm -qi- The
qiis for Query Information about a package. - For example,
rpm -qi bash- Shows you all of the information regarding bash.
- The
- Can also narrow down the search based on single attributes.
rpm -qa Group="System Environment/Shells- Shows all of the packages, that have been tagged as
system environment shells.
- Shows all of the packages, that have been tagged as
rpm -qa --last- Queries when packages were last installed and shows the date.
rpm -ql yum- Queries for the list of file paths.
- The
yumcommand contains 180 different files in various locations.
- The
- If we want to reduce this search to just documentation.
- Can specify the option with
-d
- Can specify the option with
rpm -qd yum- Finds all of the documentation for
yum
- Finds all of the documentation for
-coption- Only show configuration files.
- If find a file on a disk.
- Can query the database as well.
-qfoption.-qfis Query File.rpm -qf /bin/bash- Shows the
/bin/bashfile came from thebashpackage. - Identifying where software comes from, really helps with learning Linux.
- Shows the
- Can also use
-qdfand shows the documentation for the/bin/bashcommand.- If find file and want to know where the documentation is, the above option is useful.
- Can also ask a database what a package provides with
--providesrpm -q --provides bash- Shows the features that the
bashpackage provides.
- Shows the features that the
- Can see what it requires with
rpm -q --requires bash
- Another good option is
--changelog- Checks changes to any packages.
rpm -q --changelog bash- Can query an RPM file directly, before it is installed.- If downloading individual packages from the Internet with
yum- Need a plugin for that.
sudo yum install -y yum-plugin-downloadonly
- Then
sudo yum install --downloadonly --downloaddir=/tmp/packages httpd- Downloads the files to the
/tmp/packagesdirectory.
- Downloads the files to the
- To query a package that has not been installed yet, use
-prpm -qip httpd-2.4.6-45.el7.centos.x86_64.rpm- To query a package, we use
qip- To get a list of all the files within a package and where they’ll be install, we use
-lrpm -qlp httpd-2.4.6-45.el7.centos.x86_64.rpm- Make sure the
-poption is provided, so it queries the package and not the database.
- To get a list of all the files within a package and where they’ll be install, we use
- To query a package, we use
- Queries for the list of file paths.
- RPM Query Formatting
- All packages have a list of tags we can show or hide.
rpm --querytags- To show package name and version and nothing else:
rpm -qa --queryformat "%{NAME} %{VERSION}\n"- To use the tags, need to surround them with
%and{}\ninserts a new line.
- Can also make the command shorter with:
rpm -qa --qf "%{NAME} %{VERSION}\n"- Does the same thing.
- To use the tags, need to surround them with
rpm -qa --queryformat "%-30{NAME} %-10{VERSION}\n"- Shows 30 characters.
- Version uses 10 characters.
- Both columns are left-aligned.
- Version uses 10 characters.
- Shows 30 characters.
- When dealing with multiple lines in a package, information is stored in arrays.
rpm -ql bash | wc -l- Shows 130 files in the
bashpackage.
- Shows 130 files in the
rpm -q --qf "%{FILENAMES}\n" bash- Returns one item and shows the first item in the array.
rpm -q --qf "[%{FILENAMES}\n]" bash- Can show the contents of more than 1 array, but placing the tag inside the square brackets.
- Show file names and file sizes in the
bashpackage. rpm -q --qf "[%{FILENAMES} %{FILESIZES}\n]" bash- Can then show 50 characters:
-
rpm -q --qf "[%-50{FILENAMES} %{FILESIZES}\n]" bash- Some tags need additional formatting, for example the package name and the install date + time. -rpm -q --qf "%{NAME} %{INSTALLTIME}\n" bash- Shows the date in epoch time. The number of seconds since 1970.
-
rpm -q --qf "%{NAME} %{INSTALLTIME:date}\n" bash - Then shows the readable date.
rpm -q --qf "[%{FILEMODES} %{FILENAMES}\n]" bash- Shows the permissions here.
rpm -q --qf "[%{FILEMODES:perms} %{FILENAMES}\n]" bash- Shows the permissions in a readable format.
- Shows the date in epoch time. The number of seconds since 1970.
-
man rpm- Then
/QUERY OPTIONS- Use these in shell scripts, to return the information needed.
- More reliable then piping the output to
greporawkfor data parsing.
- Then
- To show package name and version and nothing else:
- DNF Overview
- RPM Abilities.
- Reads list of dependencies.
- Download from web or FTP servers.
- Does not maintain a list of available software.
- Does not manage them in remote repositories.
- Therefore, to get around these issues, Yellow Dog Linux created YUM
- Yellow Dog Updated Modified (YUM).
- This was rewritten and renamed as DNF.
- CentOS 6 & 7 uses YUM.
- CentOS 8, DNF is the default package manager, but can still input YUM, as the package just redirects to DNF.
- DNF resolves dependencies automatically.
- Uses Package Groups.
- A bunch of packages that are generally stored together.
- Repositories contain RPM packages.
- Client maintains local list of repositories.
- Users can add repositories, by changing the config.
- Packaging Process in DNF:
- Package Install Process:
- DNF Contacts Configured Repositories:

- DNS gets list of available software packages:
- Lists are cached locally and updates them during install operations.

- Lists are cached locally and updates them during install operations.
- User selects a software package:

- DNF calculates dependencies:
- Requested software package and any packages it requires.
- Biggest differences between YUM and DNF, are the algorithms used to calculate dependencies.

- DNF downloads packages/installs using RPM libraries (similar to the RPM command)

- Once install finishes, DNF updates the local package database:

- DNF Contacts Configured Repositories:
- One features that separates DNF from other repo-based package managers is using DNF Groups
- Contain multiple software packages.
- All sofrware in a group can be installed at one time.
- All software in a group can be removed at one time as well.
- Unless other packages require it.
- Groups can contain optional software.
- Related software, but not installed by default.
- RPM Abilities.
- Select DNF Packages by Name
- Being able to list information about whether wanting to install a 32-bit package on a 64-bit system for example, then installing, is very powerful.
- For example, attempting to sync
xfsprogs- Multiple versions of this package are available.
dnf --showduplicates list xfsprogs- Shows all packages and their versions.
- Granular Package Selection
- For example,
Available Packages 5.0.0.-2.el8 BaseOSxfsprogs.i686 5.0.0-2.el8 BaseOSxfsprogs.x86_64
- For example,
- We can select packages based on:
namename.arch- CPU Architecture
name-ver- Name and Version
name-ver-rel- Name, Version and Release
name-ver-rel.arch- Name, Version, Release and CPU Architecture.
name-epoch:ver-rel.arch
- To select a package by name, we just add the name.
- DNS does a greedy search, so as long as we add
--showduplicatesit will show all possible matches.
- DNS does a greedy search, so as long as we add
- Narrow down by architecture with.
dnf list --showduplicates xfsprogs.x86_64
- Select by name and version:
dnf list --showduplicates xfsprogs-5.0.0
- Name-version-release:
-
dnf list --showduplicates xfsprogs-5.0.0-2.el8- The release here is2.el8 - Name-version-release.architecture
-
dnf list --showduplicates xfsprogs-5.0.0-2.el8.i686- Tries to select the architecture, based on OS install, if not specified.
- There are times when we do want to overwrite, for example installing a 32-bit package on a 64-bit system.
- Can use file globs.
-
dnf list --showduplicates xfsprogs-5.0.0-[1-6]* - Select by name-epoch:version-release.arch.
dnf list --showduplicates ypbind-3:2.5-2.el8.x86_64- Overwrites the normal comparison order on version checking.
- If a packager wanted to mark a lower version for an upgrade, can tag it with an epoch number.
- DNF is picky about the format and which fields are necessary with the epoch number.
- If leave field out or put in different order, DNF will not find any matches.
- The epoch number is usually used to override normal update processes.
- To see a list of packages with an
epochnumber, rundnf list installed- Any package that has a version prefixed by a colon, has an epoch number.
- Get Info on Packages with DNF
dnf list --all- For this particular sub command, the
--allis not necessary. - Provides a quick list of all packages.
- Includes packages in the local RPM DB.
- And packages that are listed in a repository.
- The furthest right-hand column shows the repository it came from.
- For this particular sub command, the
- Can show duplicates with:
dnf list --all --showduplicates- If the package name is green and underlined, it is the currently installed version.
- Shows when both 32-bit and 64-bit versions are available.
- Package names in blue, show there is an update available.
- Can be different on other distros, blue is what CentOS uses.
- To show installed packages.
dnf list --installed
- To show the packages that need updates.
dnf list --updates- The packages listed would be installed, if we did a
dnf upgrade
dnf list --available- Shows software packages available in the repositories, but are not installed.
dnf list --obsoletes- Packages can be replaced by other packages, making the original package obsolete.
dnf info dnf- Shows more information about the
dnfpackage.- Shows
name,version,release,architecture,size,source,repository,summary,URL,licence,description- For both installed version and update.
- Shows the same information that you would get from
rpm -qi
- Shows
- Shows more information about the
dnf info --updatesdnf info --obsoletes- To get the dependencies that a package requires:
dnf deplist dnf- For example, shows what the
dnfpackage requires and which packages provide that item.
- Get Info on Package Groups
dnfhas the concept of package groups.- Pre-configured collection of packages, that can be installed or removed at one time.
- For example, dev-tool groups.
- Contains compilers and coding tools.
dnf group list- Shows all groups.
- Older versions of CentOS have a sub-command with
grouplistspelt all as one word.
- Older versions of CentOS have a sub-command with
- Shows the following categories:
Available Environment GroupsInstalled Environment GroupsInstalled Groups- Category of groups currently installed.
Available Groups- Contains collections of software for OS configurations.
- During system install, there are a lot of environment categories.
- Hidden by default and are used during the install process.
dnf group list hidden- Shows these groups.
- Very specialised, so hidden by default.
dnf group info "Development Tools"- Because the group name has a space in it, it needs to be surrounded with double quotes.
- Shows three categories:
- Mandatory Packages.
- Default Packages.
- Optional Packages.
- Depending on
dnfconfig, one or more of the above categories is installed by default.- CentOS8, Mandatory and Default Packages are installed automatically.
- Config option needs to be changed, for the Optional Software to be installed automatically.
- Can overwrite it with
--with-optional- Installs optional software.
- Can overwrite it with
- Config option needs to be changed, for the Optional Software to be installed automatically.
- CentOS8, Mandatory and Default Packages are installed automatically.
- Shows all groups.
- Search for Packages
dnf search vim- By default,
dnfsearches the name and summary information only. - Results are printed in bold.
dnfwill do a case insensitive search.
- By default,
- To search all metadata including the description:
dnf search --all vim- The last couple of lines do not have bold text.
- It means the name
vimis not in the name or summary. Probably in the description.
- It means the name
- The last couple of lines do not have bold text.
- Wildcards:
dnf list --all vi*- Shows all packages that start with
vi
- Shows all packages that start with
dnf provides vim- Shows which packages provide
vimand what version it is.
- Shows which packages provide
- Install and Remove Packages
sudo dnf install -y tree- Allows us to view our file structure as a hierarchy on the command line.
sudo dnf install -y epel-release- Third party repository –> Extra Packages for Enterprise Linux
- Safe repository.
- Always good to install on Enterprise Machines.
- Third party repository –> Extra Packages for Enterprise Linux
sudo dnf install konsole- May want to reinstall the exact same version of a package
- This is a good way to troubleshoot problems.
- Can also use
yum’s reinstall sub command.
sudo dnf reinstall vim- Can reinstall VIM.
- Downloads a new RPM and installs it over the old one.
- If want to install a package and one of its dependencies is broken and needs fixing by maintainers.
sudo dnf reinstall vim --skip-broken- Works with
install,reinstallandupdatesub commands.
dnf list updates- Shows all packages that need upgrading.
sudo dnf upgrade teamd- Package name example
sudo dnf remove teamd- If want to remove one package and all other software requires that package,
dnfwill uninstall the OS. - If want to remove package and its dependencies (and aren’t being used by other packages).
sudo dnf autoremove- Gets rid of any unused dependencies in the entire system.
- Can also use
autoremove, juist likeremoveand specify a package.
- If want to remove one package and all other software requires that package,
- Install and Remove Package Groups
- Every
dnfgroup has a group ID.- In addition to its name.
dnf group list ids- Shows names and IDS.
- Shows the group ID inside parenthesis.
- Group References
dnf group install "Security Tools"- Group name enclosed in double quotes.
- Can use the ID of the security tools group, which is:
dnf group install security-tools- No need for double quotes with ID.
- Can also manage groups using package sub commands:
dnf install @"Security Tools"- Need to prefix group names and IDs with an @ symbol.
dnf install @security-toolsdnf group list ids- Shows the groups that are installed.
- To update all packages in a group, use
group upgradesudo dnf group upgrade security-tools- Upgrades all packages in the
security-toolsgroup.
- Upgrades all packages in the
- To remove a
dnfgroupsudo dnf group remove security-tools- Removes all packages in the group.
- If not all packages are removed.
- Can use the
autoremovecommand.
- Can use the
- Shows names and IDS.
- Every
- Manage OS Updates
dnf check-update- Shows all software packages that need updating
- Any packages that are indented, are obsolete.
- The packages that they are indented from, will replace them.
- Can verify with
dnf list --obsoletes
- Shows all software packages that need updating
- Can upgrade specific packages with
sudo dnf upgrade grub2-tools- Upgrades the
grub2-toolspackage and its dependencies.
- Upgrades the
- Upgrade the entire OS with
sudo dnf upgrade - If want to upgrade all packages except one, can use the
-xoption.sudo dnf upgrade -x kernel*- Upgrades everything instead of the kernel packages.
- Can install a
dnfversion lock plugin to stop certain packages from ever being updated.sudo dnf install python3-dnf-plugin-versionlock
- There are times we want to lock the Kernel to a specific version so it is not accidentally updated.
- A reboot is necessary for the Kernel to be active.
dnf list --showduplicates kernel- Any packages shown in blue, are updates that are available.
- If want to lock the kernel so it is not updated.
- Available to versionlock it.
- If want to lock the current kernel.
- Can just use the name
kernel
- Can just use the name
sudo dnf versionlock add kernel-4.18.0.193.el8- To see a list of version lock packages
dnf versionlock list
- To delete a versionlock:
sudo dnf versionlock delete kernel-4.18.0.193.el8
- To clear all versionlocks
sudo dnf versionlock clear
- Can be more granular doing OS updates.
sudo dnf upgrade --security- Updates all packages with security updates to the latest version.
- Even if the latest version is only a bug fix.
- Updates all packages with security updates to the latest version.
- Preserving Configuration Files
- Another thing to keep in mind when installing single packages or upgrading the entire OS.
- Config files may be renamed when a new package is installed.
- Unmodified Configuration File
- Config file is overwritten
- Modified Configuration File
- Modified config file saved with
.rpmsave or .rpmorigextension..rpmsaveused if the file was installed from a previous RPM package..rpmorigextension, used if the file came from a non-rpm source.- What would happen if install from source code and then move onto a later RPM package.
- New config file is saved from the package.
- Modified config file saved with
- Modified configuration file and noreplace label in package
- If admin has modified the configuration file.
- and software package maintainer included the
noreplacelabel in the package. - New config file is saved with
.rpmnewextension. - Original configuration is left in place.
- and software package maintainer included the
- When installing with
dnforrpm, will see message that shows which operation was done, so can check there.
- If admin has modified the configuration file.
- Can check through the change logs, to see if issues or bugs were fixed.
dnf changelog kernel
- To only get change logs for packages listed to be updated:
dnf changelog --upgrades
- Another thing to keep in mind when installing single packages or upgrading the entire OS.
- Update the Kernel
- List currently installed kernel packages.
dnf list kernel- Item in bold belong to the current kernel.
- Include the kernel itself, along with modules and tools.
- Example, kernel version is
4.18.0-and the release is193.el8 - The major version is
4 - The major revision is
18 - Kernel patch is
0 - Red Hat release is
193 - Built for
Enterprise Linux 8
- Example, kernel version is
- Installed kernels reside in ``/boot`
ls -l /boot- Kernels are named
vmlinuz - Have RAM Disk Images for Booting
- Configuration Files.
- Kernels are named
- To see the current Kernel and Release
-r, type in:uname -r
sudo ls -l /boot/grub2- The configuration file for BIOS-based systems is
/boot/grub2/grub.cfg - Do not edit the files, as they are overwritten on Kernel updates.
- If you want to modify the way Linux boots, edit
/etc/default/grub- After making any changes here, have to run
grub2-mkconfig, which updates the bootloader code.sudo grub2-mkconfig- Ran automatically whenever a new Kernel is installed.
- Takes the
grub2config files and updates the bootloader code.
- Takes the
- After making any changes here, have to run
- If you want to modify the way Linux boots, edit
- For a UEFI system, the bootloader code is stored in
/boot/efi/EFI/centos/grub.cfgredhatwoud replaceCentOSfor the correct path.
- The configuration file for BIOS-based systems is
- To check for an update to the Kernel:
dnf list --available kernel- Then upgrade with
sudo dnf upgrade kernel- Downloads the newest kernel and installs it.
- For a specific kernel, can just put the kernel name in.
- Can use
dnf removeto uninstall kernels.- Different from
yum, where it lets you uninstall a kernel that you are currently using. - Workaround for
dnf, where you can preservexamount of packages that are the same name.- A configuration item in the
/etc/dnf/dnf.conf- It is called
--latest-limit- Can also set this on the command line, when uninstalling kernels.
- It is called
- A configuration item in the
- Different from
- Can use
- Then upgrade with
- If want to uninstall all but the last two kernels:
sudo dnf remove $(dnf repoquery --installonly --latest-limit=-2 -q)- Uses
dnf repoqueryto get a list of kernels further back than two and passes that list todnf remove.
- Uses
- To set the default boot kernel to another kernel
- Use the
grub2-set-defaultcomman.- Indexing starts at 0, so the newest kernel would be zero.
- One kernel older than that would be one.
- To set the default Kernel to 1.
sudo grub2-set-default 1
- Then need to update the
grubconfig:sudo grub2-mkconfig
- Now if you reboot the system, it comes up with the second kernel.
- Use the
- List currently installed kernel packages.
- Manage Kernel Modules
- In addition to the kernel itself, Linux has other modules that need to match the Kernel version.
- Modules add functionality to the kernel, that include:
- File systems.
- Device Drivers.
- 32-bit kernel modules are stored in:
/lib/modules
- 64-bit kernels:
/lib/modules
- Modules add functionality to the kernel, that include:
/lib/modules/$(uname -r)/kernel- The
$in parenthesis arounduname -rwill then execute the command.- The result is then inserted into its place.
- Easy way to insert the current kernel version into the path, without having to look it up.
- Shows directories for drivers, filesystems, network and virtualisation.
lsmod- Shows more information about available modules.
dm_mod- Provides LVM mirrors.
modinfo dm_mirror- Shows more information about a certain module.
- To remove a module:
sudo modprobe -vr dm_mirror
- To load a new Kernel module:
sudo modprobe -v dm_mirror- The
modprobecommand also loads any dependencies that the module may have. - In this case it loads the
dm-log,dm-region-hashanddm-mirrormodules.- Some modules take a customer parameter, just like a Linux command.
- Good idea is to check the
manpage for the syntax of the parameters. - Usually separated by space, but commas as well.
- Good idea is to check the
modprobewill exit without loading the module, if the module is already loaded.- If you want to change the parameters, have to unload the module and then reload it with custom parameters.
- Linux usually loads device drivers automatically, but sometimes needs to be forced.
- For instance, a device added across the network, but the local OS does not know it is there.
- This is the case with storage or remote printers.
- If the hardware is local, we can make Linux scan for it with
sudo depmod -v- Tells us the modules that are needed, either by hardware or other modules.
depmodalso updates the module dependency file in/etcas well.
- Tells us the modules that are needed, either by hardware or other modules.
- If the hardware is local, we can make Linux scan for it with
- To have modules loading automatically at boot.
- Need to create a file in
/etc/modules-load.dand include the module name. - Can name the config file anything, as long as it ends in .conf
- Need to create a file in
- Example:
sudo vim /etc/modules-load.d/dm_mirror.conf- Add the module name
dm_mirror - That’s it. Then save it. Nothing else aside from the name needs to be in the file.
- Add the module name
- The
dm_mirrormodule willl be loaded at boot.
- If you want to make sure a file is not loaded at boot.
- Make a file in
/etc/modprobe.d- This is called
blacklistinga module.
- This is called
- If we want to blacklist an old soundblaster driver, so it does not load:
sudo vim /etc/modprobe.d/ctxfi.conf- The name of the file does not matter, since we are creating it ourselves.
- The only line we would add is
blacklist snd-ctxfi- Save that.
- It is rare that we have to manually manage modules like that.
- Make a file in
- If you want to change the parameters, have to unload the module and then reload it with custom parameters.
- Some modules take a customer parameter, just like a Linux command.
- The
- In addition to the kernel itself, Linux has other modules that need to match the Kernel version.
- The exam is 2.5 hours and has no Internet access. Access to
manpages is permitted. This is done in a lab enviornment.- The learning is done on a per product basis.
- Virtualisation Environments:
