Skip to content

Troubleshoot Linux SSH Connection and Permission Denied Errors

Admin
November 18, 2026
5 min read
Intermediate
💻 Target OS: Ubuntu 24.04+ / Debian 12+ / RHEL 9+

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
Guide tools
0/0 Steps (0%)

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

01

Read the client’s connection trace

Client

Replace 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.

Terminal window
ssh -G [email protected] | grep -E '^(hostname|user|port|identityfile) '
ssh -vv -o ConnectTimeout=5 -o ConnectionAttempts=1 [email protected]
02

Check the listener and correlate server logs

Server

Use 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.

Terminal window
# Ubuntu
systemctl status ssh.service ssh.socket --no-pager
sudo journalctl -u ssh.service -u ssh.socket --since '15 minutes ago' --no-pager
# RHEL
systemctl status sshd.service --no-pager
sudo journalctl -u sshd.service --since '15 minutes ago' --no-pager
sudo ss -ltnp 'sport = :22'
03

Inspect the user’s authorized key path

Authentication

Run 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.

Terminal window
getent passwd ops
sudo namei -l /home/ops/.ssh/authorized_keys
sudo ssh-keygen -lf /home/ops/.ssh/authorized_keys
sudo sshd -t
04

Verify a fresh connection

Verification

Correct 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.

Terminal window
ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519 [email protected] 'id -un; hostname'

References

Comments