Lesson 017 · Linux Administration Learning Path

RHEL SSH Administration and Secure Remote Access

· Published · 8 min read

Labelled RHEL path showing verified SSH host identity user key or certificate policy bastion session evidence and lockout-safe recovery

SSH protects a connection only when both sides make trustworthy identity decisions. A client that accepts an unexplained host-key change loses server authentication. A server that accepts a copied private key from many people loses individual attribution. Secure administration combines verified host identity, named users, scoped authentication, least privilege, current cryptography, session evidence and a console-backed change procedure.

Separate server identity from user authentication

Host keys identify the server to clients. User public keys or certificates authenticate a principal to the server. They are different trust chains. Rebuilds, load-balanced endpoints and host certificates require an owned distribution method so clients can distinguish planned identity change from interception.

Agent and port forwarding extend trust across boundaries. Keep them disabled unless the workflow and destination are controlled. A bastion reduces exposed entry points but becomes a high-value identity and audit boundary.

Build an evidence map

LayerQuestion to answerEvidence
Server identityHow does the client verify this endpoint?Host-key fingerprint, CA or managed known_hosts
User identityWhich named principal authenticated?Account and key/certificate fingerprint
AuthorizationWhich source, command and privilege are allowed?sshd Match rules, authorized_keys options and sudo
PathDirect, ProxyJump or forwarded connection?Client config, bastion logs and destination evidence
RecoveryHow is bad policy reversed?Console, retained session and tested config backup

Operating sequence

  1. Inventory listeners, host keys, users, keys, bastions and automation dependencies.
  2. Back up exact configuration and retain console plus two privileged sessions.
  3. Validate a proposed drop-in with sshd -t and inspect effective values with sshd -T.
  4. Add one control at a time, preferably through a Match block with known scope.
  5. Reload rather than restart when supported, keeping the existing session open.
  6. Test new login, intended denial, sudo and automation from the real source.
  7. Remove superseded keys only after every owner and job has migrated.

Commands and expected evidence

ss -lntp | grep ':22'
sshd -t
sshd -T | grep -E '^(passwordauthentication|pubkeyauthentication|permitrootlogin|allowagentforwarding|allowtcpforwarding)'
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
ssh-keygen -lf ~/.ssh/authorized_keys
ssh -G host.example | grep -E '^(hostname|user|proxyjump|identityfile)'
ssh -o StrictHostKeyChecking=yes host.example
journalctl -u sshd --since '-30 minutes' --no-pager
  • Use sshd -T -C user=...,host=...,addr=... when Match rules depend on connection context.
  • Never print private-key material; fingerprints of approved public keys are adequate inventory evidence.
  • Strict host checking should fail an unrecognized change until identity is verified independently.
  • Reload only after syntax passes and the recovery session remains usable.

Evidence and acceptance criteria

EvidenceHealthy resultFailure meaning
Host identityFingerprint/CA matches inventory through trusted channelPossible interception, wrong host or unmanaged rebuild
Effective policyContext-specific sshd output matches designInclude/Match ordering differs from file reading
AuthenticationNamed user and approved key/cert fingerprint succeedWrong account, key, permissions or policy
DenialPassword/root/unapproved source behavior fails as intendedUnintended fallback remains
RecoveryConsole and retained session restore known configPolicy mistake can strand the host

Worked operating scenario

After a rebuild, automation reports a host-key mismatch. Deleting the known-host entry would restore connectivity but erase the only warning that server identity changed. The operator checks the rebuild record and console-displayed fingerprint through a trusted inventory path, then updates the centrally managed host identity.

The old fingerprint is retained in the change record. Automation resumes only after strict verification, and no user is told to disable host-key checking.

Practical how-to cases

Case 1: Create and install a user key

Generate a modern key with a passphrase and install only its public half. Keep console and a second authenticated session until syntax, new login and intended denial all pass.

ssh-keygen -t ed25519 -a 64 -f ~/.ssh/id_ed25519_lab
ssh-copy-id -i ~/.ssh/id_ed25519_lab.pub student@servera
ssh-keygen -lf ~/.ssh/id_ed25519_lab.pub
ssh -i ~/.ssh/id_ed25519_lab student@servera
CheckpointWhat to establish
Expected resultThe server authenticates the intended account and the private key never leaves the client.
If it failsPermission or label errors on .ssh and authorized_keys can make a correct key unusable.
Safe recoveryRestore the saved sshd drop-in from console, validate with sshd -t, restart the service, and reconcile the verified host fingerprint.

Case 2: Harden with a drop-in

Disable root and password login only after key access succeeds in another session. Keep console and a second authenticated session until syntax, new login and intended denial all pass.

printf '%s\n' 'PermitRootLogin no' 'PasswordAuthentication no' | sudo tee /etc/ssh/sshd_config.d/40-site-policy.conf
sudo sshd -t
sudo sshd -T | grep -E 'permitrootlogin|passwordauthentication'
sudo systemctl reload sshd
CheckpointWhat to establish
Expected resultEffective configuration reports both controls and a fresh key login works.
If it failsA Match block or lexically earlier file can alter effective values; inspect sshd -T in context.
Safe recoveryRestore the saved sshd drop-in from console, validate with sshd -t, restart the service, and reconcile the verified host fingerprint.

