CH-J Toolsserver management over SSH
Menu
All guides and articles →

Fix SSH connection refused, timeout and permission denied

Identify whether SSH fails at the port, network or authentication stage before changing server configuration.

What does each SSH error actually mean?

An SSH connection passes through several stages: resolving the destination, opening a TCP connection, negotiating SSH and checking the server identity, then authenticating your account. The last error tells you where to investigate. Changing a password cannot repair a connection that never reached authentication, and opening another firewall port cannot fix a rejected user key.

  • Connection refused: the connection attempt was actively rejected. Common causes are the wrong port, no listening service, or a firewall sending a rejection. The response need not come from the intended server.
  • Connection timed out: no usable response arrived before the deadline. Filtering, routing, a missing VPN, an incorrect address or an unresponsive endpoint can cause this.
  • Permission denied: SSH reached user authentication and the attempted credentials or permitted methods did not satisfy the server policy. Confirm that you reached the intended machine before changing credentials.

A host key warning or a no matching algorithm message belongs to another stage. Record the exact wording rather than grouping every failure under permission denied. Also record whether the problem affects one account, one client network, or everyone; that comparison often narrows the investigation immediately.

How do you collect useful evidence on the client?

The following commands use the OpenSSH client on Linux, macOS or Windows with OpenSSH installed. Replace user, server.example and port 22 with the actual account, destination and port. Run the first command once and inspect the final lines, plus the earlier line showing the address being contacted. ConnectTimeout limits connection establishment and the initial SSH handshake; it is not a general session timeout.

ssh -vvv -o ConnectTimeout=5 -p 22 user@server.example
ssh -G -p 22 user@server.example

The second command prints evaluated client settings without logging in. Check hostname, user, port, proxyjump, proxycommand and identityfile. A Host alias or a broad configuration rule can select a different destination or key than you expected. If a jump host is configured, establish which hop failed; a timeout at the bastion does not diagnose the final server.

Verbose logs can expose account names, addresses, local paths and public key fingerprints. Redact identifying details before sharing a relevant excerpt, and never include passwords or private key contents. Keep the destination, port and attempt time in your own incident notes so the administrator can correlate the request with server logs.

How do you investigate connection refused on the server?

Use the physical, hypervisor or provider console. On Ubuntu and Debian with systemd, inspect the SSH service, actual listening sockets, configuration syntax and recent journal entries. These are inspection commands; a service status command can return a nonzero exit status when the service is inactive.

sudo systemctl status ssh.service --no-pager
sudo ss -lntp
sudo /usr/sbin/sshd -t
sudo journalctl -u ssh.service -n 50 --no-pager

On RHEL and its derivatives, use sshd.service for the service and journal checks. Look for the configured TCP port and its listening address. A listener on 127.0.0.1 is available only locally. An IPv4 listener alone does not establish that IPv6 works. Compare the socket with the address and port from the client log rather than assuming everything uses port 22.

Some Ubuntu installations use ssh.socket for socket activation. Inspect that unit if it is present: an inactive ssh.service alone does not prove SSH is unavailable. Port changes may also require socket configuration changes, depending on the installation. Treat ss output as evidence of the current listener, while sshd_config describes intended daemon settings.

How do you distinguish a timeout from a DNS or network problem?

Compare IPv4 and IPv6 explicitly using the same account and port. If one succeeds, investigate the failing family: its DNS record, route, listener and firewall rules. Do not disable IPv6 across the server merely to hide a broken path. If the hostname resolves incorrectly, repair the record or client resolver configuration after confirming the intended address.

ssh -4 -o ConnectTimeout=5 -p 22 user@server.example
ssh -6 -o ConnectTimeout=5 -p 22 user@server.example

On a Windows client, PowerShell can test TCP reachability separately from SSH authentication. TcpTestSucceeded reports whether that TCP connection succeeded, not whether the server identity or login is valid. Use the actual SSH port if it differs from 22.

Test-NetConnection -ComputerName server.example -Port 22
  1. Confirm the required VPN and route are active. Compare a test from the approved management network with the failing location.
  2. Check the server firewall, provider security rules and any NAT port forwarding. Match the actual client source address, destination and TCP port; inspect return traffic restrictions too.
  3. If the listener exists but attempts leave no SSH log entry, investigate the path before authentication. Where authorized, packet capture at the server can distinguish missing requests from unanswered or lost replies.

Ping uses a different protocol and may be filtered independently. A ping reply does not prove SSH is reachable, and a missing reply does not prove the machine is off. A timeout after TCP has connected also deserves a different investigation from a timeout while connecting: inspect SSH negotiation and server load rather than assuming a blocked port.

Why does SSH reject the account or key?

Read the methods in the final permission denied message and the preceding verbose lines. Permission denied (publickey) generally means the server offered public key authentication and the client did not complete it. It does not prove the key file is corrupt. Check the remote username first: a valid key installed for another account will not normally authorize this one.

Test an explicitly selected private key. This example uses a Linux or macOS shell and an existing key file; on Windows, substitute its actual path. IdentitiesOnly limits the identities selected for authentication, but additional IdentityFile entries in client configuration can still matter. Inspect ssh -G output if unexpected keys remain. A key passphrase prompt unlocks a local private key; it is different from the remote account password.

