TL;DR
This guide shows how to add authentication (username and password) when connecting through an HTTP proxy server for tunneling, using common tools like SSH and curl. We’ll cover setting up SSH config files and passing credentials with curl.
SSH Tunneling with Proxy Authentication
- Edit your SSH configuration file: Open
~/.ssh/configin a text editor. If the file doesn’t exist, create it.nano ~/.ssh/config - Add a host entry for your proxy: This tells SSH how to connect through the proxy.
Host myproxy Hostname your.proxy.server User your_username ProxyCommand nc -X connect -x your.proxy.server:8080 %h %pReplace:
myproxywith a name you choose for the proxy connection.your.proxy.serverwith the actual hostname or IP address of your proxy server.your_usernamewith your username for the proxy.8080with the port number your HTTP proxy uses.
- Add a host entry for the target server: Configure SSH to use the proxy when connecting to your final destination.
Host targetserver Hostname your.target.server User your_target_username ProxyCommand ssh myproxy nc %h %pReplace:
targetserverwith a name for the target server connection.your.target.serverwith the hostname or IP address of the target server.your_target_usernamewith your username on the target server.
- Connect to the target server: Now you can connect using SSH as normal.
ssh targetserverSSH will prompt you for your proxy password when connecting through
myproxy, and then for your target server password.
curl with HTTP Proxy Authentication
- Using the command line: Pass your username and password directly in the curl command.
curl -x http://your_username:[email protected]:8080 https://www.example.comReplace:
your_usernamewith your proxy username.your_passwordwith your proxy password.your.proxy.serverwith the hostname or IP address of your proxy server.8080with the port number your HTTP proxy uses.
- Using environment variables: Set the
http_proxyandhttps_proxyenvironment variables.export http_proxy=http://your_username:[email protected]:8080curl https://www.example.comThis will use the proxy with authentication for all curl requests.
- Using a .netrc file: Store your credentials in a
~/.netrcfile (securely!).machine your.proxy.server login your_username password your_passwordThen use the following curl command:
curl -x http://your.proxy.server https://www.example.comEnsure the
~/.netrcfile has appropriate permissions (e.g.,chmod 600 ~/.netrc) to protect your credentials.

