---
title: 'Use SSH as SOCKS 5 proxy'
url: 'https://kb.hills-family.uk/blog/use-ssh-as-socks-5-proxy'
markdown: 'https://kb.hills-family.uk/blog/use-ssh-as-socks-5-proxy.md'
date: '2021-04-10'
description: 'I recently needed to access a resource that was only available from a remote Linux PC (i.e. my machine → remote Linux PC → network resource). The problem? There’s no GUI, no X Server I only have SSH access. The solution? One option is to set up a local port forward (ssh -L local_socket:host:host_socket), but this is limited to only a single end point and won’t work if the remote network resource redirects traffic to another port. This would work if we are, for example, talking to a web server over HTTP (port 80), but we would need to create a separate rule for HTTPS (port 443) and any other port required (e.g. for web sockets). Fortunately, anothe'
taxonomy:
  tag:
    - Linux
    - SSH
---

# Use SSH as SOCKS 5 proxy

[ Home ](https://kb.hills-family.uk/)     [ Blog ](https://kb.hills-family.uk/blog)      Use SSH as SOCKS 5 proxy    

   10 *Apr*   
#### [Use SSH as SOCKS 5 proxy](https://kb.hills-family.uk/blog/use-ssh-as-socks-5-proxy)

  [Linux](https://kb.hills-family.uk/blog/tag:Linux) [SSH](https://kb.hills-family.uk/blog/tag:SSH)  

I recently needed to access a resource that was only available from a remote Linux PC (i.e. my machine → remote Linux PC → network resource). The problem? There’s no GUI, no X Server I only have SSH access. The solution? One option is to set up a local port forward (`ssh -L local_socket:host:host_socket`), but this is limited to only a single end point and won’t work if the remote network resource redirects traffic to another port. This would work if we are, for example, talking to a web server over HTTP (port 80), but we would need to create a separate rule for HTTPS (port 443) and any other port required (e.g. for web sockets).

Fortunately, another solution exists whereby I can use the remote Linux PC as a proxy server, essentially letting me work as if I was on the remote Linux PC instead of my machine. This solution involves using the SSH tunnel to the remote Linux PC as a local dynamic application-level port forward and treating the connection as a proxy. This can be activated from terminal using:

```bash
ssh -D 8080 -C2qTnN username@remote_linux_pc_address
```

This command will connect to `remote_linux_pc_address` using `username` and configure SSH as follows:

- `-D 8080` establishes a local port listener at port 8080 that you can attach a browser to use it as a SOCKS 5 proxy.
- `-C` enable compressions.
- `-2` uses SSH version 2 *only*.
- `-q` supresses warnings and diagnostic messages.
- `-T` disables pseudo-terminal (tty) allocation.
- `-n` redirects `stdin` to `/dev/null`, thus prevening reading of `stdin`.
- `-N` tells SSH not to execute a remote command.

Next, set up a web browser to use a SOCKS 5 proxy with hostname `localhost` (or `127.0.0.1`) and port `8080`.

**Note:** If the web browser doesn’t respond, it’s possible the SSH connection has dropped.

 [ Next Post](https://kb.hills-family.uk/blog/when-you-dont-have-curl)

#### Knowledge Base

Tips, tricks and how-to guides on various topics.

#### Popular Tags

  [Linux](https://kb.hills-family.uk/blog/tag:Linux) [Dynamics AX](https://kb.hills-family.uk/blog/tag:Dynamics%20AX) [D365 Finance and Operations](https://kb.hills-family.uk/blog/tag:D365%20Finance%20and%20Operations) [Network](https://kb.hills-family.uk/blog/tag:Network) [Data Management Framework](https://kb.hills-family.uk/blog/tag:Data%20Management%20Framework) [Logic Apps](https://kb.hills-family.uk/blog/tag:Logic%20Apps) [JavaScript](https://kb.hills-family.uk/blog/tag:JavaScript) [netcat](https://kb.hills-family.uk/blog/tag:netcat) [SSH](https://kb.hills-family.uk/blog/tag:SSH) [PowerShell](https://kb.hills-family.uk/blog/tag:PowerShell) [Virtual Machines](https://kb.hills-family.uk/blog/tag:Virtual%20Machines) [VMware](https://kb.hills-family.uk/blog/tag:VMware) [SQL Server](https://kb.hills-family.uk/blog/tag:SQL%20Server) [Wireshark](https://kb.hills-family.uk/blog/tag:Wireshark) [Python](https://kb.hills-family.uk/blog/tag:Python) [Licensing](https://kb.hills-family.uk/blog/tag:Licensing) [Ubuntu](https://kb.hills-family.uk/blog/tag:Ubuntu)

---

## Navigation

- Parent: [Blog](https://kb.hills-family.uk/blog.md)
- Previous: [When you don't have curl...](https://kb.hills-family.uk/blog/when-you-dont-have-curl.md)
