How to Understand SSH Tunneling and Its Use Cases / Blogs / Perficient (2024)

SSH tunneling is the feature offered by the OpenSSH tool, which lets us create a tunnel between two hosts so that data from some other protocol is encapsulated in the SSH header and transferred as SSH data between those two hosts.

SSH comes with authentication and encryption built-in, meaning we can use SSH tunnels to transfer the data from unsecured services between two hosts.

How to Understand SSH Tunneling and Its Use Cases / Blogs / Perficient (1)

SSH tunneling can be implemented in three ways:

  1. SSH Tunnel (local port forwarding)
  2. Reverse SSH Tunnel (remote port forwarding)
  3. Dynamic SSH Tunnel (dynamic port forwarding)

SSH Tunnel (local port forwarding)

When you create an SSH tunnel with local port forwarding, the SSH tunnel forwards the data from the port on the client machine to the port on the server machine. It is the simplest form of SSH tunnel.

Use the following command to set up the SSH tunnel between your machine and remote machine (given that you have SSH access to the remote machine):

ssh -L 1234:localhost:5678 remoteuser@remotehost

In this command, “-L” refers to the local side listening. With the above command, all the data coming on “port 1234” of your machine will be encapsulated as SSH data and forwarded to “port 5678” of the remotehost. In the above example, “localhost” refers to the localhost IP of a remote machine.

How to Understand SSH Tunneling and Its Use Cases / Blogs / Perficient (2)

Another implementation of local port forwarding is the following:

ssh -L 1234:farawayhost_IP:5678 remoteuser@remotehost

In this kind of implementation, all the data coming on “port 1234” of your machine will be forwarded to the “port 5678” on the farawayhost machine by remotehost machine (given that farawayhost allows the remote host to send data for port 5678).

How to Understand SSH Tunneling and Its Use Cases / Blogs / Perficient (3)

Local port forwarding is very useful while accessing the services hosted on a private network. Let’s take a scenario where your office network only allows SSH connections to the inside resources/machines, blocks all other traffic from outside networks, and you want to access the website restricted to your office network securely. In such a case, you can create an SSH tunnel to the machine inside your office network and access the restricted website:

ssh -L 8080:restricted.domain.com:80 remoteuser@remotehost

You can access the restricted website with the URL “http://localhost:8080” in your local machine browser. This is one of many use cases of local port forwarding. One other use case would be to access the database on the server securely without exposing the database ports.

Reverse SSH Tunnel (Remote Port Forwarding)

Reverse SSH tunnel listens to the port on the remote machine and forwards all the data coming on that port to the specified port on your local machine via SSH.

ssh -R 1234:localhost:5678 remoteuser@remotehost

In this command, “-R” refers to the remote side listening and listens to the “port 1234” on the remote machine and forwards all the data from “port 1234” of the remote machine to the “port 5678” on your local machine.

How to Understand SSH Tunneling and Its Use Cases / Blogs / Perficient (4)

Another implementation of remote port forwarding is the following:

ssh -R 1234:nearhost_IP:5678 remoteuser@remotehost

In this example, all the data from “port 1234” of the remote machine will be forwarded by your local machine to “port 5678” of the nearhost machine.

How to Understand SSH Tunneling and Its Use Cases / Blogs / Perficient (5)

Now let’s imagine a scenario where a developer is developing an application/website on its local machine and wants to let his/her client/team access that locally hosted website/app for a demo. Often, you do not have a public IP for your local machine (although you can create access to your local machine by configuring NAT rules, it doesn’t always work). You can create a reverse SSH tunnel to a publicly accessible server for “port 80” (or any custom port) and let the end-users (clients or your team members in this example) browse the website using the IP address of this public server on “port 80” (or any custom port that you define in the command) to access the website.

Before you consider implementing a reverse SSH tunnel, the parameter “GatewayPorts” should be set to “yes” in your remotehost’s SSH server configuration file “/etc/ssh/sshd_config.”

Dynamic SSH Tunnel (Dynamic Port Forwarding)

Before we learn about what a dynamic SSH tunnel is, let’s discuss what a proxy and a Socket Secure (SOCKS) proxy are. Simply, a proxy is a service/server that makes a request on your behalf. You must have used HTTP proxy, where your browser connects to a proxy server and that proxy server makes the HTTP request on your behalf and forwards you the response it gets.

Aside from traffic forwarding, proxy servers provide security by hiding the actual IP address of a client.

How to Understand SSH Tunneling and Its Use Cases / Blogs / Perficient (6)

A SOCKS proxy routes any type of traffic generated by any protocol or program to the actual server on the behalf of the client. Unlike an HTTP proxy, it’s protocol-independent.

Many applications like browsers support a SOCKS proxy where you configure the IP and port of the proxy server. If the proxy is configured on the browser, this request is encapsulated with the SOCKS header where the destination port and IP of your request become the port and IP of the proxy server you configured on your browser.

