logo头像

aferica

Ubuntu安装ssr客户端

本文于621天之前发表,文中内容可能已经过时。

使用自己的API时,有些时候访问的地址需要翻墙获取数据,此时,就可以通过ssr来在服务器访问,然后获取信息,这样就可以将翻墙工作都放在服务器执行
文章参考来源于在 Ubuntu 上使用 SSR 梯子

安装客户端

1
2
3
4
5
6
7
8
9
10
11
12
# 创建ssr文件
vim ssr
# 复制内容(查看文末)并保存

# 将其加到 $PATH 环境变量里(不必和我一样的目录,只要保证 SSR 文件能在 PATH 里找到即可)
sudo mv ssr /usr/local/bin

# 加入可执行权限
sudo chmod 766 /usr/local/bin/ssr

# 安装
ssr install

使用

使用config命令,配置服务器,一般来说保存config会自动启动生效

1
ssr config

ssr文件内容

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/bash
# 作者:老徐
# SSR免费分享网站(所有帐号均来源于网上别人的分享):http://ss.pythonic.life
# 源代码主页:https://github.com/the0demiurge
# 访问https://github.com/the0demiurge/CharlesScripts/blob/master/charles/bin/ssr获取本脚本的最新版
# 使用方法:把该脚本放到$PATH里面并加入可执行权限就行(比如说放到/usr/local/bin)
# 首次使用输入ssr install后安装时会自动安装到 $HOME/.local/share/shadowsocksr
# 输入ssr config进行配置,输入JSON格式的配置文件
# 输入ssr uninstall卸载
# 输入ssr help 展示帮助信息

set -e
if [ -z "$EDITOR" ]; then
EDITOR=vi
fi

WEBSITE=http://ss.pythonic.life
BRANCH=manyuser
GIT_REPO=https://github.com/shadowsocksrr/shadowsocksr.git
INSTALL_PATH=$HOME/.local/share/shadowsocksr

ssr_help() {
echo ShadowSocksR python client tool
echo -e if you have not installed ssr, run \`ssr install\` first
echo Usage:
echo -e "\t" "ssr help"
echo -e "\n" "Install/Uninstall"
echo -e "\t" "ssr install install shadowsocksr client"
echo -e "\t" "ssr uninstall uninstall shadowsocksr client"
echo -e "\n" "Config and Subscribe"
echo -e "\t" "ssr update update subscription from $WEBSITE"
echo -e "\t" "ssr config edit config.json"
echo -e "\t" "ssr xclip paste configs from clipboard to config.json"
echo -e "\n" "Start/Stop/Restart"
echo -e "\t" "ssr start start the shadowsocks service"
echo -e "\t" "ssr stop stop the shadowsocks service"
echo -e "\t" "ssr restart restart the shadowsocks service"
echo -e "\n" "Testing and Maintenance"
echo -e "\t" "ssr test get ip from cip.cc using socks5 proxy"
echo -e "\t" "ssr log cat the log of shadowsocks"
echo -e "\t" "ssr shell cd into ssr installation dir"
echo -e "\t" "ssr clean clean ssr configuration backups"
}

ssr_install() {
git clone -b $BRANCH $GIT_REPO $INSTALL_PATH
echo -e "Install finished!\nYou can visit my website $WEBSITE to acquire free ssr configs"
}

ssr_uninstall() {
echo "Danger! are you to remove $INSTALL_PATH forever?(y/N)"
read doit
if [ $doit == 'y' ]; then rm -rvf $INSTALL_PATH; fi
}

ssr_test() {
echo Testing Connection...
if [[ ! -z $(which jq 2>/dev/null) ]]; then
echo 'jq in use'
PORT=$(jq .local_port $INSTALL_PATH/config.json)
else
PORT=$(sed -r 's/\/\/.*$|\s+//g' $INSTALL_PATH/config.json | grep -oP '(?<!//)(?<="local_port":)\d+')
echo "local_port is $PORT; if any exceptions orrured, please install jq"
fi

echo 'connection information:'
curl ipinfo.io --socks5 localhost:$PORT
echo
curl cip.cc --socks5 localhost:$PORT

if [ $? == 0 ]; then
if [[ -z $(which proxychains4 2>/dev/null) ]]; then
echo "You may install proxychains4 and configure it properly to test net delay"
else
echo -e '\nChecking delay...'
proxychains4 ping -c 5 cip.cc
fi
fi
}

ssr_start() {
cd $INSTALL_PATH/shadowsocks/
python local.py -d start --pid-file=$INSTALL_PATH/ssr.pid --log-file=$INSTALL_PATH/ssr.log
sleep 1
ssr_test
}

ssr_stop() {
cd $INSTALL_PATH/shadowsocks/
python local.py -d stop --pid-file=$INSTALL_PATH/ssr.pid --log-file=$INSTALL_PATH/ssr.log
}

ssr_restart() {
ssr_stop
ssr_start
}

ssr_config() {
$EDITOR $INSTALL_PATH/config.json
ssr_restart
}

BLOCKED='
Update failed! For more information, see
https://github.com/the0demiurge/ShadowSocksShare-OpenShift/issues/17
And edit `$WEBSITE` in this script.'

ISSUE='
The response was empty, try it 10 mins later or report it on
https://github.com/the0demiurge/CharlesScripts/issues'

ssr_update() {
JSON=$(curl -L $WEBSITE/json)
# If failed
case $? in
0) ;;
*)
echo -e $BLOCKED
exit $?
;;
esac

# If json is empty
case $JSON in
'Not Found')
echo -e $BLOCKED
exit $?
;;
'' | '{}')
echo $ISSUE
exit 2
;;
esac

mv $INSTALL_PATH/config.json $INSTALL_PATH/config.json.bak.$(date +%y-%m-%d-%T)
echo -e "$JSON" | tee $INSTALL_PATH/config.json
ssr_restart
echo -e "Updated from $WEBSITE"
}

ssr_xclip() {
xclip -o | tee $INSTALL_PATH/config.json
ssr_restart
}

ssr_log() {
tail -f $INSTALL_PATH/ssr.log
}

ssr_shell() {
cd $INSTALL_PATH
$SHELL
}

ssr_clean() {
rm -ri $INSTALL_PATH/config.json.bak.*
}

ssr_main() {
case $1 in
help) ssr_help ;;
install) ssr_install ;;
uninstall) ssr_uninstall ;;
update) ssr_update ;;
config) ssr_config ;;
xclip) ssr_xclip ;;
start) ssr_start ;;
stop) ssr_stop ;;
restart) ssr_restart ;;
test) ssr_test ;;
log) ssr_log ;;
shell) ssr_shell ;;
clean) ssr_clean ;;
*) ssr_help ;;
esac
}

ssr_main $1
微信打赏

你的赞赏是对我最大的鼓励