Troubleshoot Linux SSH Connection and Permission Denied Errors
Before you begin
- Applies to:Ubuntu 26.04 LTS and RHEL 10 with OpenSSH and systemd.
- Where to start:Start in the client terminal using the affected account. Keep a working server session or console available for server-side checks.
- What you need:Have the actual username, hostname, port, and intended key. Server inspection requires authorized sudo access.
Guide tools
Start with the exact error. A timeout or refusal occurs before authentication. Permission denied means the server was reached and rejected the login. A host key warning requires independent verification of server identity before continuing.
Before You Start
Ubuntu 26.04 LTS and RHEL 10 with OpenSSH and systemd. Use a regular client account for connection checks and authorized sudo access on the server. Have console access or keep a working administrative session open. Replace example account names, paths, hostnames, ports and service names with your own values. Run the steps in order, using the same shell for blocks that share variables.
Troubleshooting Steps
Read the client’s connection trace
ClientReplace the example username and hostname. Use the same alias and port as the failing connection. The last lines before failure identify whether it stopped at DNS, TCP, host verification, or user authentication. Use ssh -G to inspect client configuration without connecting.
What you should see · The trace identifies the destination and shows whether it reaches user authentication.
If you see something else · For a timeout or refusal, check the server listener in Step 2. For a host-key mismatch, verify the fingerprint with the server owner before proceeding. For a public-key rejection, correlate the server log and continue to Step 3.
Check the listener and correlate server logs
ServerUse the pair for your distribution. Check that the expected address and port appear in the listener list. Ubuntu can use ssh.socket for activation, so check whether that unit owns the listener. If there is a listener but the client times out, review the route, approved firewall scope and any cloud firewall. If the server logs the attempt, focus on authentication.
# Ubuntusystemctl status ssh.service ssh.socket --no-pagersudo journalctl -u ssh.service -u ssh.socket --since '15 minutes ago' --no-pager
# RHELsystemctl status sshd.service --no-pagersudo journalctl -u sshd.service --since '15 minutes ago' --no-pager
sudo ss -ltnp 'sport = :22'Inspect the user’s authorized key path
AuthenticationRun on the server using the real account and its actual home directory. Compare the offered public key fingerprint with the approved key and inspect the whole path for unexpected writable directories. If AuthorizedKeysFile is overridden, inspect that path instead. On RHEL with SELinux enabled, inspect labels and check audit records before correcting labels.
getent passwd opssudo namei -l /home/ops/.ssh/authorized_keyssudo ssh-keygen -lf /home/ops/.ssh/authorized_keyssudo sshd -tVerify a fresh connection
VerificationCorrect only the identified issue. Restore the prior SSH configuration if validation or a new connection fails. If changing server configuration, validate it before reloading the relevant ssh or sshd service through your maintenance procedure. For a key issue, test with the intended key. Confirm the username and hostname in the new session before closing console or fallback access.
References
Your feedback keeps these production procedures accurate and battle-tested.