Case 3: Use a bastion

Define ProxyJump and prove final host identity remains independently verified. Keep console and a second authenticated session until syntax, new login and intended denial all pass.

ssh -J [email protected] [email protected]
ssh -G serverb.example.test | grep -E 'hostname|user|proxyjump|identityfile'
ssh-keyscan -t ed25519 serverb.example.test
CheckpointWhat to establish
Expected resultTraffic traverses the bastion while serverb authentication and host-key checking remain end to end.
If it failsssh-keyscan collects a key but does not authenticate it; compare through a trusted inventory path.
Safe recoveryRestore the saved sshd drop-in from console, validate with sshd -t, restart the service, and reconcile the verified host fingerprint.

Case 4: Diagnose authentication

Run a verbose client attempt and correlate the server journal without weakening policy. Keep console and a second authenticated session until syntax, new login and intended denial all pass.

ssh -vvv student@servera
sudo journalctl -u sshd --since '-10 minutes' --no-pager
sudo sshd -T -C user=student,host=servera,addr=192.0.2.50
namei -om /home/student/.ssh/authorized_keys
ls -ldZ /home/student/.ssh /home/student/.ssh/authorized_keys
CheckpointWhat to establish
Expected resultClient offer, server decision, file traversal and SELinux evidence identify the rejection.
If it failsEnabling passwords or root login hides the cause and expands attack surface.
Safe recoveryRestore the saved sshd drop-in from console, validate with sshd -t, restart the service, and reconcile the verified host fingerprint.

Case 5: Transfer files securely

Use scp or sftp with strict host-key checking and verify the received digest. Keep console and a second authenticated session until syntax, new login and intended denial all pass.

sha256sum package.tar.gz
scp -o StrictHostKeyChecking=yes package.tar.gz student@servera:/tmp/
ssh student@servera 'sha256sum /tmp/package.tar.gz'
sftp -b batch.txt student@servera
CheckpointWhat to establish
Expected resultThe local and remote SHA-256 values match and the verified server identity is used.
If it failsEncryption does not prove the file is complete or sent to the intended host when host identity is ignored.
Safe recoveryRestore the saved sshd drop-in from console, validate with sshd -t, restart the service, and reconcile the verified host fingerprint.

Independent practice tasks

  1. Configure key-only access and prove password rejection.
  2. Use Match Address for a lab subnet and inspect contextual output.
  3. Configure local and remote forwarding, then state the exposure risk.
  4. Recover from an invalid sshd drop-in through console.

For this lesson on RHEL SSH Administration, complete each task without copying the worked command sequence. Record the initial state, exact change, verification, negative test and recovery command. A task is unfinished if it works now but does not survive a reboot where persistence is required.

Troubleshooting by symptom

SymptomInspect firstDefensible next action
Permission denied publickeyAccount, offered fingerprint, file modes and effective policyCorrect exact key/account or Match rule
Host-key changedInventory, rebuild/change and console fingerprintVerify identity before updating trust
Config test passes, login failsContext-specific sshd -T -C, PAM and journalDiagnose actual source/user path
ProxyJump failsEach hop identity, forwarding policy and destination DNSTest and verify hops separately
Existing session works, new failsDo not close recovery session; inspect latest journal/policyRestore reviewed drop-in or correct bounded rule

Unsafe operations and recovery boundaries

  • Unsafe: disabling host-key verification permits silent redirection or interception.
  • Unsafe: replacing sshd configuration remotely without console and retained sessions can lock out every operator.
  • Unsafe: shared private keys and unrestricted agent forwarding expand impersonation across hosts.

Rewritten knowledge checks

What does an SSH host key authenticate?
The server endpoint to the client.
What does a user public key authenticate?
Control of the corresponding private key for a user authorization entry.
Why use <code>sshd -T</code>?
It prints effective configuration after defaults and includes; -C evaluates Match context.
Should a host-key warning be deleted automatically?
No. Verify the planned identity change independently first.
What is ProxyJump?
A client route through an SSH bastion to the destination without copying a private key to the bastion.
Why restrict forwarding?
It can turn a session into a path to other networks or credentials.
Why reload with an existing session retained?
The session provides recovery while new authentication is tested.
What proves hardening works?
Approved login succeeds, intended fallbacks and sources fail, privilege works narrowly and evidence is attributable.

Guided lab and acceptance test

  1. Record lab server host-key fingerprints at the console.
  2. Create a named lab user and a new protected key pair; install only the public key.
  3. Verify strict host checking and record the accepted fingerprint.
  4. Add a scoped sshd drop-in, validate and reload while retaining one session.
  5. Test approved login plus password/root denial.
  6. Remove the lab key/account only after checking files, jobs and sessions.

Primary references

Advertisement