Getting sshd to use a proxy when tunneling with SOCKS5

Abstract: Configure SSH client to route connections through a SOCKS5 proxy using ProxyCommand or ProxyJump directives in the local config file.

Created: 2026-09-12 by

To configure sshd to use a proxy when tunneling with SOCKS5, you must rely on the client-side configuration rather than server-side settings. The ProxyCommand or ProxyJump directives in your local ~/.ssh/config file instruct the SSH client to route its connection through a specified proxy before reaching the target host. This approach ensures that all traffic, including the initial handshake and subsequent data transfer, is correctly routed through the SOCKS5 proxy.

Understanding the Client-Server Dynamic

It is crucial to understand that the Secure Shell daemon (sshd) running on the remote server has no control over how the client connects to it. The server simply listens for incoming connections; it does not initiate them. Therefore, any requirement to use a proxy for establishing the connection must be handled by the SSH client software on your local machine. Attempting to configure proxies within the sshd_config file on the remote server will have no effect on the establishment of the tunnel itself. The standard way to achieve this is by modifying the configuration of the SSH client. OpenSSH provides robust mechanisms to define how connections are made, including support for various proxy types such as HTTP CONNECT, SOCKS4, and SOCKS5. By configuring the client, you ensure that the tunnel is established correctly regardless of network restrictions between your local machine and the intermediate proxy server. For more information on managing SSH tunnels and troubleshooting common failures, you might find Troubleshooting Autossh/Ssh Failure Setting Tunnel with ExitOnForwardFailure helpful, as it addresses stability issues often encountered when maintaining persistent connections through complex network paths.

Configuring SOCKS5 Proxy via SSH Config

The most reliable method to route SSH traffic through a SOCKS5 proxy is using the ProxyCommand directive. This directive allows you to specify an external command that will handle the connection to the remote host. For SOCKS5 proxies, the nc (netcat) utility with SOCKS5 support is commonly used. First, ensure that your version of nc supports SOCKS5. You can verify this by checking the manual page or attempting a test connection. If your system uses proxychains or a similar tool, that can also be utilized, but direct nc integration is often simpler and more transparent. Add the following lines to your ~/.ssh/config file:
Host my-proxy-host
    HostName 192.168.1.100
    User username
    ProxyCommand nc -X 5 -x proxy.server.com:1080 %h %p
In this example, nc -X 5 specifies the use of SOCKS5 protocol, and -x proxy.server.com:1080 defines the address and port of your SOCKS5 proxy. The %h and %p placeholders are replaced by the hostname and port of the target host automatically by the SSH client. This configuration tells SSH to execute the netcat command, which then establishes a SOCKS5 tunnel to the target. If you are experiencing negotiation errors or connection drops, refer to SSH Connection Tunnel Unable to Negotiate Error: A Technical Support Guide for diagnostic steps that may apply to your specific network environment.

Using ProxyJump for Simplified Routing

OpenSSH versions 7.3 and later introduced the ProxyJump directive, which simplifies the process by allowing you to jump through one or more hosts without manually specifying the proxy command. However, ProxyJump typically works best when jumping through another SSH server, not directly through a raw SOCKS5 proxy. To use a SOCKS5 proxy with ProxyJump, you would need to set up an intermediate SSH server that itself uses a SOCKS5 proxy, or combine it with ProxyCommand. A common pattern is to define a "gateway" host that handles the proxy connection:
Host gateway
    HostName proxy.server.com
    Port 22
    User proxyuser
    ProxyCommand nc -X 5 -x localhost:1080 %h %p

Host target-server
    HostName 10.0.0.5
    User admin
    ProxyJump gateway
This setup creates a logical chain where your SSH client connects to the gateway (which uses the SOCKS5 proxy), and then jumps to the target server. This method is cleaner and easier to maintain than chaining multiple ProxyCommand directives.

Optimizing and Troubleshooting

When using proxies, latency can increase due to the additional hop. To optimize performance, consider keeping the connection alive by setting ServerAliveInterval and ServerAliveCountMax in your ~/.ssh/config. This prevents the proxy from dropping idle connections. Additionally, if you need to upgrade your connection from a proxied state to a direct connection for faster access once inside the network, look into strategies for Upgrade SSH Proxy Connection to Direct Connection for Faster Remote Server Access. This can be particularly useful in dynamic environments where network routes change after authentication. Ensure that your firewall rules allow outbound connections to the SOCKS5 proxy port. Common ports include 1080 for SOCKS5 and 8080 for HTTP proxies. If you encounter permission denied errors, verify that the proxy requires authentication and provide credentials via the nc command or a separate authentication mechanism supported by your proxy server. Finally, always test your configuration with verbose output by adding -v to your SSH command. This will show you exactly where the connection is failing, whether at the proxy handshake stage or during the SSH key exchange.

Frequently Asked Questions

Can I configure the proxy directly in sshd_config?

No, sshd_config controls the server's behavior, not the client's connection method. Proxies must be configured on the client side using ~/.ssh/config or command-line options.

What if my SOCKS5 proxy requires authentication?

Most basic SOCKS5 proxies do not support authentication natively in the nc command. You may need to use a wrapper script or a specialized proxy client that supports username/password authentication for SOCKS5.

How do I test if my SSH config is using the proxy?

Run your SSH command with the -v flag (e.g., ssh -v user@host). Look for lines indicating the execution of the ProxyCommand or the connection to the proxy server IP address.

Is ProxyJump better than ProxyCommand?

ProxyJump is generally preferred for simplicity and readability when jumping through SSH servers. However, for raw SOCKS5 proxies, ProxyCommand with nc is often more straightforward unless you have an intermediate SSH gateway.

Why am I getting a "Connection refused" error?

This usually means the proxy server is not running, the port is incorrect, or your local firewall is blocking outbound connections to the proxy. Verify the proxy service status and network connectivity first.
Tags: ssh proxy tunnel

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More