How to fix channel 2: open failed: connect failed: Connection timed out in SSH

SSHINTERMEDIATEMEDIUMUpdated May 28, 2026· 278 views

SSH port forwarding fails when the SSH server cannot reach the final destination host/port and the connection times out. Causes include firewalls, a down service, wrong host/port, or disabled TCP forwarding.

Quick fix

Fixes channel 2: open failed: connect failed: Connection timed out

ssh -v user@remote-host.com
  1. Verify the SSH connection itself works
  2. Test the destination host directly from the remote server
  3. Confirm you are using the right destination address (resolved on the remote server)
  4. Check that the SSH server allows TCP forwarding
ssh — error
ssh -v user@remote-host.com
channel 2: open failed: connect failed: Connection timed out

What this error means

When using SSH port forwarding (ssh -L or -R), a SOCKS proxy (ssh -D), proxy commands, or remote execution, SSH opens a "channel" to forward traffic to a destination host. The error "channel open failed: connect failed: Connection timed out" means SSH successfully connected to the remote SSH server and established the initial SSH session, but when the remote server then tried to open a TCP connection onward to the final destination (for example 127.0.0.1:8080 as seen from that remote server), that connection timed out. The destination didn't respond within the TCP timeout window, indicating a network/routing issue, a firewall block, or that the target service isn't running or listening. The timeout you are seeing is the remote server's own TCP connect timeout to the destination, not the SSH client's connect timeout to the SSH server.

Typical symptoms

  • SSH connection establishes successfully, but channel operations fail
  • Port forwarding sits idle then displays the error message
  • Error appears with multiple channels when using an SSH tunnel (channel 2, 3, etc.)
  • Manual SSH works, but ssh -L local_port:host:remote_port fails
  • Continuous stream of channel timeout errors when using a SOCKS proxy
  • Remote command execution seems to connect but times out before output

Common causes

  1. The destination service (web server, database, etc.) isn't running or listening on the specified port
  2. The destination host/port is incorrect in the forwarding command (and is resolved on the remote server, not locally)
  3. A firewall (iptables, firewalld, ufw) blocks the connection from the remote SSH server to the destination
  4. The destination host is unreachable or the remote server has no route to it
  5. TCP forwarding is disabled on the SSH server (AllowTcpForwarding no in sshd_config)
  6. The destination IP is using IPv6 but the tunnel expects IPv4 (or vice versa)
  7. Network latency or packet loss is so high the TCP connect times out before completing
  8. Connection idle/timeout policies on intermediate network devices (routers, load balancers, bastions)
  9. SSH server has MaxSessions or MaxStartups limits preventing new channels from opening

How to fix "channel 2: open failed: connect failed: Connection timed out"

1Verify the SSH connection itself works

First confirm that the basic SSH connection to the remote server succeeds:

bash
ssh -v user@remote-host.com

If this fails, you have an SSH authentication or reachability issue with the SSH server itself, not a channel issue. Fix basic SSH connectivity before proceeding. If this works, the SSH session is fine and the problem is the onward connection to your forwarding destination, so continue to the next step.

2Test the destination host directly from the remote server

SSH into the remote server and try connecting to the destination host the same way the tunnel would. This is the single most useful test, because the destination is resolved and connected from the remote server, not from your local machine:

bash
ssh user@remote-host.com
# Now you are on the remote server
nc -zv destination-host 8080
# or
curl -v http://destination-host:8080/

If this times out or is refused from the remote server, the tunnel will fail in exactly the same way. Check, in order:
- The destination service is actually running and listening (ss -tlnp | grep 8080 on the destination)
- The destination host/port is correct
- The remote server has a route to the destination
- No firewall (on the remote server or the destination) is blocking the path

3Confirm you are using the right destination address (resolved on the remote server)

In ssh -L local_port:host:dest_port, the host:dest_port is resolved and connected from the remote SSH server, not from your laptop. A common cause of this timeout is pointing at an address the remote server cannot reach.

If the service runs on the SSH server itself and listens on loopback, use 127.0.0.1:

bash
ssh -L 8080:127.0.0.1:8080 user@remote-host.com

If the service listens on a specific interface or another internal host reachable from the remote server, use that address instead:

bash
ssh -L 8080:192.168.1.10:8080 user@remote-host.com

Verify what the service is bound to (loopback vs a specific IP vs 0.0.0.0) with ss -tlnp on the machine running it, and match the forwarding target to that.

4Check that the SSH server allows TCP forwarding

If forwarding is disabled server-side, channels will fail. SSH into the server and check /etc/ssh/sshd_config:

bash
grep -i AllowTcpForwarding /etc/ssh/sshd_config

The default (when unset) is yes. If it is explicitly set to no, enable it:

bash
sudo nano /etc/ssh/sshd_config
# Find or add:
AllowTcpForwarding yes

Validate the config and restart SSH:

bash
sudo sshd -t
sudo systemctl restart sshd
5Allow the remote SSH server's outbound connection to the destination

The connection that times out is an outbound connection made by sshd on the remote server to your destination. If the remote server has an egress firewall, that outbound traffic may be dropped silently (a drop, not a reject, is what produces a timeout rather than an immediate refusal). On the remote server, allow the outbound connection to the destination port.

