All articles

Debug an SSH Connection with Verbose Client Output

6 minutes read


Linux publication

Share this article

𝕏✉

Illustration for Debug an SSH Connection with Verbose Client Output

ssh: connect to host ... port 22: Connection timed out and Permission denied (publickey) happen at different stages. Treating both as an SSH server problem wastes time and can damage a working configuration.

Start with the client configuration that SSH actually resolved, then make one bounded connection attempt.

Expand configuration without connecting

ssh -G production |
  sed -n '/^\(hostname\|user\|port\|identityfile\|proxycommand\|proxyjump\|stricthostkeychecking\) /p'

ssh -G prints the configuration after evaluating command-line options, ~/.ssh/config, system configuration, Host patterns, and canonicalization rules 1. It does not open a network connection.

Compare with a clean configuration when aliases or wildcards are suspect:

ssh -G -F /dev/null \
  -o User=deploy -o Port=22 example.com |
  sed -n '/^\(hostname\|user\|port\|identityfile\) /p'

The result identifies hidden ProxyJump, unexpected users, nonstandard ports, and identity files selected by broad Host * blocks. The configuration keywords and precedence are documented in ssh_config(5) 2.

Make one bounded verbose attempt

Caution: Verbose output can expose usernames, internal hostnames, proxy routes, identity-file paths, and authentication methods. Redact it before sharing. The command below creates network traffic and may trigger security monitoring or authentication rate limits.

ssh -vvv \
  -o ConnectTimeout=10 \
  -o ConnectionAttempts=1 \
  -o NumberOfPasswordPrompts=0 \
  production true

Read the log in stages:

Last useful line Investigate
resolving hostname DNS, spelling, search domains
connecting to address route, firewall, port, listener
remote protocol version SSH transport reached the server
host key verification known-host entry and expected fingerprint
offering public key selected key, agent, server authorization
authenticated to remote command or session startup

-v, -vv, and -vvv increase debug detail. A failed connection still returns a nonzero status; capture it with the log.

Check the host key deliberately

Inspect existing entries:

ssh-keygen -F production
ssh-keygen -F 192.0.2.10

A changed host-key warning protects against both legitimate rebuilds and interception. Verify the new fingerprint through an independent administrative channel before replacing an entry.

Do not delete the entire known_hosts file to silence one mismatch. Hashed host entries and aliases can make the relevant line less obvious, which is why ssh-keygen -F is useful.

See which keys the agent holds

ssh-add -l

Then constrain one test to one identity:

ssh -vv \
  -o IdentitiesOnly=yes \
  -i "$HOME/.ssh/id_ed25519" \
  production true

IdentitiesOnly=yes prevents additional agent identities from filling the server’s authentication-attempt limit. It does not prove that the selected public key is present in the target account’s authorized_keys.

Keep client and server evidence separate

Client output proves what this machine attempted. Server logs explain why the daemon accepted or rejected it. When you administer both ends, line up the same timestamp, source address, target account, and connection attempt.

Record the effective hostname, port, proxy path, host-key fingerprint, offered identity, final debug stage, and exit status. Change configuration only after one of those values identifies the mismatch.

Sources and further reading
  1. OpenBSD ssh(1) manual
  2. OpenBSD ssh_config(5) manual