Thursday, 28 October 2021

How to Fix the "Side Channel and TCP Port Forwarding" Error in OpenSSH

If you've encountered an error while trying to establish an SSH connection that involves "side channel" or "TCP port forwarding," it typically means that your OpenSSH server (SSHD) is rejecting your client's request to open a side channel or initiate TCP port forwarding. This issue can be fixed by ensuring that the correct SSHD settings are enabled on the server. 

Here's how to resolve the issue:
1. Settings You Need to Enable on the SSHD Server
The following settings must be enabled in your SSHD configuration to allow side-channel communication and TCP port forwarding:
    TCPKeepAlive: This setting specifies whether the system should send TCP keepalive messages to the other side to maintain the connection.
    AllowTCPForwarding: This option needs to be enabled on the server to allow port forwarding. By default, SSH servers may have this option disabled for security purposes.
    PermitOpen: This option specifies which destinations are allowed for TCP port forwarding. You need to set this correctly to allow forwarding.

2. Find Current Settings
Before making any changes, it's a good idea to check the current SSHD settings to see if any of the required options are disabled.
sudo sshd -T | grep -Ei 'TCPKeepAlive|AllowTCPForwarding|PermitOpen'
/etc/ssh/sshd_config line 32: Deprecated option KeyRegenerationInterval
/etc/ssh/sshd_config line 33: Deprecated option ServerKeyBits
/etc/ssh/sshd_config line 39: Deprecated option RSAAuthentication
/etc/ssh/sshd_config line 41: Deprecated option RhostsRSAAuthentication
tcpkeepalive no
allowtcpforwarding yes
permitopen any

tcpkeepalive no: This means that TCP keepalive messages are disabled, which could lead to connection timeouts.
 
3. Set Correct Values
    Open the SSH configuration file (/etc/ssh/sshd_config) in a text editor:
sudo nano /etc/ssh/sshd_config

Look for the following directives and adjust them as needed:
TCPKeepAlive yes
AllowTCPForwarding yes
PermitOpen any

Verify the changes by running the command again to check that the settings have been applied correctly:
sudo sshd -T | grep -Ei 'TCPKeepAlive|AllowTCPForwarding|PermitOpen'
    tcpkeepalive yes
    allowtcpforwarding yes
    permitopen any

4. Reload SSHD to Apply Changes
After updating the SSHD configuration file, you'll need to reload the SSHD service to apply the changes.
sudo systemctl reload sshd.service

No comments:

Post a Comment