For iptables (allow outbound to the destination port; add the matching inbound ESTABLISHED rule if your OUTPUT policy is restrictive):

bash
# Inspect current rules
sudo iptables -L OUTPUT -n --line-numbers

# Allow outbound connections to the destination port (example: 8080)
sudo iptables -A OUTPUT -p tcp --dport 8080 -j ACCEPT

For ufw, this is an outbound (egress) allow rule:

bash
sudo ufw allow out to any port 8080 proto tcp

firewalld does not filter outbound traffic in its default zones, so a normal --add-port (which opens *inbound* traffic) will not help here. If you have an explicitly restrictive egress policy, add a direct/rich rule allowing the outbound connection instead, for example:

bash
sudo firewall-cmd --permanent --direct --add-rule ipv4 filter OUTPUT 0 \
  -p tcp --dport 8080 -j ACCEPT
sudo firewall-cmd --reload

Do not use firewall-cmd --add-forward-port for this: that sets up NAT/port redirection on the firewall host and does not authorize sshd's outbound connection to the destination, so it will not resolve this error.

Also remember the firewall on the destination host must accept the inbound connection from the remote server.

6Handle IPv4 vs IPv6 mismatches

If the destination resolves to an IPv6 address but only IPv4 connectivity works (or vice versa), the connect can hang and time out. Force the destination address family by specifying the literal address.

For an explicit IPv4 destination:

bash
ssh -L 8080:192.168.1.10:8080 user@remote-host.com

For an explicit IPv6 destination, wrap it in square brackets:

bash
ssh -L 8080:[::1]:8080 user@remote-host.com

You can also influence which family SSH uses to reach the remote server with -4 or -6, but the destination timeout itself is decided by what host resolves to on the remote server.

7Enable verbose logging to see exactly where it fails

Add verbose flags to see the detailed channel and connection attempts:

bash
ssh -vvv -L 8080:localhost:8080 user@remote-host.com

Look for lines such as:
- Requesting port forward... / Local forwarding listening... (the local listener is set up)
- channel N: connecting to <host> port <dest_port> (the remote-to-destination attempt begins)
- connect failed: Connection timed out (the onward connection is what failed)

Seeing the failure only after the connecting to line confirms the problem is the remote server reaching the destination, which points you back to steps 2 and 5.

8Rule out SSH server channel/session limits

If many forwarded connections fail at once, the SSH server may be limiting concurrent sessions or new connections. Check the server's sshd_config:

bash
grep -iE 'MaxSessions|MaxStartups' /etc/ssh/sshd_config

If MaxSessions is very low (for example 1), raise it:

bash
MaxSessions 10

Then validate and restart:

bash
sudo sshd -t
sudo systemctl restart sshd

Note: limits typically surface as open failed: administratively prohibited or connection drops rather than a timeout, so treat this as a secondary check once network reachability (steps 2 and 5) is confirmed.

Advanced notes

Where the timeout actually comes from: The "Connection timed out" is the remote server's TCP connect timeout to the destination, governed by the remote OS network stack (and any firewall dropping packets), not by the SSH client. Client-side options like ConnectTimeout only control how long your client waits to reach the SSH server; they do not extend or fix the remote-to-destination connect, so increasing ConnectTimeout will not resolve this error. The right fix is making the destination reachable from the remote server (steps 2 and 5).

SOCKS proxy (ssh -D): When using ssh -D as a SOCKS proxy, occasional channel N: open failed: connect failed: Connection timed out messages are common and usually harmless — they reflect individual destination connections your proxy client tried that timed out (for example dead trackers or blocked hosts). The proxy keeps working for reachable destinations.

Multi-hop paths and bastions: If your connection path goes through several hops (bastion host, VPN, jump host), an intermediate device may be dropping the onward connection. Use ProxyJump (ssh -J bastion user@remote-host.com) and test connectivity from each hop independently to find where the timeout originates.

Keep long-lived tunnels alive: For long-running tunnels, add keep-alive packets so an idle channel is not torn down by intermediate firewalls or NAT timeouts:

bash
ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=3 -L 8080:localhost:8080 user@remote-host.com

This addresses tunnels that *drop after being idle*, which is a different symptom from the initial connect timeout described above.

Frequently asked questions

What does "channel 2: open failed: connect failed: Connection timed out" mean?
When using SSH port forwarding (ssh -L or -R), a SOCKS proxy (ssh -D), proxy commands, or remote execution, SSH opens a "channel" to forward traffic to a destination host. 1:8080 as seen from that remote server), that connection timed out. The destination didn't respond within the TCP timeout window, indicating a network/routing issue, a firewall block, or that the target service isn't running or listening.
How do I fix "channel 2: open failed: connect failed: Connection timed out"?
SSH port forwarding fails when the SSH server cannot reach the final destination host/port and the connection times out. Causes include firewalls, a down service, wrong host/port, or disabled TCP forwarding.
What causes "channel 2: open failed: connect failed: Connection timed out"?
The destination service (web server, database, etc.) isn't running or listening on the specified port The destination host/port is incorrect in the forwarding command (and is resolved on the remote server, not locally) A firewall (iptables, firewalld, ufw) blocks the connection from the remote SSH server to the destination
Is the "channel 2: open failed: connect failed: Connection timed out" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading