SSH Tunneling

SSH Tunneling

What is SSH Tunneling?
SSH tunneling is used to securely access private services that are not exposed to the internet.

  • It works only over SSH
  • It uses port 22 to encrypt and forward traffic
  • It can carry other traffic like HTTP, databases, or RDP

Why do we need SSH Tunneling?
Some services are internal only and cannot be accessed directly:

  • Databases (MySQL, PostgreSQL)
  • Internal web applications
  • Admin dashboards
  • RDP or SSH on other machines

Exposing these services to the internet would be insecure.

Solution: An SSH tunnel allows access to these internal services through one secure entry point: 👉 SSH (port 22).

Security (encryption)
Some services:

  • Don’t encrypt traffic
  • Use weak auth
  • Were never designed for the public internet

SSH tunnel:

  • Encrypts everything
  • Hides credentials
  • Protects against sniffing

Example

ssh -L 9000:localhost:80 10.5.2.1

What happens here?

  • Server 10.5.2.1 runs:

    • SSH (port 22)
    • A web service (port 80)
  • Alice:

    1. Runs the SSH command (ssh -L 9000:localhost:80 10.5.2.1)
    2. Logs in successfully
    3. Opens her browser and goes to: http://localhost:9000

-L: Means local port

➡️ This securely connects her to the web service on 10.5.2.1 without server exposing the webservice to the internet.

Difference between SSH login vs SSH Tunneling

Command Meaning
ssh user@ip Remote login
ssh -L / -R / -D SSH tunneling (port forwarding)

Articles recommended by the author

References

Leave a Reply

Your email address will not be published. Required fields are marked *


© 2026 A. Maharjan