Post

Run clash over ssh

Clash operates as a proxy tool. There are many GUI wrapper over the core.

But when remote developing a server via ssh, it would be useful to find an elegant method to run the proxy.

Clash would open a web server and allow users to control the program via web api.

The goal of this tutorial is to set up a clash core on cli and use ssh to run reverse proxy to control the core via web app.

  1. Use ssh to access the target machine.
  2. Install mihomo(wget LINK; dpkg -i FILE.deb)
  3. Use mihomo to run the program.
  4. (Optional) Manually download the geoip database and put it in the same directory as the core.
  5. Add a valid external-controller in the config file. (e.g. external-controller:9090)
  6. Write/Copy a valid config file and rerun the program. The config file would be stored at ~/.config/mihomo/config.yaml. The file would be auto created if not found.
  7. Add export http(s)_proxy=http://127.0.0.1:PORT to the shell profile(.bashrc) and reload the shell.
  8. Use ssh -L 9090:127.0.0.1:9090 -N target to run the reverse proxy. (The first 9090 is the local port, 127.0.0.1:9090 is the core’s web port set by external-controller in config.yaml) (target is the ssh config target)(You can also use 0.0.0.0 to listen from all addresses)
  9. Use a web dashboard(e.g. metacube) to control the core.
    • The server hosted dashboard seems to be unable to access the core’s web api via ip address, so the reverse proxy is needed.
This post is licensed under CC BY 4.0 by the author.