The proxy server then decapsulates this data and sends the request to the actual IP (IP of the website) and port (80 or 443), where the source IP is the IP of the proxy server.

How to Understand SSH Tunneling and Its Use Cases / Blogs / Perficient (7)

Let’s demonstrate the Dynamic SSH tunnel by revisiting the example we saw for local port forwarding. In that case, if you want to access multiple restricted URLs in a private network, you will have to create multiple static SSH tunnel sessions to the destination host. This is not a feasible solution.

Here comes the dynamic SSH tunnel to the rescue, which leverages the SOCKS protocol. You can implement the dynamic SSH tunnel using the following command:

ssh -D 1234 remoteuser@remotehost

In this case, your SSH tunnel acts as SOCKS proxy listening on “port 1234.” The request is added to “port 1234” of your local machine will be forwarded to the remotehost machine, and the remotehost machine will make the request to the actual server on your behalf.

Your client application should be SOCKS aware. In this case, our client is our browser. We will consider Firefox in our example:

Go to “Settings.” Click “General,” then “Network Settings,” and click the “Settings” button. Select “Manual proxy configuration.” Enter the IP address of your local machine (127.0.0.1 will also work) in the section “SOCKS Host.” Next, enter the port number you specified in the above command (1234 in this example).

Now, whenever you hit any URL, the request will be sent to “port 1234” of your local machine by the browser, which will then be forwarded to the remote host via SSH tunnel, and then the remotehost will make the request to the actual server on your behalf. In this case, all the Domain Name System (DNS) requests by the browser are also made through the remotehost machine.

This kind of implementation is very helpful when you’re connected to a public internet source like a hotel or restaurant Wi-Fi. You can set up a small device like a Raspberry Pi (a small pocket-sized System-on-Chip Computer) in your home network and make it SSH accessible publicly. Connect to the Raspberry Pi by using the dynamic SSH tunnel and configure your browser accordingly. This can protect you from a “Man-In-The-Middle” attack (where an attacker sniffs the data traffic between the source and the destination) while using the public internet.

Easily Utilize SSH Tunneling

SSH tunneling is a very simple feature yet very powerful, enabling secure data transfer over a network. As we’ve discussed, SSH Tunneling doesn’t have any fixed type of use case, but it can come in very handy in different kinds of situations if you know how it works. For more information, contact our experts.

How to Understand SSH Tunneling and Its Use Cases / Blogs / Perficient (2024)

FAQs

What is the use case of SSH tunneling? ›

This is useful for providing access to a local service from the remote machine or exposing a local service to the internet through the remote server. Use Cases for Remote Port Forwarding: Allowing remote users to access a local web server. Providing access to a local application from a remote server.

What are the 3 types of SSH tunneling? ›

SSH tunneling can be implemented in three ways:
  • SSH Tunnel (local port forwarding)
  • Reverse SSH Tunnel (remote port forwarding)
  • Dynamic SSH Tunnel (dynamic port forwarding)
Aug 10, 2021

What is a server tunnel? ›

Similarly, in networking, tunnels are a method for transporting data across a network using protocols that are not supported by that network. Tunneling works by encapsulating packets: wrapping packets inside of other packets.

What is a SSH tunnel proxy? ›

A SOCKS proxy is an SSH encrypted tunnel in which configured applications forward their traffic down, and then, on the server-end, the proxy forwards the traffic to the general Internet.

What is the risk of SSH tunneling? ›

This invisibility carries considerable risk potential if it is used for malicious purposes such as data exfiltration. Cybercriminals or malware could exploit SSH tunnels to hide their unauthorized communications, or to exfiltrate stolen data from the target network.

What are the main uses of SSH? ›

SSH is often used to "login" and perform operations on remote computers but it may also be used for transferring data.

What is the difference between SSL tunnel and SSH tunnel? ›

An SSH tunnel uses public key authentication or password authentication for access control. In comparison, an SSL uses digital certificates from trusted third-party certificate authorities to verify server identity and client authenticity.

What is the difference between SSH tunnel and VPN? ›

VPNs and SSH systems both create secure “tunnels” for your data to travel through. These tunnels ensure that nobody other than the intended recipient can view or alter your data. However, while an SSH connection only works on an application level, a VPN connection encrypts and protects all your data.

Is SSH TCP or UDP or both? ›

Is SSH over TCP or UDP? SSH uses TCP, not UDP (User Datagram Protocol).

What is the purpose of tunneling? ›

Tunnels are used for a wide variety of purposes. They provide essential links in many highways, railroads, and urban rapid transit systems. Urban water supply and distribution, sewage collection and disposal, hydroelectric power generation, flood control, and mining require extensive tunneling.

What is the difference between port forwarding and tunneling? ›

Port Forwarding, also known as “port-based forwarding” or “port mapping”, maps an IP address and TCP port to another IP address and another TCP port. What is tunnelling? Tunnelling is encapsulating and wrapping packets in layers of headers to form a tunnel.

How to create SSH tunneling? ›

