Clash on Linux

在 Linux 上安装 Clash 客户端

首先在 Linux 上下载 Clash For Windows

Github release 链接:https://github.com/Fndroid/clash_for_windows_pkg/releases

1
2
[root@stream9 ~]# wget https://github.com/Fndroid/clash_for_windows_pkg/releases/download/0.20.18/Clash.for.Windows-0.20.18-x64-linux.tar.gz
#没有代理会下载的比较慢

image-20230311184509324

1
2
3
4
[root@stream9 ~]# tar -xf Clash.for.Windows-0.20.18-x64-linux.tar.gz -C /mnt/
[root@stream9 ~]# cd /mnt/
[root@stream9 mnt]# mv Clash\ for\ Windows-0.20.18-x64-linux/ clash
[root@stream9 mnt]# cd clash/

image-20230311185028114

1
2
3
4
5
6
# 解压后会出现对应的文件夹,文件夹中会有一个名为 cfw 的文件,按理说现在在文件中直接打开终端,然后运行
[root@stream9 clash]# ./cfw
[0311/185145.670804:FATAL:electron_main_delegate.cc(292)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
Trace/breakpoint trap (core dumped)

`不过 root 用户需要加上 --no-sandbox 参数才支持,普通用户则不需要,直接 ./cfw 即可

image-20230311185454175

现在可以导入 Clash 代理节点了

Terminal 代理

Terminal 局部代理(只在当前用户生效)

1
2
3
4
5
6
7
8
[root@stream9 ~]# vim .bashrc 
... 在最下方添加以下命令 ...
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890

[root@stream9 ~]# bash
[root@stream9 ~]# curl www.google.com
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage".........

Terminal 全局代理(对所有用户生效)

1
2
3
4
5
6
7
8
[root@stream9 ~]# vim /etc/bashrc 
... 在最下方添加以下命令 ...
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890

[lai@stream9 ~]$ bash
[lai@stream9 ~]$ curl www.google.com
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage".........

顺便说一句,Linux 版本 Clash 客户端无法自动设置系统代理,需要自己手动设置

配置快速启动图标

1
2
3
4
- 软链接我们解压出的 cfw 到对应路径下,注意不要直接 cp 过去,会找不到动态库。
[root@stream9 bin]# ln -s /mnt/clash/cfw /usr/bin/clash

# 这时可以在任意路径下敲命令 clash 或 clash --no-sandbox

image-20230311203248574

但最快捷的方法还是创建一个桌面图标(快捷方式)

首先需要明白的是这个里面的每个快捷方式,其实都是解析一个文件得到的,这些文件都存在于 /usr/share/applications/ 中,文件名为 .desktop

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
- 下载Logo图片(注意:要开代理下载)
[root@stream9 mnt]# wget https://upload.wikimedia.org/wikipedia/commons/0/0b/Clash_Logo.png
[root@stream9 mnt]# ls
clash Clash_Logo.png hgfs

- 创建一个'clash.desktop',文件内容如下:
[root@stream9 ~]# vim /usr/share/applications/clash.desktop
[Desktop Entry]
Name=Clash Fow Windows
Exec=/usr/bin/clash --no-sandbox
Icon=/mnt/Clash_Logo.png
Type=Application
StartupNotify=true

保存退出,图标就创建好了
关键词 意义
[Desktop Entry] 文件头
Name 应用名称
Comment 描述
Exec 执行的命令
Icon 图标路径
Type 启动器类型
Categories 应用的类型(内容相关)
StartupNotify 启动时是否打印输出信息
Terminal 是否在终端中运行

image-20230311204155796

注意,在 /usr/share/applications 路径下创建的 .desktop 文件是对所有用户生效的;

如果只需要在当前用户(如 root)下生成应用的桌面图标,则放在~/.local/share/applications/clash.desktop路径下

1
2
- 如下 ↓
[root@stream9 ~]# mv /usr/share/applications/clash.desktop ~/.local/share/applications/

扩展(安装 Chrome)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
- 配置'google-chrome'的repo源
[root@stream9 ~]# vim /etc/yum.repos.d/google.repo
[google-chrome]
name=google-chrome - 64-bit
baseurl=http://dl.google.com/linux/chrome/rpm/stable/x86_64
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub

[root@stream9 ~]# dnf clean all
[root@stream9 ~]# dnf repolist
[root@stream9 ~]# dnf makecache

- 搜索chrome的包
[root@stream9 ~]# dnf search chrome
Last metadata expiration check: 0:00:18 ago on Sat 11 Mar 2023 09:27:47 PM CST.
=============================================================== Name & Summary Matched: chrome ===============================================================
google-chrome-beta.x86_64 : Google Chrome (beta)
google-chrome-stable.x86_64 : Google Chrome
google-chrome-unstable.x86_64 : Google Chrome (unstable)
==================================================================== Name Matched: chrome ====================================================================
chrome-gnome-shell.x86_64 : Support for managing GNOME Shell Extensions through web browsers

[root@stream9 ~]# dnf list | grep chrome
chrome-gnome-shell.x86_64 10.1-14.el9 @AppStream
google-chrome-beta.x86_64 112.0.5615.20-1 google-chrome
google-chrome-stable.x86_64 111.0.5563.64-1 google-chrome
google-chrome-unstable.x86_64 113.0.5638.0-1 google-chrome

- 安装'google-chrome-stable'(# 可能需要走代理才能安装成功)
[root@stream9 ~]# dnf -y install google-chrome-stable.x86_64

- 启动chrome
[root@stream9 ~]# google-chrome --no-sandbox
# 非root用户不需要加--no-sandbox

image-20230311213743586

1
2
3
4
- 查看chrome的桌面图标
[root@stream9 ~]# ls /usr/share/applications/ | grep -i chrome
google-chrome.desktop
org.gnome.ChromeGnomeShell.desktop

image-20230311214802252

但是单击 chrome 谷歌图标,会无响应,普通用户则可以正常打开 chrome

原因:默认用户是root,但是谷歌不让 root 用户打开它,防止 root 权限进行破坏操作,所以需要一些操作关掉谷歌的沙盒模式

1
2
3
- 修改chrome的启动项配置
[root@stream9 ~]# vim /opt/google/chrome/google-chrome
# 找到如下最后一行代码

image-20230311215048631

1
2
- 添加一行'--user-data-dir --no-sandbox'
exec -a "$0" "$HERE/chrome" "$@" --user-data-dir --no-sandbox

image-20230311215427918

此时便可以愉快的玩转 Google 了。

打开 Clash,在 Google 设置局部代理;

Setting —> 搜索proxy

image-20230311215956479

image-20230311220044363 image-20230311220122814

Okay,代理设置完毕,可以正常访问 Google ~