How to create a SSH tunnel or proxy channel in Linux

Published on Aug. 22, 2023, 12:14 p.m.

To create a SSH tunnel or proxy channel, you can use the SSH command-line tool with the -L option. Here is an example command:

ssh -L local_port:target_host:target_port user@ssh_server

In this command, local_port is the port number on your local machine that you want to use to access the remote service on target_host:target_port. user is your username on the SSH server, and ssh_server is the hostname or IP address of the SSH server. For example, to create a SSH tunnel to access a web service running on port 80 of example.com, you can use this command:

ssh -L 8080:example.com:80 user@ssh_server

After running this command and authenticating with the SSH server, you can access the web service on your local machine by opening a web browser and going to http://localhost:8080. Note that you may need to configure firewalls or security groups to allow the SSH traffic and the traffic on the forwarded port.

available for Chrome

There are many proxy plugins available for Chrome, but here are three popular ones:

FoxyProxy: This is a versatile extension that allows you to easily switch between different proxy configurations. You can set up rules to automatically switch between different proxies based on website URLs, IP addresses, and other criteria.

Proxy SwitchyOmega: This extension lets you configure multiple proxies and switch between them with a single click. You can create profiles for different proxy configurations and easily switch between them.

ZenMate VPN: This is a VPN service that also offers a Chrome extension. It encrypts your traffic and routes it through a remote server, making it difficult for others to intercept your browsing data.

It’s important to note that while browser extensions can be useful for adding an extra layer of privacy and security to your online activities, they may not be suitable for all use cases. If you require a high level of security, you may want to consider using a standalone VPN client or configuring a SOCKS proxy using the instructions provided in my previous answer.

To use a proxy in a Bash shell on Linux, you can set the HTTP_PROXY and HTTPS_PROXY environment variables. Here’s how:

Open a terminal window.

Set the HTTP_PROXY and HTTPS_PROXY variables to the proxy address and port. For example, if the proxy server is running at 192.168.1.100 on port 8080, you can set the variables like this:

export HTTP_PROXY=http://192.168.1.100:8080
export HTTPS_PROXY=https://192.168.1.100:8080

Alternatively, if your proxy server requires authentication, you can set the variables like this:

export HTTP_PROXY=http://username:[email protected]:8080
export HTTPS_PROXY=https://username:[email protected]:8080

To make the environment variables persist across terminal sessions, you can append the commands to your .bashrc file:
echo “export HTTP_PROXY=http://192.168.1.100:8080” >> ~/.bashrc
echo “export HTTPS_PROXY=https://192.168.1.100:8080” >> ~/.bashrc

Note that some programs may not use these environment variables by default. For example, Git may require additional configuration. You may need to consult the documentation for the specific program you’re using to ensure that it’s using the proxy.

To use a proxy with Git on Linux

To use a proxy with Git on Linux, you can set the HTTP_PROXY and HTTPS_PROXY environment variables in your terminal session or in your Git configuration. Here’s how:

Set the HTTP_PROXY and HTTPS_PROXY variables to the proxy address and port. For example, if the proxy server is running at 192.168.1.100 on port 8080, you can set the variables like this in your terminal session:
export HTTP_PROXY=http://192.168.1.100:8080
export HTTPS_PROXY=https://192.168.1.100:8080
Alternatively, you can set the proxy variables in your Git configuration. To do this for all repositories, run the following command:
git config –global http.proxy http://192.168.1.100:8080
git config –global https.proxy https://192.168.1.100:8080
If your proxy server requires authentication, you can include your username and password in the URL or set the proxy credentials in your Git configuration. To set them in your configuration, run the following command:
git config –global http.proxy http://username:[email protected]:8080
git config –global https.proxy https://username:[email protected]:8080
Note that some Git servers may require additional configuration to work properly with a proxy. You may need to consult the documentation for the specific Git server you’re using to ensure that it’s correctly configured.

Tags: