Table of Contents

SSH Port Forwarding (Tunneling)

SSH (Secure Shell) is a widely used protocol for system administration and file transfer. It provides secure encrypted communication between two hosts over an insecure network. One of the key features of SSH is port forwarding, also known as SSH tunneling, which allows users to create encrypted connections and forward network traffic through SSH sessions. This guide will provide a comprehensive overview of SSH port forwarding, including its types and practical examples.

Prerequisites

Checking SSH Server Configuration

sudo nano /etc/ssh/sshd_config
AllowTcpForwarding yes
GatewayPorts yes
sudo systemctl restart sshd

Installing SSH Client

Local Port Forwarding

Definition and Usage

Examples

Forwarding Database Traffic

ssh -L 4000:127.0.0.1:3306 user@example.com

Forwarding Multiple Ports

ssh -L 5901:127.0.0.1:5901 -L 4000:127.0.0.1:3306 user@example.com
Note
  VNC stands for Virtual Network Computing. It is a graphical desktop sharing system that allows users to remotely control and interact with graphical desktops of computers or servers over a network connection.

Forwarding to Internal Servers

ssh -L 4000:server003.local:3306 user@example.com

Remote Port Forwarding

Definition and Usage

Examples

Sharing Local Web Application

ssh -R 7000:127.0.0.1:8000 user@example.com

Configuring Remote Access to Local Resources

ssh -R 8080:192.168.100.1:8000 user@example.com

Dynamic Port Forwarding

Definition and Usage

Configuring Dynamic Port Forwarding

ssh -D 4000 user@example.com

Applications and Settings

Additional Tips and Best Practices

Disabling Shell and Running in Background

Considerations for Proxy Usage


Nadir Habib 2024/03/30 21:17