By Lin Jian
A controlled Linux tunnel proxy can use Squid for HTTP CONNECT and OpenSSH for access authentication and transport between the client and server. This setup keeps the proxy port off the public network and is suitable for a limited development or testing environment.
I separate installation, authentication, and request validation. A running process does not prove that the request path works.
Prepare a fresh test environment
Use a new Ubuntu server with sudo access and a working SSH account. The client needs OpenSSH and curl. The server must reach the approved test destination, and the SSH account must be permitted to use local TCP forwarding.
The configuration below uses Squid 6/7 directives. Check squid -v; do not assume that Squid 8 supports the same directives. The steps replace the main configuration on a fresh test server, so an existing production deployment requires a separate review.
Install Squid and restrict the destination
sudo apt update
sudo apt install squid curl
sudo cp -n /etc/squid/squid.conf /etc/squid/squid.conf.before-connect
Edit the file with sudoedit /etc/squid/squid.conf:
http_port 127.0.0.1:3128
acl local_client src 127.0.0.1/32
acl approved_target dstdomain .example.com
acl tls_port port 443
acl CONNECT method CONNECT
http_access allow local_client approved_target tls_port CONNECT
http_access deny all
cache deny all
This allows only local CONNECT requests to port 443 on example.com and its subdomains. Ordinary HTTP requests and other destinations are denied. For your task, add only authorized domains and review their resolution and redirects. Do not replace the rules with an unconditional allow.
Validate before restarting:
sudo squid -k parse
sudo systemctl restart squid
sudo systemctl status squid --no-pager
sudo ss -ltnp
Continue only after syntax validation and confirmation that the listener is 127.0.0.1:3128. On a syntax error, correct the configuration instead of restarting. To restore the original state, restore the backup, parse it, and then restart.
The Ubuntu installation guide and Squid access-control reference explain these operations.
Authenticate through SSH
Run this on the client after replacing the account and server placeholders:
ssh -N -o ExitOnForwardFailure=yes \
-L 127.0.0.1:18080:127.0.0.1:3128 \
YOUR_SSH_USER@YOUR_SERVER
Verify the server host-key fingerprint and use your approved SSH authentication method. -N runs no remote command; -L forwards client port 18080 to server loopback port 3128. The OpenSSH manual documents these options.
SSH authenticates the caller. Squid checks the local source and destination rules. Other processes on the server may also reach the loopback listener, so a shared host needs additional user isolation or proxy authentication. Loopback binding is not user-level isolation.
Check allowed and rejected requests
Keep SSH running. In another client terminal:
curl --noproxy '' --proxy http://127.0.0.1:18080 \
--connect-timeout 10 --max-time 30 https://example.com/
Confirm the expected page and normal TLS verification. The explicit empty proxy-exclusion list keeps this test from bypassing its selected proxy. The timeout values are tutorial settings, not performance claims.
Next, request an approved test domain outside the allowlist, such as https://example.org/. Squid should reject it. Inspect the server access log for the corresponding request, then stop SSH and confirm that the client can no longer use port 18080.
This verifies both access boundaries and dependence on the intended tunnel. For application-level configuration, see the HTTP proxy client guide.
Diagnose the failed stage
| Symptom | First checks |
|---|---|
| SSH fails | Server address, SSH port, authentication, network rules |
| Local port is occupied | Another client process listening on 18080 |
| Forwarding is prohibited | The SSH account's forwarding permissions |
| Squid denies the request | Destination domain, method, port rules |
| Certificate validation fails | System time, trust store, destination certificate |
| Timeout after CONNECT | Destination response, network path, timeout budget |
Do not disable certificate checks, open the firewall, and loosen access rules together. Doing so obscures the cause.
This setup does not rotate exits. The server network supplies the exit unless a separate upstream arrangement is added. See gateway routing versus session persistence before extending it. Successful transport also needs content acceptance checks in a data task.
Frequently asked questions
Is this an HTTP proxy or a SOCKS proxy?
The client uses HTTP. SSH -L forwards the TCP port, and Squid handles CONNECT. SSH -D is a different SOCKS-based arrangement.
Does this configuration automatically rotate the exit?
No. Rotation requires suitable upstream resources and additional configuration or management.
Can I open port 3128 publicly instead of using SSH?
Not by simply changing this example. Public access requires a separate design for encrypted transport, authentication, source restrictions, destination rules, and credential management.
About the author
Lin Jian writes about proxy integration, protocols, authentication, and troubleshooting.
Areas of focus: HTTP, HTTPS, and SOCKS5; proxy authentication; client configuration; timeout and connection diagnosis.