ssh -vvv -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519_chj -p 22 user@server.example
ssh-keygen -lf ~/.ssh/id_ed25519_chj.pub

On the server, compare the matching public key with the authorized key source configured for that account. Inspect ownership, directory traversal permissions and whether another user can write the files. Also check account expiry, access restrictions, Match blocks and any required second factor. On SELinux systems, wrong labels can deny access despite apparently correct Unix modes; diagnose the denial rather than disabling SELinux.

How do you apply a repair without losing access?

Keep a working administrative session and independent console access during server changes. A syntax check cannot prove that your account will still be allowed to log in. Do not close the original session until a fresh connection has succeeded.

  1. Identify the specific mismatch from the client and server evidence. Preserve the original configuration and record which setting or file you will change.
  2. For a listener problem, correct the intended service, listening address or port. For filtering, adjust only the necessary rule for the approved management source. Avoid changing service and network policy simultaneously.
  3. For authentication, correct the account, selected key or authorized public key entry. Preserve existing authorized keys and verify the expected owner before changing permissions.
  4. Validate configuration before applying it, then test from a second client window. If the test fails, use the retained session or console to restore the previous configuration.

For a conventional local Linux account named user with home directory /home/user, inspect these paths first. Confirm the home directory using getent; adapt the paths if it differs. Common restrictive modes are 700 for .ssh and 600 for authorized_keys, with ownership appropriate to the account. These modes do not fix an incorrect key or a different AuthorizedKeysFile location.

getent passwd user
sudo ls -ld /home/user /home/user/.ssh /home/user/.ssh/authorized_keys

For daemon configuration changes on Ubuntu or Debian using ssh.service, this conditional command reloads only after a successful syntax check. It does not handle socket listener changes. If the service is stopped, investigate why before starting it from the console. Updating authorized_keys alone normally needs no daemon reload.

sudo /usr/sbin/sshd -t && sudo systemctl reload ssh.service

How do you verify the repair, including Windows servers?

Repeat the original connection from the original client network using the intended name, port and account. Confirm the server identity, complete authentication, and run a harmless command such as whoami. A successful TCP probe alone is insufficient. Check the server log for the matching attempt and confirm that unrelated users still follow the intended authentication policy.

For Windows Server 2022 or 2025 with OpenSSH Server installed, inspect the service and listener in elevated PowerShell. Use Event Viewer under Applications and Services Logs, OpenSSH, Operational for authentication evidence. The default server configuration is C:\ProgramData\ssh\sshd_config. Linux chmod advice does not apply to Windows ACLs; use Windows-specific key file permissions and the configured authorized key path.

Get-Service -Name sshd
Get-NetTCPConnection -State Listen -LocalPort 22

If the listener uses another port, substitute it in the PowerShell check and the firewall policy. Verify the active firewall profile and the allowed remote address scope. Do not assume the presence of a rule named OpenSSH-Server-In-TCP proves that the current port and management network are allowed.

Which shortcuts should you avoid, and how do you prevent recurrence?

  • Do not disable the firewall or allow unrestricted inbound access as a diagnostic default. Keep access scoped to approved sources and change one condition at a time.
  • Do not enable root password login or broadly relax authentication policy to make one key work. Investigate the rejected account and key instead.
  • Do not apply recursive chmod or chown to an entire home directory. Inspect the specific files and preserve application permissions and existing authorized keys.
  • Do not bypass host identity checks. If the host key changed, verify its fingerprint through an independent trusted channel before replacing a stored entry.

Document the management endpoint, port, required VPN, account and recovery console. Keep client configuration explicit for each server, maintain a tested spare administrative access path, and review configuration changes before applying them. After a planned port or address change, verify both address families that you publish and update firewall rules and operational notes together.

How does CH-J Tools help with these errors?

CH-J Diagnostics can test TCP reachability without an SSH login. Use that check when separating an unreachable endpoint from a rejected account. A successful TCP result does not establish that SSH authentication will succeed; continue with the account, key and server log checks described above.

Frequently asked questions

Why can I ping the server but SSH times out?

ICMP replies and TCP access are controlled separately. Verify the SSH listener, destination port, routing and filtering for your actual client source address.

Does permission denied mean my password is wrong?

Not necessarily. The username may be wrong, password login may be disabled, the key may be missing, or account policy may reject access. Check the offered methods and server log.

Why does SSH work from one network but not another?

The working path may use a VPN, another DNS answer or an allowed source address. Compare resolved destinations and routes before changing the server authentication settings.

Can too many agent keys prevent SSH login?

Yes. The server may end authentication after too many failed attempts before the correct key is tried. Select the intended key with IdentitiesOnly and inspect additional configured identity files.

Should I reinstall OpenSSH to fix connection refused?

First confirm the destination, listener and service state. A stopped service, incorrect port or rejecting firewall can explain the error without a damaged installation.

Detailed documentation

OpenSSH: ssh →

OpenSSH: sshd_config →

OpenSSH: ssh_config →

Microsoft Learn: Troubleshoot OpenSSH communication through Windows Firewall →

Biometric unlock and security →

All tutorials by category →