clash for linux
Clash 是一个使用 Go 语言编写,基于规则的跨平台代理软件核心程序。
下载
| 1 | wget https://github.com/Dreamacro/clash/releases/download/v1.13.0/clash-linux-amd64-v1.13.0.gz | 
最新版本 https://github.com/Dreamacro/clash/releases
安装
解压后直接执行,将在~/.config/目录下生成一个clash目录,其中有配置文件
| 1 | gzip -d clash-linux-amd64-v1.13.0.gz | 
为了后期管理方便,可以之间将解压后的clash拷贝到~/.config/clash目录下,并重命名为clash
| 1 | cp ./clash-linux-amd64-v1.13.0 ~/.config/clash/clash | 
配置
下载配置文件
| 1 | wget -O config.yaml "代理商提供的订阅链接" | 
如果下载到的是一大堆字符则需要在订阅链接的后面添加 &flag=clash
执行./clash,将会下载Country.mmdb
| 1 | ./clash | 
如果下载失败进行手动下载
| 1 | ./clash | 
| 1 | wget -O Country.mmdb https://www.sub-speeder.com/client-download/Country.mmdb | 
在 https://github.com/Dreamacro/maxmind-geoip/releases 下载也可以
以上准备配置文件弄号后就可以运行
| 1 | ~/.config/clash | 
在clash启动后用浏览器访问网址http://clash.razord.top/ ,在这里修改配置信息
配置代理
系统代理配置——浏览器生效

命令行设置:
| 1 | gsettings set org.gnome.system.proxy.http host '127.0.0.1' | 
git代理
https传输
- http代理 - 1 
 2- git config --global http.proxy 'http://127.0.0.1:1080' 
 git config --global https.proxy 'http://127.0.0.1:1080'
- socks5代理 - 1 
 2- git config --global http.proxy 'socks5://127.0.0.1:1081' 
 git config --global https.proxy 'socks5://127.0.0.1:1081'
- 取消代理 - 1 
 2- git config --global --unset http.proxy 
 git config --global --unset https.proxy
ssh传输
通过 netcat 或 ssh-connect 可以建立连接以供 ssh 使用。
修改 OpenSSH 的 config 文件(Unix/Linux/Git-Bash:~/.ssh/config),添加如下内容之一
netcat
- http代理1 
 2
 3
 4Host github.com 
 HostName github.com
 User git
 ProxyCommand nc -v -X connect -x 127.0.0.1:1080 %h %p
- socks5代理1 
 2
 3
 4Host github.com 
 HostName github.com
 User git
 ProxyCommand nc -v -x 127.0.0.1:1081 %h %p
ssh-connect
- http代理 - 1 
 2
 3
 4- Host github.com 
 HostName github.com
 User git
 ProxyCommand connect -H 127.0.0.1:1080 %h %p
- socks5代理 - 1 
 2
 3
 4- Host github.com 
 HostName github.com
 User git
 ProxyCommand connect -S 127.0.0.1:1081 %h %p
命令行下载代理——proxychains
需要socks代理端口
| 1 | sudo apt install proxychains | 
ProxyChains 的配置文件位于 /etc/proxychains.conf ,打开后你需要在末尾添加你使用的代理。
| 1 | [ProxyList] | 
- 测试
| 1 | proxychains ping www.google.com | 
- 解决方法:
查找libproxychains.so.3位置
| 1 | whereis libproxychains.so.3 | 
修改/usr/bin/proxychains
| 1 | !/bin/sh | 
代理与source执行
在需要代理并通过source执行脚本时,可以使用以下方法:
| 1 | proxychains bash -c source install.sh | 
代理与sudo
| 1 | sudo proxychains apt-get update | 
clash的自启动
| 1 | pkill -9 clash # 先杀死之前的进程 | 
创建一个auto_run.sh脚本
| 1 | nohup $HOME/.config/clash/clash -d $HOME/.config/clash/ > /dev/null 2>&1 & | 
将clash注册为systemctl服务 /usr/lib/systemd/system下新建一个文件clash.service 填入内容
| 1 | sudo vim /usr/lib/systemd/system/clash.service | 
根据实际配置路径进行修改
| 1 | 重新加载配置文件 | 
自动更新配置文件
配置文件信息是会更新的,我们也需要定时地更新本地的配置文件
| 1 | wget -O /home/your_name/.config/clash/config.yaml "订阅链接" | 
使用linux自带的cron定时器,设定每日都运行一遍
| 1 | crontab -e # 编辑定时任务 | 
每天的
20:25定时执行更新命令
参考
- 如何在Linux中使用Clash
- CLash for Linux 安装配置
- 如何在 Linux 上优雅的使用 Clash? —— Docker