SSH SOCKS5 proxy
Written by masteryeti on .
This article is about creating a tunnel to a remote server that will be instructed to act as a proxy server.
It only needs ssh
on the local machine, and an sshd
-service on the remote server, which is usually already installed on Linux.
A proxy may be used to access the internet through the remote server's internet connection.
The following command creates a local SOCKS5 proxy to a remote server. This is basically a port to an ssh-tunnel to the remote server, using the SOCKS5 protocol, so that it may use the remote server's internet connection. A local application (such as an internet browser) can make use of this, by configuring the SOCKS5 proxy in the settings of that application. Sometimes a system-wide SOCKS5 proxy is also possible at the network/wifi/ethernet settings.
ssh -D 1337 -q -C -N -p 22 username@example.com
-
ssh
is the client program to open an ssh-connection to the server. The server must have thesshd
service running. -
-D 1337
specifies the local bind port, this is what must be configured in the local application or system that uses the proxy. -
-q
surpresses verbose output from ssh. -
-C
enables compression in order to lower bandwidth at the cost of additional computational power. -
-N
is there to say that no command will be passed to execute. -
-p 22
is redundant if the port is 22, since that is the default. But this option may be used to specify an alternative port on which to connect to the remote sshd service. -
username@example.com
is respectively the username to authenticate, and the domain name at which to connect to the remote sshd service. An IPv4 or IPv6 address may also be used instead of a domain name.
The above command will keep running until interrupted, an error occurred, or it is killed.
To stop the command gracefully, use <CTRL+C>
.
In order to make use of the created proxy tunnel, manually configure the application or system like so:
- SOCKS Host:
localhost
(or use:127.0.0.1
)- SOCKS Port:
1337
- SOCKS Version:
- SOCKS v5
Additionally, you may choose an option to also proxy DNS (Domain Name System) when using SOCKS v5, which is recommended for improving privacy.