Skip to content

Instantly share code, notes, and snippets.

@antiops
Created March 11, 2023 04:00
Show Gist options
  • Save antiops/e01928e29b8955cd4b0bc604efbea7ef to your computer and use it in GitHub Desktop.
Save antiops/e01928e29b8955cd4b0bc604efbea7ef to your computer and use it in GitHub Desktop.
Set up SOCKS proxy for rclone

SOCKS5 Proxy for rclone CLI/Mount using Docker

Docker Image: https://github.com/serjs/socks5-server

  • YourUsername: Unique username for SOCKS proxy
  • YourPassword: Unique password for SOCKS proxy
  • RemoteSocksHost: IP or hostname of remote server running the proxy

SOCKS Server

Start a SOCKS5 server on the remote host that all rclone data will go through

docker run --restart=always -d --name socks5 -p 0.0.0.0:1080:1080 -e PROXY_USER=YourUsername -e PROXY_PASSWORD=YourPassword -e PROXY_PORT=1080 serjs/go-socks5-proxy

'override' script

Write to a file in ~/bin called rclone or rcx.

#!/bin/bash

http_proxy=socks5://YourUsername:YourPassword@RemoteSocksHost:1080
https_proxy=$http_proxy
HTTP_PROXY=$http_proxy
HTTPS_PROXY=$http_proxy

rclone "$@"

Ensure ~/bin is in $PATH and use rclone or rcx like normal


System-Wide Proxy

  • Not recommended, last resort. Any tool will use this environment variable and can break other tools

in ~/.bashrc` write:

export http_proxy=socks5://YourUsername:YourPassword@RemoteSocksHost:1080
export https_proxy=$http_proxy
export HTTP_PROXY=$http_proxy
export HTTPS_PROXY=$http_proxy

Run source ~/.bashrc


Systemd Service

If rclone is running as a service add the below under the [Service] line un the file

Environment="http_proxy=socks5://YourUsername:YourPassword@RemoteSocksHost:1080"
Environment="https_proxy=socks5://YourUsername:YourPassword@RemoteSocksHost:1080"
Environment="HTTP_PROXY=socks5://YourUsername:YourPassword@RemoteSocksHost:1080"
Environment="HTTPS_PROXY=socks5://YourUsername:YourPassword@RemoteSocksHost:1080"

Restart the service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment