How to fix error: connect_to hostname port port: failed. in SSH

SSHINTERMEDIATEHIGHUpdated Jan 4, 2026ยท 159 views

This error occurs when an SSH client cannot establish a TCP connection to the SSH server on the remote host. It typically indicates a network connectivity issue, incorrect hostname/port, or the SSH service isn't running or accessible.

Quick fix

Fixes error: connect_to hostname port port: failed.

# Test with explicit hostname and port
ssh -p 22 user@example.com
ssh -p 2222 user@example.com  # If using non-standard port
  1. Verify the hostname and port are correct
  2. Test DNS resolution
  3. Verify the host is reachable with ping
  4. Check if the SSH port is open with telnet or nc
ssh โ€” error
# Test with explicit hostname and port
ssh -p 22 user@example.com
ssh -p 2222 user@example.com # If using non-standard port
error: connect_to hostname port port: failed.

What this error means

The "connect_to hostname port port: failed" error appears when the SSH client attempts to open a TCP socket connection to the specified host and port but the connection fails before the SSH protocol negotiation even begins. This is a lower-level network error that indicates the client cannot reach the server's SSH port. Unlike connection refused or timeout errors, this generic "failed" error can indicate various network issues including unreachable hosts, firewall blocks, DNS resolution problems, or network interface issues.

Typical symptoms

  • SSH connection fails immediately without waiting
  • Error appears during initial connection attempt before password/key prompt
  • Ping to the same hostname works but SSH fails
  • Connection works to other hosts but not this one
  • Error occurs from behind a corporate firewall or VPN
  • Works on one network but not another
  • Port scanning shows the port as filtered or closed

Common causes

  1. Hostname does not resolve correctly to an IP address (DNS issue)
  2. SSH service is not running on the remote host
  3. SSH is listening on a different port than you're trying to connect to
  4. Firewall is blocking outbound connections to the SSH port
  5. Firewall on the remote host is not allowing inbound SSH traffic
  6. Network routing issue preventing the packet from reaching the destination
  7. The host IP address is incorrect or the server is offline
  8. Proxy or VPN configuration interfering with direct connections
  9. Network interface on remote host is not properly configured
  10. SSH daemon crashed or stopped responding

How to fix "error: connect_to hostname port port: failed."

1Verify the hostname and port are correct

First, double-check the hostname and port you're using. The default SSH port is 22, but some servers use non-standard ports:

bash
# Test with explicit hostname and port
ssh -p 22 user@example.com
ssh -p 2222 user@example.com  # If using non-standard port

Verify you have the correct hostname. Try using the IP address directly to rule out DNS issues:

bash
ssh -p 22 user@192.168.1.100
2Test DNS resolution

Verify that the hostname resolves to an IP address:

bash
nslookup example.com
dig example.com
# On Windows:
nslookup example.com

If the hostname doesn't resolve, it won't work. Check:
- The hostname spelling is correct
- You have an active internet connection
- Your DNS resolver is working
- The domain actually exists

If DNS resolution fails, either use the IP address directly or fix your DNS settings.

3Verify the host is reachable with ping

Test if the remote host is reachable at all:

bash
ping -c 4 example.com
# On Windows:
ping example.com

If ping fails, the host is unreachable due to network issues. Check:
- The host is actually online
- Network cables/WiFi connection is active
- No firewall is blocking ICMP traffic
- The IP address/hostname is correct

If the host is offline or unreachable, that's the root cause of the SSH connection failure.

4Check if the SSH port is open with telnet or nc

Test if the specific SSH port is open and accepting connections:

bash
# Using telnet (if available)
telnet example.com 22
# Or using nc (netcat)
nc -vz example.com 22
# Or using timeout + bash
timeout 2 bash -c 'echo > /dev/tcp/example.com/22' && echo "Port open" || echo "Port closed"

If this succeeds, you should see a response like:

bash
Connected to example.com.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.4

If it fails, the SSH port is not accessible. This confirms the network/firewall issue.

5Enable SSH verbose mode for detailed diagnostics

Run SSH with verbose flags to see exactly where the connection fails:

bash
ssh -vvv user@example.com

The -vvv flag provides maximum verbosity. Look for lines like:
- Trying 192.168.1.100... - Shows if it found an IP
- Connection refused - Server is reachable but SSH port closed
- No route to host - Network unreachable
- Connection timed out - Server not responding

