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.
- Use ssh to access the target machine.
- Install mihomo(
wget LINK
;dpkg -i FILE.deb
) - Use
mihomo
to run the program. - (Optional) Manually download the geoip database and put it in the same directory as the core.
- Add a valid
external-controller
in the config file. (e.g.external-controller:9090
) - 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. - Add
export http(s)_proxy=http://127.0.0.1:PORT
to the shell profile(.bashrc
) and reload the shell. - 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 byexternal-controller
in config.yaml) (target is the ssh config target)(You can also use0.0.0.0
to listen from all addresses) - 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.