← All chapters · Book · Repository
Chapter 8: Task Scheduling and Remote Access Answers
Red Hat RHCSA 10 Study Companion: Getting Ready for the EX200 Exam by Andrey Markelov (May 2026).
Topics
- Background jobs
- at command
- Cron jobs
- Time management (timedatectl)
- SSH key generation and configuration
exercise_01.sh
executable safe: yes#!/bin/bash
# @type: executable
# @requires: none
# @safe: yes
set -euo pipefail
# Exercise 1: Execute the sleep 1200 command in the background.
# Immediately verify it is running, and then note its job number.
#
# Task: Start a background job and verify its status.
# Start sleep in background
sleep 1200 &
echo "Sleep process started in background."
echo ""
# List jobs with PID
jobs -l
exercise_02.sh
executable safe: yes#!/bin/bash
# @type: executable
# @requires: none
# @safe: yes
set -euo pipefail
# Exercise 2: Start a ping 127.0.0.1 process in the foreground.
# Stop it using the appropriate key sequence, and then send the stopped process
# to the background so it resumes running.
#
# Task: Demonstrate job control - stopping and backgrounding a process.
echo "Starting ping in foreground..."
echo "Press Ctrl+Z to stop it, then run: bg %1"
echo ""
# Start ping process
ping 127.0.0.1
# After Ctrl+Z is pressed, the user would run:
# jobs
# bg 1
# jobs
exercise_03.sh
executable safe: yes#!/bin/bash
# @type: executable
# @requires: none
# @safe: yes
set -euo pipefail
# Exercise 3: Schedule a command using at to execute 5 minutes from now.
# The command should redirect the output of date to a file named ~/test_output.txt.
#
# Task: Schedule a one-time task using the at command.
# Schedule the job
at now + 5 minutes << EOF
date > ~/test_output.txt
EOF
echo "Job scheduled to run in 5 minutes."
echo "The output will be saved to ~/test_output.txt"
exercise_04.sh
executable safe: yes#!/bin/bash
# @type: executable
# @requires: none
# @safe: yes
set -euo pipefail
# Exercise 4: Immediately after scheduling the job, use the command to view the job queue.
#
# Task: Display scheduled at jobs.
atq
exercise_05.sh
executable safe: yes#!/bin/bash
# @type: executable
# @requires: none
# @safe: yes
set -euo pipefail
# Exercise 5: Edit your user's crontab file to run the command
# /bin/echo "Cron!" > ~/cron.log every day at 9:00.
#
# Task: Create a cron job that runs daily at 9 AM.
echo "Adding cron job..."
# Add the cron job
(crontab -l 2>/dev/null; echo "0 9 * * * /bin/echo \"Cron!\" > ~/cron.log") | crontab -
echo ""
echo "Current crontab:"
crontab -l
exercise_06.sh
executable safe: yes#!/bin/bash
# @type: executable
# @requires: none
# @safe: yes
set -euo pipefail
# Exercise 6: Use the Systemd utility to display the current system time,
# time zone, and the status of the NTP service.
#
# Task: Display time and NTP synchronization status.
timedatectl
exercise_07.sh
executable safe: yes#!/bin/bash
# @type: executable
# @requires: none
# @safe: yes
set -euo pipefail
# Exercise 7: Generate a new key pair. Use a strong passphrase for security.
# What are the names of the two files created in your ~/.ssh/ directory?
#
# Task: Generate SSH key pair and identify the created files.
echo "Generating SSH key pair..."
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519
echo ""
echo "Files created in ~/.ssh/:"
ls -la ~/.ssh/id_ed25519*
echo ""
echo "The two files are:"
echo "1. id_ed25519 (private key)"
echo "2. id_ed25519.pub (public key)"
exercise_08.sh
executable safe: yes#!/bin/bash
# @type: executable
# @requires: none
# @safe: yes
set -euo pipefail
# Exercise 8: You need to enable key-based authentication for the user root on the local server 127.0.0.1.
# Use the specialized utility to securely copy your users' public key to the server.
#
# Task: Copy SSH public key to remote server for key-based authentication.
ssh-copy-id -i ~/.ssh/id_ed25519.pub [email protected]
echo ""
echo "Note: This will work if PermitRootLogin is enabled in the SSH server configuration."
echo "For a separate VM, you may need to modify /etc/ssh/sshd_config:"
echo " PermitRootLogin yes"
exercise_09.sh
executable safe: no requires: root#!/bin/bash
# @type: executable
# @requires: root
# @safe: no
set -euo pipefail
# Exercise 9: Which two lines would you modify in the main OpenSSH server configuration file
# (/etc/ssh/sshd_config) to disable password authentication and prevent the root user
# from logging in directly?
#
# Task: Display the SSH configuration changes needed for improved security.
echo "To disable password authentication and prevent root login,"
echo "modify these lines in /etc/ssh/sshd_config:"
echo ""
echo "PasswordAuthentication no"
echo "PermitRootLogin no"
echo ""
echo "After making changes, restart sshd:"
echo "sudo systemctl restart sshd"