In Windows - putty

Click the plus sign by the SSH menu choice in the left pane of the main window. Click on Tunnels. Once the information is in place, click the Add button to create the tunnel. Click on the Session menu choice at the top of the left hand pane and enter any valid SCF host in the Host Name window.

Why do we need SSH tunneling? ›

SSH tunneling, also known as SSH port forwarding, provides a secure method for client applications to communicate with remote servers. By encrypting traffic, SSH tunnels ensure data protection during transmission.

What port to use for SSH tunnel? ›

Remote Forwarding

This allows anyone on the remote server to connect to TCP port 8080 on the remote server. The connection will then be tunneled back to the client host, and the client then makes a TCP connection to port 80 on localhost .

What is reverse SSH tunneling? ›

Reverse SSH tunneling is a technique used to establish a secure connection from a remote server or a remote IoT device back to a local machine. At its core, it's about creating an encrypted SSH connection in the opposite direction to the norm.

What are tunneling protocols used for? ›

A tunnelling protocol is one that encloses in its datagram another complete data packet that uses a different communications protocol. They essentially create a tunnel between two points on a network that can securely transmit any kind of data between them.

What is the use case of IPSec tunnel? ›

IPSec tunnels are primarily used for securing data transmission over the internet, intranets, and extranets, as well as in VPNs. Security Features: IPSec provides a comprehensive set of security features, including data encryption, data integrity verification, and authentication of communication endpoints.

What is the use case of SSH key? ›

An SSH key is an access credential in the SSH protocol. Its function is similar to that of user names and passwords, but the keys are primarily used for automated processes and for implementing single sign-on by system administrators and power users.

What is the common use of SSH? ›

In addition to providing strong encryption, SSH is widely used by network administrators to manage systems and applications remotely, enabling them to log in to another computer over a network, execute commands and move files from one computer to another.

Top Articles
Do Forex Brokers Cheat Traders? Unveiling the Truth
Esistono paesi europei in cui è possibile non pagare il capital gain? – Borgogna – The house of mind
Po Box 7250 Sioux Falls Sd
Is Sam's Club Plus worth it? What to know about the premium warehouse membership before you sign up
Metra Union Pacific West Schedule
Sandrail Options and Accessories
Nyu Paralegal Program
Lifebridge Healthstream
Myhr North Memorial
Computer Repair Tryon North Carolina
Directions To Lubbock
Cvs Learnet Modules
Summoner Class Calamity Guide
Dutchess Cleaners Boardman Ohio
Clarksburg Wv Craigslist Personals
Apne Tv Co Com
Bitlife Tyrone's
Andhrajyothy Sunday Magazine
Craigslist Sparta Nj
Welcome to GradeBook
[Cheryll Glotfelty, Harold Fromm] The Ecocriticism(z-lib.org)
Outlet For The Thames Crossword
Acts 16 Nkjv
Dr Ayad Alsaadi
Reser Funeral Home Obituaries
Lines Ac And Rs Can Best Be Described As
Cona Physical Therapy
The Creator Showtimes Near Baxter Avenue Theatres
Evil Dead Rise Showtimes Near Regal Sawgrass & Imax
Google Flights To Orlando
Wheeling Matinee Results
King Soopers Cashiers Check
Bad Business Private Server Commands
Productos para el Cuidado del Cabello Después de un Alisado: Tips y Consejos
Unm Hsc Zoom
Where Can I Cash A Huntington National Bank Check
JD Power's top airlines in 2024, ranked - The Points Guy
LEGO Star Wars: Rebuild the Galaxy Review - Latest Animated Special Brings Loads of Fun With An Emotional Twist
Dr. John Mathews Jr., MD – Fairfax, VA | Internal Medicine on Doximity
Ursula Creed Datasheet
Scarlet Maiden F95Zone
Patricia And Aaron Toro
Rocket Lab hiring Integration & Test Engineer I/II in Long Beach, CA | LinkedIn
Squalicum Family Medicine
Hillsborough County Florida Recorder Of Deeds
Sc Pick 3 Past 30 Days Midday
Windy Bee Favor
Myapps Tesla Ultipro Sign In
Frank 26 Forum
Coldestuknow
Koniec veľkorysých plánov. Prestížna LEAF Academy mení adresu, masívny kampus nepostaví
Latest Posts
Article information

Author: Kareem Mueller DO

Last Updated:

Views: 5623

Rating: 4.6 / 5 (46 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Kareem Mueller DO

Birthday: 1997-01-04

Address: Apt. 156 12935 Runolfsdottir Mission, Greenfort, MN 74384-6749

Phone: +16704982844747

Job: Corporate Administration Planner

Hobby: Mountain biking, Jewelry making, Stone skipping, Lacemaking, Knife making, Scrapbooking, Letterboxing

Introduction: My name is Kareem Mueller DO, I am a vivacious, super, thoughtful, excited, handsome, beautiful, combative person who loves writing and wants to share my knowledge and understanding with you.