The verbose output will tell you exactly where the connection process fails, helping identify if it's DNS, routing, firewall, or the SSH service.

6Check firewall rules on the remote host

If the host is reachable by ping, verify the firewall allows SSH on port 22:

On the remote host (Linux):

bash
# Check if SSH port is listening
sudo netstat -tlnp | grep ssh
# Or using ss:
sudo ss -tlnp | grep ssh

Should show something like:

bash
tcp  0  0 0.0.0.0:22  0.0.0.0:*  LISTEN

Check firewall rules:

bash
# UFW (Ubuntu/Debian)
sudo ufw status
sudo ufw allow 22/tcp

# iptables (general Linux)
sudo iptables -L -n | grep 22

# firewalld (CentOS/RHEL)
sudo firewall-cmd --list-all
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
7Check firewall on your local machine

Verify your local firewall isn't blocking outbound SSH connections:

On Linux:

bash
sudo iptables -L -n
sudo firewall-cmd --list-all  # For firewalld

On macOS:
Open System Preferences > Security & Privacy > Firewall and check if it's blocking SSH.

On Windows:
Open Windows Defender Firewall > Advanced settings and check for outbound rules blocking port 22.

Most modern firewalls allow outbound connections by default, but corporate networks may restrict them. If behind a corporate firewall, check with your IT department.

8Restart the SSH service on the remote host

If you have access to the remote host console or through another method, restart the SSH daemon:

bash
# On Linux/Unix
sudo systemctl restart ssh
# Or:
sudo systemctl restart sshd

# Check if it's running:
sudo systemctl status ssh

The SSH service might have crashed or stopped. Restarting it may resolve the issue. If you can't access the console, you may need to:
- Request the system administrator restart SSH
- Reboot the server if necessary
- Check cloud provider console (AWS, DigitalOcean, etc.) for the host status

Advanced notes

Advanced troubleshooting:

SSH on Non-Standard Ports: Many systems run SSH on ports other than 22 (e.g., 2222, 10022) for security. Always specify the correct port with -p:

bash
ssh -p 2222 user@example.com

Behind NAT/Router: If connecting through a NAT router or firewall, port forwarding must be configured. The remote address might be a public IP that maps to an internal IP. Work with your network admin to set up port forwarding rules.

IPv6 vs IPv4: Some hosts respond on IPv6 but not IPv4, or vice versa. Try explicitly specifying the IP version:

bash
ssh -4 user@example.com  # Force IPv4
ssh -6 user@example.com  # Force IPv6

ProxyJump/Bastion Hosts: If connecting through a bastion/jump host, use ProxyJump:

bash
ssh -J user@bastion.com user@internal-host.com

SSH ProxyCommand: Older systems may need ProxyCommand in ~/.ssh/config instead of ProxyJump.

Corporate Network Issues: Behind a corporate proxy or firewall, direct SSH may be blocked. Check if SSH over HTTPS (port 443) is available, or use ssh -C for compression. Contact your IT department for proxy settings.

DNS Propagation Delays: After adding a new DNS record, changes can take hours to propagate worldwide. If you just added the DNS entry, wait and try again later, or use the IP address directly.

Intermittent Failures: If connection sometimes works and sometimes doesn't, suspect:
- Load balancer or DNS round-robin with some servers offline
- Temporary network congestion
- Rate limiting kicking in after repeated failed attempts

Frequently asked questions

What does "error: connect_to hostname port port: failed." mean?
The "connect_to hostname port port: failed" error appears when the SSH client attempts to open a TCP socket connection to the specified host and port but the connection fails before the SSH protocol negotiation even begins. This is a lower-level network error that indicates the client cannot reach the server's SSH port. Unlike connection refused or timeout errors, this generic "failed" error can indicate various network issues including unreachable hosts, firewall blocks, DNS resolution problems, or network interface issues.
How do I fix "error: connect_to hostname port port: failed."?
This error occurs when an SSH client cannot establish a TCP connection to the SSH server on the remote host. It typically indicates a network connectivity issue, incorrect hostname/port, or the SSH service isn't running or accessible.
What causes "error: connect_to hostname port port: failed."?
Hostname does not resolve correctly to an IP address (DNS issue) SSH service is not running on the remote host SSH is listening on a different port than you're trying to connect to
Is the "error: connect_to hostname port port: failed." error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading