Setting up an SSH tunnel on MacOS allows you to securely route your internet traffic through a remote server. Here’s how you can do it:
-
Requirements:
- A remote server running SSH and capable of making outbound connections to the internet.
- A user account on the remote server that can log in via SSH.
- Access to the Terminal application on your Mac (located in
/Applications/Utilities/Terminal). - Access to the Network section in System Preferences or an alternative browser (like Firefox) that accepts locally configured proxy connections.
-
Setting Up the SSH Tunnel:
- Open Terminal on your Mac (you can find it in the Utilities folder within Applications).
- Execute the following command, replacing the placeholders:
ssh -f -N -M -S /tmp/sshtunnel -D 1080 [email protected] -p22- Replace
USERwith the username on the remote server (preferably an unprivileged user). - Replace
server.domain.comwith the hostname or IP address of your remote server. - Adjust the port number (
22by default) if your remote server uses a different SSH port.
- Replace
-
Configure the Proxy Service:
- Go to System Preferences > Network.
- Select your active network connection (Wi-Fi or Ethernet).
- Click “Advanced” > “Proxies.”
- Check the box next to “SOCKS Proxy” and enter
127.0.0.1for the SOCKS Proxy Server and1080for the port (the same as in the SSH command). - Click “OK” to save the settings.
-
Using a Browser:
- Open your preferred browser (e.g., Chrome).
- Configure the browser to use the SOCKS proxy:
- In Chrome, open a new tab and enter:
chrome --proxy-server="socks5://127.0.0.1:1080" --host-resolver-rules="MAP * 0.0.0.0, EXCLUDE localhost" - This will direct your browsing traffic through the encrypted SSH tunnel to the remote server.
- In Chrome, open a new tab and enter:
Remember that SSH tunnels are powerful tools for secure browsing, especially when dealing with restrictive firewalls or remote network issues