Setup SSH Connection with 3 Ubuntu Machines to Bypass a Firewall

Abstract: Bypass restrictive firewalls to access internal services by chaining SSH connections through an intermediate Ubuntu host.

Created: 2026-10-20 by
Establishing a secure SSH tunnel through three Ubuntu machines allows you to bypass restrictive firewalls by chaining connections. This method routes traffic through intermediate hosts that have open ports, effectively masking the final destination from the initial firewall rules. By configuring each node correctly, you can access internal services securely without exposing them directly to the public internet.

Understanding the Network Topology

Before configuring any software, it is crucial to map out the roles of your three Ubuntu machines. In this scenario, Machine A is your local client, Machine B acts as the first hop (the entry point that has direct internet access), and Machine C is the target server located behind the restrictive firewall. The goal is to connect from A to B, and then from B to C, creating a continuous encrypted path. This approach relies on the fact that while the firewall blocks direct inbound connections to C, it likely allows outbound SSH traffic or permits connections from B to C if they are on the same private network segment. You must ensure that all three machines run compatible versions of OpenSSH and that key-based authentication is preferred over passwords for automation and security. For more details on securing these nodes, refer to our guide on Securing an Ubuntu Server for Development Purposes.

Configuring Key-Based Authentication

Security is paramount when chaining SSH connections. Using password authentication introduces significant risk and complexity, especially across multiple hops. Start by generating SSH keys on your local machine, Machine A. Run the command ssh-keygen -t ed25519 to create a strong key pair. Next, copy the public key to Machine B using ssh-copy-id user@B_IP. Once authenticated to B, generate another key pair specifically for the connection to C, or reuse the existing one if permissions allow. Copy the public key from B to C using ssh-copy-id user@C_IP. This step ensures that both Machine B and Machine C trust the respective identities without requiring manual password entry during the tunnel setup. If you encounter permission issues during this process, check the ownership of the .ssh directory and ensure it is set to 700.

Setting Up the SSH Config File

The most efficient way to manage multi-hop SSH connections is through the configuration file on Machine A. Edit or create the file ~/.ssh/config and define a new host entry for Machine C. Within this block, use the ProxyJump directive to specify Machine B as the intermediary. The configuration should look like this:
Host c_server
    HostName C_IP_Address
    User ubuntu
    ProxyJump B_IP_Address
    IdentityFile ~/.ssh/id_ed25519
This single configuration line tells SSH to automatically establish a connection to B before attempting to reach C. It handles the routing transparently, meaning you do not need to manually open two terminal windows. When you later execute ssh c_server, the system will seamlessly bridge the gap between A and C via B. Ensure that the HostName field matches the actual IP address or DNS name reachable from Machine B. If Machine C is only accessible via a private IP from B, use that private IP here rather than a public one.

Testing and Verifying the Connection

After saving the configuration, test the connectivity from Machine A. Run ssh c_server and observe the output. If configured correctly, you should be logged into Machine C without being prompted for a password for either B or C. To verify that the traffic is indeed passing through B, you can check the active connections on Machine B using ss -tnp | grep ssh. You should see established connections originating from A destined for C. Additionally, enable verbose mode with ssh -v c_server to see the detailed handshake process. This helps identify where the connection might fail if there are network restrictions. For deeper insights into troubleshooting packet drops that might interfere with this chain, see Troubleshooting Dropping Packets in iptables.

Maintaining Persistent Tunnels

For long-term usage, consider setting up persistent tunnels using tools like autossh or systemd timers. This prevents disconnections due to temporary network glitches. Configure autossh to monitor the connection to C and restart it if it fails. This is particularly useful for accessing development environments or databases that require constant availability. Remember to update your SSH config if IP addresses change, and regularly rotate your SSH keys to maintain high security standards. Always restrict the allowed commands in the authorized_keys file on Machine C if the connection is used for automated tasks, adding an extra layer of protection against unauthorized access.

Frequently Asked Questions

What happens if Machine B goes offline?

If Machine B becomes unreachable, the SSH connection from A to C will fail immediately because B is the required gateway. You must restore connectivity to B before re-establishing the tunnel. Consider setting up a backup proxy server if high availability is critical for your workflow.

Can I use port forwarding instead of ProxyJump?

Yes, you can use LocalForward directives in your SSH config, but ProxyJump is generally simpler and more secure for chaining hosts. Port forwarding requires managing multiple local ports and can be more complex to configure correctly. ProxyJump handles the routing internally without exposing additional ports on your local machine.

Is it safe to share SSH keys across multiple machines?

Sharing the same key pair across machines reduces security if one machine is compromised. It is best practice to generate unique key pairs for each hop or role. This limits the blast radius of a potential breach and makes auditing easier. Use different identity files for connections to B and C if possible.

How do I troubleshoot connection timeouts?

Check the firewall rules on both Machine B and Machine C to ensure SSH traffic is permitted. Use the verbose flag (-v) to pinpoint where the connection hangs. Verify that the network interfaces on all machines are properly configured and that routing tables allow traffic between the subnets.

Can I access internal services on Machine C via the tunnel?

Absolutely. Once connected, you can forward local ports to services running on C using additional LocalForward rules in your SSH config. This allows you to access web servers, databases, or other applications on C as if they were running locally on A. Just ensure the services on C are bound to localhost or the correct interface.

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