SSH and mandatory access denials
Quick answer
An SSH authentication failure and a mandatory access denial require different investigations. Preserve server identity verification and enforcement during troubleshooting.
First determine whether host identity, user authentication or authorization failed. If mandatory policy is involved, correlate the denial with the intended identity and resource. Preserve enforcement and avoid making unrelated permission changes as a diagnostic shortcut.
Prepare the practice environment
Run python3 lab-fixtures/troubleshooting/setup.py from the extracted root as an ordinary user. Enter the printed fresh private path and check pwd. Use fresh fixtures, Bash with set -e -o pipefail, LC_ALL=C and umask 077. Run each snippet in a separate Bash process, not your interactive shell. Only private files are used; optional examples require an authorized snapshot VM. Do not change live services, mounts, policies or resource limits. All supplied records are fictional; no host incident records are collected. Review the lab guide.
Prerequisites
Review: DNS, connection and TLS failures.
How it works
For SSH, confirm the intended hostname and trusted host fingerprint before diagnosing user authentication. Check the account, selected identity, key ownership and mode; private key files must be protected from other users. The server may reject authorized_keys when ownership or directory modes violate its policy. Use ssh -G to inspect client options and authorized server logs to inspect authentication; do not copy secrets into logs. A host-key change needs independent verification, not blind removal. SELinux can deny access even when Unix mode permits it; inspect the expected label and source and target context in a relevant AVC record. AppArmor uses profiles and can deny a path operation. In an approved VM compare the expected label with ls -Z and restorecon -n for preview, or inspect the intended profile. Correct the specific label, ownership or approved policy only after understanding the legitimate access. Preserve console access and the previous configuration, retest as the intended user, and revert if readiness fails. Prevent recurrence by checking mode, labels and identity at deployment. All supplied logs and key-like files are fictional.
Try the examples
grep -F 'bad ownership or modes' ssh.sampleInvestigate parent directory ownership and mode; this is not a host-key mismatch.
Expected stdout:
Authentication refused: bad ownership or modes for directory /home/learnerThis models restrictive permissions using text that is not a key. It does not run SSH.
Expected stdout:
644 is too broad; 600 verified on private copyCheck whether the expected resource label is correct before proposing a policy change. Do not disable enforcement.
Expected stdout:
avc: denied { read } scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:default_t:s0 tclass=fileCommon mistakes
Never use a real private key as a fixture or turn off host verification, SELinux or AppArmor as a generic fix.
Practice
Explain the authentication diagnostic and identify the source domain, target type and operation in the AVC. Propose a minimal approved correction and verification without disabling security.
Related references
Study: ssh, journalctl, ausearch. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
SSH and mandatory access denials — Knowledge Check
Apply troubleshooting concepts to synthetic fixtures and VM-only scenarios.
What should precede trusting a changed host key?
What mode protects a typical private key owned by the user?
Can SELinux deny a read allowed by Unix file modes?
What is the initial response to an unexpected SELinux denial?