Day 2 Lab Workbook: Build a RHEL Practice VM and Connect with SSH¶
1. Lab Overview¶
| Item | Detail |
|---|---|
| Lab title | Build your own RHEL practice lab and manage SSH access |
| Objective | Create a RHEL virtual machine, install the operating system, connect to it with SSH, and safely change and restore the SSH server configuration |
| Skills tested | VM creation, RHEL installation choices, network discovery, SSH client use, sshd configuration, service management, log reading, troubleshooting |
| Estimated time | 2 to 3 hours (most of it is installation time) |
| Difficulty | Beginner to intermediate |
| Required environment | A Windows (or other) computer with VMware Workstation or VirtualBox, a RHEL ISO, and about 20 GB of free disk space for the VM |
| Prerequisites | Day 1 completed; a Red Hat account with access to the RHEL download |
2. Lab Environment and Safety¶
Requirements
- A host computer with enough free memory to give the VM 2 to 4 GB while the host stays responsive.
- A hypervisor: VMware Workstation or Oracle VirtualBox. The steps in the notes use VMware Workstation.
- A RHEL installation ISO downloaded from your Red Hat account.
- Internet access for downloads.
Assumptions (not verified for your environment)
- Your hypervisor's default network mode lets your host reach the VM's IP address. If it does not, adjust the VM's network adapter in the hypervisor (for example, NAT or bridged).
- Your CPU and hypervisor meet the hardware requirements of the RHEL release you install. Check Red Hat's documentation.
- Menu names in the hypervisor and the installer may differ slightly from the notes.
Safety
- Use only a private, disposable VM. Do not run these tasks on production or shared systems.
- The simple passwords used in this lab are acceptable only because the VM is private. Never use them on a real system.
- Changing SSH settings can lock you out. Keep the VM console (or an existing SSH session) open while you test changes.
- Do not disable SELinux or the firewall at any point in these tasks.
- The only destructive actions are deleting and recreating your own practice VM. Do not delete anything else.
3. Practice Tasks¶
Complete the tasks in order. Solutions are in the last section. Try each task using only the requirements before consulting the notes or hints.
Task 1: Prepare the host and download¶
Scenario: You want a private RHEL environment on your computer that will outlast the time-limited hosted lab.
Requirements:
- Confirm your computer has at least 20 GB of free disk space for the VM and room for the ISO file.
- Install a hypervisor (VMware Workstation or VirtualBox). If an older version is present and the installer offers Change, Repair, or Remove, handle it appropriately.
- Download the RHEL ISO.
- Confirm the ISO is not corrupted by comparing its checksum with the value published by Red Hat.
Hints:
- In Windows PowerShell, a built-in command can calculate a file's SHA-256 hash.
- A mismatched checksum means you should download the file again.
Success criteria: The hypervisor opens, and your calculated checksum matches the published checksum.
Task 2: Create the VM¶
Scenario: You must create a VM for RHEL practice that follows common lab sizing.
Requirements:
- Create a new VM from the ISO.
- Choose the guest OS type that fits the RHEL version you downloaded.
- Name it
<yourname>-vmand store its files in a dedicated folder. - Use 2 processors, 2 GB of memory (or 4 GB if your host allows), and a 20 GB virtual disk stored as a single file.
- Power the VM on so the installer's boot menu appears.
Hints:
- RHEL 10 may not appear in the hypervisor's list. Use the generic 64-bit option if so.
- Look for the hardware customization option before finishing the wizard.
Success criteria: The VM boots to the RHEL installer menu, and the VM's settings show 2 processors and a 20 GB disk.
Task 3: Install RHEL¶
Scenario: The VM needs a working RHEL installation with both an administrative and a regular account.
Requirements:
- Use the language of your choice.
- Select the Server with GUI software environment.
- Install to the virtual disk.
- Enable the root account and give it a password.
- Create a regular user. If the installer offers to make the user an administrator, enable it.
- Complete the installation, reboot, and log in.
Hints:
- The installer asks for confirmation (pressing Done twice) when a password is weak.
- The installation can take 30 to 45 minutes. Do not interrupt it.
Success criteria: After reboot you can log in as your regular user and open a terminal. cat /etc/os-release shows Red Hat Enterprise Linux.
Task 4: Discover the VM's network identity¶
Scenario: You need the VM's address and hostname so that other tools can reach it.
Requirements:
- Find the VM's IP address using two different commands.
- Find the VM's hostname.
- Confirm that the SSH service is running and enabled to start at boot.
- Write the IP address, hostname, and service state in a file named
~/vm-info.txt.
Hints:
- One command is short and prints only addresses. The other shows interfaces in detail.
systemctlcan report both the active state and whether a unit is enabled.
Success criteria: cat ~/vm-info.txt lists the address, hostname, and the SSH service's status, and the values match fresh command output.
Task 5: Connect with SSH¶
Scenario: The VM console is slow, and you want to administer the VM from your computer's terminal.
Requirements:
- From PowerShell (or PuTTY) on your host, log in to the VM as your regular user using SSH.
- Verify that the host key prompt appears on the first connection, and accept it only after confirming that the address is your VM's.
- Inside the SSH session, run a command that proves you are on the VM, and run one that proves who you are.
- Disconnect cleanly.
Hints:
- The command needs a user name and an address.
- The
exitcommand ends a session.
Success criteria: Your host terminal shows the VM's prompt, and the commands you ran report the VM's OS and your user name.
Task 6: Allow root password login (practice VM only)¶
Scenario: For lab convenience, you want to log in as root over SSH with a password. You must make the change safely and reversibly.
Requirements:
- Create a backup of the SSH server configuration before changing it.
- Configure the server so that root can log in with a password.
- Validate the configuration syntax before restarting.
- Confirm the effective settings, not just the file contents.
- Restart the service and log in as root from your host.
- Leave a regular-user session open while you test.
Hints:
- Two options matter. Search for their names rather than counting lines.
- A drop-in directory under
/etc/ssh/can override settings in the main file.
Success criteria: The effective settings show root login and password authentication allowed, and a root SSH login succeeds.
Task 7: Restore the secure default¶
Scenario: Your lab work is done for the day, and you want to return the SSH server to its original configuration.
Requirements:
- Restore the SSH configuration from the backup you made in Task 6.
- Validate the restored file.
- Restart the service.
- Confirm that root password login no longer works, and that your regular user still can log in.
Hints:
- Test both logins from a new terminal window so that you do not rely on an already-open session.
Success criteria: The effective settings no longer allow root password login (the effective value matches what you recorded before Task 6), the root login attempt is rejected, and the regular user login works.
Task 8: Create a safe baseline¶
Scenario: You want to be able to return to a clean, working VM quickly after experiments.
Requirements:
- Using your hypervisor, take a snapshot of the VM with a descriptive name.
- Make a harmless change inside the VM (for example, create a directory in your home).
- Restore the snapshot.
- Confirm the change is gone.
Hints:
- Snapshots are a hypervisor feature. Look for a Snapshot menu or manager.
- Power the VM on again after restoring if needed.
Success criteria: After the restore, the directory you created no longer exists.
4. Troubleshooting Challenges¶
All challenges are for your disposable VM. Take a snapshot first (Task 8).
Challenge A: The service that will not start¶
Setup: As root or with sudo, add a deliberately invalid line to /etc/ssh/sshd_config. For example, set PermitRootLogin to a value that is not valid, such as the misspelled yse. Do not restart sshd yet.
Your job:
- Use the proper tool to find the error before restarting.
- Identify the line that causes it.
- Fix the line.
- Validate again, then restart the service and confirm it is running.
Success criteria: The validation command reports the problem before the restart, and after the fix the service runs and you can connect.
Challenge B: The connection that times out¶
Setup: Power off the VM, then try to connect from your host.
Your job: List the checks you would perform, in order, to find out why the connection fails. Then power the VM on and connect.
Success criteria: Your list includes confirming the VM is running, confirming the IP address (which might have changed), and confirming that the network adapter is connected.
Challenge C: The host key warning¶
Setup: Reinstall the VM, or restore an older snapshot, and reconnect to the same IP address.
Your job: Explain what the warning means, decide whether it is expected in this case, and fix it.
Success criteria: You removed the outdated saved host key for that address (only after confirming the change is expected), and the connection works.
Challenge D: The setting that will not stick¶
Setup: Create a file in /etc/ssh/sshd_config.d/ that sets PermitRootLogin to a different value than the main file.
Your job: Determine which value is in effect and why. Remove your test file and confirm the effective value changes.
Success criteria: You identified the effective value with the proper command and explained which file wins.
5. Final Practical Challenge¶
Scenario: You are handing your practice VM to a study partner who will connect from their own computer. The VM must be reachable and reasonably safe.
Requirements:
- Take a snapshot named for the starting state.
- Confirm the SSH service is running and enabled at boot.
- Confirm the firewall allows SSH, without disabling the firewall. If SSH is missing from the allowed services, add it permanently.
- Confirm that your regular user can log in over SSH from your host and can run an administrative command through
sudo. - Confirm that root password login is not allowed.
- Review the SSH service's recent log entries and note one successful login event.
- Write a short handover file,
~/handover.txt, that contains the VM's IP address, the user name to use, the effective values ofPermitRootLoginandPasswordAuthentication, and one sentence on why root password login is disabled.
You must choose the commands yourself. Do not copy commands from the notes without understanding their output.
Success criteria: Each statement in the handover file matches what the system reports when you check it again.
6. Verification Checklist¶
- [ ] The hypervisor is installed and the ISO checksum matches.
- [ ] The VM has 2 processors, 2 to 4 GB of memory, and a 20 GB disk.
- [ ] RHEL is installed and I can log in as a regular user.
- [ ] I found the VM's IP address with two commands.
- [ ]
sshdis running and enabled at boot. - [ ] I connected over SSH from my host as a regular user.
- [ ] I backed up
sshd_configbefore changing it. - [ ] I validated with
sshd -tbefore every restart. - [ ] I confirmed effective settings with
sshd -T. - [ ] I restored the original SSH configuration and verified it.
- [ ] I took and restored a snapshot.
- [ ] I completed Challenges A to D.
- [ ] My
handover.txtmatches current system state. - [ ] I did not disable SELinux or the firewall at any point.
7. Solutions and Answer Key¶
Try the tasks before reading this section. Output varies by system, so the expected results describe what to look for rather than exact text. Replace placeholders such as
<IP-address>with your own values.
Task 1 solution¶
Approach: Install the tools, download, and check integrity before using the file.
- Install VMware Workstation (or VirtualBox). If the installer offers Change, Repair, or Remove for an old version, remove the old version and install the new one.
- Download the ISO from your Red Hat account.
- Calculate the checksum in PowerShell:
powershell Get-FileHash .\<iso-file-name>.iso -Algorithm SHA256 - Compare the result with the checksum shown on the download page.
Verification: The two values are identical. If not, download the file again.
Task 2 solution¶
- Create a New Virtual Machine, then choose Installer disc image file (ISO) and select your ISO.
- Guest OS: Other / Other 64-bit for RHEL 10 (or Linux / RHEL 9 64-bit for RHEL 9).
- Name:
<yourname>-vm. Location: a dedicated folder. - Disk: 20 GB, store as a single file.
- Customize Hardware: memory 2048 MB (or 4096 MB), processors 2.
- Close, Finish, then Play virtual machine.
Verification: The installer menu appears, and the VM's settings list the chosen values.
Rollback: Delete the VM from the hypervisor and recreate it with different settings.
Task 3 solution¶
- Choose Install Red Hat Enterprise Linux and press Enter.
- Select a language and continue.
- Software Selection: Server with GUI.
- Installation Destination: select the virtual disk, Done.
- Root Account: enable, set a password, Done (twice if warned).
- User Creation: create the user and password, enable the administrator option if offered, Done.
- Begin Installation, wait, then Reboot.
Verification:
cat /etc/os-release
whoami
/etc/os-release shows Red Hat Enterprise Linux, and whoami shows your user name.
Task 4 solution¶
hostname -I
ip addr
hostname
systemctl is-active sshd
systemctl is-enabled sshd
Create the file:
{ echo "IP:"; hostname -I; echo "Hostname:"; hostname; echo "sshd active:"; systemctl is-active sshd; echo "sshd enabled:"; systemctl is-enabled sshd; } > ~/vm-info.txt
cat ~/vm-info.txt
Explanation: hostname -I prints addresses only. ip addr shows interfaces and their state. systemctl is-active and is-enabled print one-word states that are easy to record.
If sshd is not running or not enabled:
sudo systemctl enable --now sshd
Verification: Re-run the commands and compare them with the file.
Task 5 solution¶
From PowerShell on the host:
ssh <user>@<IP-address>
On the host-key prompt, confirm the address is your VM's, then type yes. Enter the password.
Inside the session:
cat /etc/os-release
whoami
exit
Verification: The prompt shows the VM's hostname, and the commands report RHEL and your user name.
If it fails: Check that the VM is running, that the IP is correct, and that sshd is running (see Task 4).
Task 6 solution¶
Approach: Back up, edit, validate, check the effective values, restart, test.
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
sudo sshd -T | grep -Ei 'permitrootlogin|passwordauthentication' # record the "before" values
sudo vim /etc/ssh/sshd_config
In Vim, search with /PermitRootLogin. Set (removing any #):
PermitRootLogin yes
PasswordAuthentication yes
Save with :wq, then:
sudo grep -ri 'permitrootlogin\|passwordauthentication' /etc/ssh/sshd_config.d/
sudo sshd -t
sudo sshd -T | grep -Ei 'permitrootlogin|passwordauthentication'
sudo systemctl restart sshd
If a file in sshd_config.d/ sets different values, edit that file as well, because the first value read wins.
From the host, in a new terminal:
ssh root@<IP-address>
Verification: sshd -T shows permitrootlogin yes and passwordauthentication yes, and the root login succeeds.
Rollback: See Task 7.
Task 7 solution¶
sudo cp /etc/ssh/sshd_config.bak /etc/ssh/sshd_config
sudo sshd -t
sudo systemctl restart sshd
sudo sshd -T | grep -Ei 'permitrootlogin|passwordauthentication'
From a new host terminal:
ssh root@<IP-address> # expected: rejected
ssh <user>@<IP-address> # expected: succeeds
Explanation: Restoring the backup puts the file back as it was. Validating before the restart avoids a failed service, and testing from new terminals proves the new state, not the old sessions.
Verification: The effective values match what you recorded before Task 6. If a drop-in file you edited in Task 6 was changed, restore or correct it too.
Task 8 solution¶
- In the hypervisor, open the Snapshot menu and take a snapshot with a descriptive name, such as
clean-install. - In the VM:
mkdir ~/snapshot-test. - In the hypervisor, restore the snapshot.
- Power the VM on and run
ls ~.
Verification: snapshot-test is not listed.
Challenge A solution¶
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak2
sudo vim /etc/ssh/sshd_config # add the invalid value
sudo sshd -t # reports an error and a line number
The message points to the line with the invalid value (the exact text varies). Correct it to a valid value, such as no, yes, or prohibit-password, then:
sudo sshd -t
sudo systemctl restart sshd
systemctl status sshd
Explanation: sshd -t catches syntax problems before a restart could leave the service stopped. Never restart before validating.
Verification: sshd -t prints nothing, the service is active, and you can connect.
Challenge B solution¶
Checks, in order: (1) the VM is powered on and finished booting; (2) the IP address inside the VM, using hostname -I (it may have changed); (3) the VM's network adapter is connected in the hypervisor; (4) sshd is running; (5) the firewall allows the ssh service. After powering on, connect with the current IP.
Challenge C solution¶
Meaning: The address now presents a different host key than the one saved in ~/.ssh/known_hosts. That is expected after a reinstall or a snapshot restore to a state with different keys, but it can also indicate that a different machine answers at that address, so confirm the change is expected first.
ssh-keygen -R <IP-address>
ssh <user>@<IP-address>
Accept the new host key after confirming.
Challenge D solution¶
sudo grep -ri permitrootlogin /etc/ssh/sshd_config /etc/ssh/sshd_config.d/
sudo sshd -T | grep -i permitrootlogin
sshd -T shows the effective value. Because the main file normally includes the drop-in directory near the top and the first value read wins, the drop-in's value takes precedence. Remove the test file:
sudo rm /etc/ssh/sshd_config.d/<your-test-file>
sudo sshd -t
sudo systemctl restart sshd
sudo sshd -T | grep -i permitrootlogin
Warning: Delete only the test file you created.
Verification: The effective value returns to the main file's setting.
Final practical challenge solution¶
sudo systemctl is-active sshd
sudo systemctl is-enabled sshd
sudo firewall-cmd --list-services
If ssh is missing from the list:
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
From the host:
ssh <user>@<IP-address>
sudo whoami # expected: root
Confirm root password login is blocked:
sudo sshd -T | grep -Ei 'permitrootlogin|passwordauthentication'
ssh root@<IP-address> # from a host terminal; expected: rejected
Review the logs:
sudo journalctl -u sshd --since "30 minutes ago"
Look for an entry that records a successful login for your user.
Write the handover file:
{ echo "IP: $(hostname -I)"; echo "User: <your-user>"; sudo sshd -T | grep -Ei 'permitrootlogin|passwordauthentication'; echo "Root password login is disabled because root is the most targeted account; use a regular user with sudo."; } > ~/handover.txt
cat ~/handover.txt
Explanation: The firewall is checked, never disabled. Using --permanent keeps the rule after a reboot, and --reload applies it now. sudo whoami proves that your user has administrative rights without needing root login.
Verification: Re-run each check and compare it with the file.
Cleanup: If the VM is handed over, remove practice files you no longer need, and only those you created: rm ~/vm-info.txt ~/handover.txt.
8. Extended Practice Drills¶
Short, independent drills for repeated practice. Do them in order or jump to the group you need. Work only inside your lab directory, read each drill carefully, and check your result with a command before looking at the answer list in section 9.
Setup (run once):
mkdir -p ~/day2-lab && cd ~/day2-lab
A. VM and hypervisor concepts¶
- Define hypervisor, host, guest, and virtual machine.
- Why build your own VM when a hosted lab exists?
- What is an ISO image and why is it used?
- Why verify an ISO checksum?
- In PowerShell, which command calculates a file's SHA-256 hash?
- Which guest OS type did the notes use for RHEL 10 in VMware?
- State the lab VM sizing used: processors, memory, disk.
- What problem can a too-small disk cause?
- Which software selection is easier for learners, and which is more common on servers?
- Why is the simple lab password acceptable only on a private VM?
- What is a snapshot and what is it not?
B. Network identity¶
- Show the VM's IP addresses (short form).
- Show interfaces and addresses in detail.
- Show a brief one-line-per-interface summary.
- Show the hostname with two commands.
- Confirm you are on RHEL.
- Test that the VM can reach another address of your choice (4 packets).
C. The SSH service¶
- Show the status of the SSH service.
- Print only whether sshd is active.
- Print only whether sshd is enabled at boot.
- Start sshd now and enable it at boot with one command.
- Show which TCP port sshd listens on.
- Show which services the firewall allows.
- Allow SSH permanently if it is missing, without disabling the firewall.
- Show recent sshd log entries.
- Show only sshd log entries from the last 10 minutes.
D. The SSH client¶
- Connect from your host to the VM as your regular user.
- Inside the session, prove you are on the VM and show who you are.
- End the SSH session.
- Connect with verbose output to see the connection steps.
- Explain the host key prompt on first connection.
- View the saved host keys on your computer.
- Remove a stale host key after confirming the VM was reinstalled.
- Run a single command remotely without an interactive session.
- Check who is currently logged in.
- Show recent logins.
E. SSH server configuration (practice VM only)¶
- Back up the SSH configuration.
- Find the lines mentioning root login and password authentication.
- List additional configuration snippets.
- Search the snippet directory for the same settings.
- Validate the configuration syntax.
- Show the effective values of both settings.
- Explain why a drop-in file can override the main file.
- Apply a configuration change.
- Restore the backup and apply it.
- Why keep an existing session open while testing SSH changes?
- List the four
PermitRootLoginvalues and their meaning.
F. Troubleshooting¶
sshtimes out. List the checks in order.sshsays connection refused. What is the likely cause and fix?sshsays permission denied for root. What are two causes?sshwarns that the remote host identification changed. Cause and fix?- An
sshd_configedit has no effect after restart. List two causes. hostname -Iprints nothing. What do you check?- Installer fails at destination. Likely cause and fix?
- Write the IP, hostname, sshd state, and effective root login setting into
~/day2-lab/vm-info.txt.
9. Drill Answer Key¶
Answers show one valid approach. Output varies by system, so compare the meaning of your output, not exact text. Commands marked with
sudoneed elevated privileges.
A. VM and hypervisor concepts¶
- Hypervisor: software that runs VMs. Host: the physical computer. Guest: the OS inside the VM. VM: the simulated computer.
- No time limit, can be reset or restored, and allows extra experiments.
- A disk image of installation media. It is attached to the VM as a virtual DVD, so no physical disc is needed.
- To confirm the download is complete and not corrupted or tampered with.
Get-FileHash .\<file>.iso -Algorithm SHA256- Other, version Other 64-bit (use RHEL 10 if your VMware lists it).
- 2 processors, 2 GB (or 4 GB) memory, 20 GB disk as a single file. Verify against Red Hat's official requirements.
- The installer can fail at the installation destination step.
- Server with GUI for learning. Server (no GUI) is common on production servers.
- Simple passwords are easy to guess. On shared or exposed systems they would be a serious weakness.
- A hypervisor feature that saves a VM's state so you can restore it. It is not a RHEL feature and not a full backup.
B. Network identity¶
hostname -Iip addrip -br addrhostnameandhostnamectlcat /etc/os-releaseping -c 4 <address>
C. The SSH service¶
systemctl status sshdsystemctl is-active sshdsystemctl is-enabled sshdsudo systemctl enable --now sshdsudo ss -tlnp | grep sshd(default port is 22)sudo firewall-cmd --list-servicessudo firewall-cmd --permanent --add-service=sshthensudo firewall-cmd --reloadsudo journalctl -u sshdsudo journalctl -u sshd --since "10 minutes ago"
D. The SSH client¶
ssh <user>@<IP-address>cat /etc/os-releaseandwhoamiexitssh -v <user>@<IP-address>- The client shows the server's fingerprint. Accept (
yes) only if you expect this server. It is then saved in~/.ssh/known_hosts. cat ~/.ssh/known_hostsssh-keygen -R <IP-address>ssh <user>@<IP-address> hostnamewholast | head
E. SSH server configuration (practice VM only)¶
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.baksudo grep -Ei 'permitrootlogin|passwordauthentication' /etc/ssh/sshd_configls -l /etc/ssh/sshd_config.d/sudo grep -ri 'permitrootlogin\|passwordauthentication' /etc/ssh/sshd_config.d/sudo sshd -t(no output means valid)sudo sshd -T | grep -Ei 'permitrootlogin|passwordauthentication'- For most settings the first value read wins, and the drop-in directory is included near the top. Always confirm with
sshd -T. sudo systemctl restart sshd(aftersudo sshd -tpasses)sudo cp /etc/ssh/sshd_config.bak /etc/ssh/sshd_config,sudo sshd -t,sudo systemctl restart sshd- A mistake could lock you out. The open session lets you fix the file.
yes(password or key),prohibit-password(key only),forced-commands-only(key, specific commands),no(never).
F. Troubleshooting¶
- VM running, correct and current IP, network adapter connected, sshd running, firewall allows ssh.
- sshd not running.
sudo systemctl enable --now sshd. - Root password login is not allowed, or the password was mistyped.
- The host key at that address changed (for example after reinstall). Confirm it is expected, then
ssh-keygen -R <IP>. - A drop-in file overrides it, or the service was not restarted. Check
sudo sshd -T. ip addrand the VM network adapter settings in the hypervisor.- Virtual disk too small. Recreate the VM with a 20 GB disk.
- Combine
hostname -I,hostname,systemctl is-active sshd, and thesshd -T | grepcommand, redirecting with>and then>>.