Shadowsocks Python版一键安装脚本

技术 秋水逸冰 2402696浏览 1333评论

本脚本适用环境:
系统支持:CentOS 6,7,Debian,Ubuntu
内存要求:≥128M
日期:2018 年 02 月 07 日

关于本脚本:
一键安装 Python 版 Shadowsocks 的最新版。
友情提示:如果你有问题,请先参考这篇《Shadowsocks Troubleshooting》后再问。

默认配置:
服务器端口:自己设定(如不设定,默认从 9000-19999 之间随机生成)
密码:自己设定(如不设定,默认为 teddysun.com)
加密方式:自己设定(如不设定,默认为 aes-256-gcm)
备注:脚本默认创建单用户配置文件,如需配置多用户,安装完毕后参照下面的教程示例手动修改配置文件后重启即可。

Shadowsocks for Windows 客户端下载:
https://github.com/shadowsocks/shadowsocks-windows/releases

使用方法:
使用root用户登录,运行以下命令:

wget --no-check-certificate -O shadowsocks.sh https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks.sh
chmod +x shadowsocks.sh
./shadowsocks.sh 2>&1 | tee shadowsocks.log

安装完成后,脚本提示如下:

Congratulations, Shadowsocks-python server install completed!
Your Server IP        :your_server_ip
Your Server Port      :your_server_port
Your Password         :your_password
Your Encryption Method:your_encryption_method

Welcome to visit:https://teddysun.com/342.html
Enjoy it!

卸载方法:
使用root用户登录,运行以下命令:

./shadowsocks.sh uninstall

单用户配置文件示例(2015 年 08 月 28 日修正):
配置文件路径:/etc/shadowsocks.json

{
    "server":"0.0.0.0",
    "server_port":your_server_port,
    "local_address":"127.0.0.1",
    "local_port":1080,
    "password":"your_password",
    "timeout":300,
    "method":"your_encryption_method",
    "fast_open": false
}

多用户多端口配置文件示例(2015 年 08 月 28 日修正):
配置文件路径:/etc/shadowsocks.json

{
    "server":"0.0.0.0",
    "local_address":"127.0.0.1",
    "local_port":1080,
    "port_password":{
         "8989":"password0",
         "9001":"password1",
         "9002":"password2",
         "9003":"password3",
         "9004":"password4"
    },
    "timeout":300,
    "method":"your_encryption_method",
    "fast_open": false
}

使用命令(2015 年 08 月 28 日修正):
启动:/etc/init.d/shadowsocks start
停止:/etc/init.d/shadowsocks stop
重启:/etc/init.d/shadowsocks restart
状态:/etc/init.d/shadowsocks status

更多版本 Shadowsocks 服务端一键安装脚本:
ShadowsocksR 版一键安装脚本(CentOS,Debian,Ubuntu)
CentOS 下 Shadowsocks-libev 一键安装脚本
Debian 下 Shadowsocks-libev 一键安装脚本
Shadowsocks-go 一键安装脚本(CentOS,Debian,Ubuntu)
Shadowsocks 一键安装脚本(四合一)

参考链接:
https://teddysun.com/339.html

更新日志

(2018 年 02 月 07 日)
1、修改:将默认端口从 8989 改为从 9000-19999 之间随机生成。

(2017 年 07 月 21 日)
1、修正:默认加密方式从 aes-256-cfb 改为 aes-256-gcm(官方原版客户端支持该加密方式);
2、新增:安装时可选 16 种加密方式的其中之一。如下所示:

aes-256-gcm
aes-192-gcm
aes-128-gcm
aes-256-ctr
aes-192-ctr
aes-128-ctr
aes-256-cfb
aes-192-cfb
aes-128-cfb
camellia-128-cfb
camellia-192-cfb
camellia-256-cfb
chacha20-ietf-poly1305
chacha20-ietf
chacha20
rc4-md5

(2016 年 08 月 18 日)
1、修正:默认安装 Github 上 master 分支最新版本(目前为 2.9.0)。
2、修正:由于原作者已经不再更新 pip 下的源代码,故不再使用 pip 安装 Shadowsocks,而是改为下载 Github 的 master 分支来安装。如果在一段时间后,版本升级了,则先卸载,并再次执行本脚本就可以升级为最新版。

(2016 年 05 月 12 日)
1、新增在 CentOS 7 下的防火墙规则设置。

(2015 年 08 月 28 日)
1、修正控制脚本 /etc/init.d/shadowsocks 在 CentOS 7 无法查看 status 的问题。

(2015 年 08 月 01 日)
1、新增自定义服务器端口功能(如不设定,默认端口为 8989);

(2015 年 03 月 10 日)
1、新增在 Debian、Ubuntu 下的一键安装;

(2015 年 01 月 21 日)
1、修正配置文件,与官方给出的 Sample 一致;
2、修改启动脚本,使用官方给出的后台启动和停止命令。

(2014 年 10 月 10 日)
跟作者反馈了多用户多端口问题,作者已更新 Wiki 页面。本教程新增多用户多端口配置文件的 sample 。

(2014 年 09 月 24 日)
如何配置多用户?详见:这里
备注:Shadowsocks 已经支持多用户,在配置文件中增加不同的端口,对应不同的密码即可。

(2014 年 07 月 12 日)
1、修正获取公网 IP 时的一个问题。建议不要使用共享公网 IP 的 VPS 来搭建 Shadowsocks 服务。

(2014 年 05 月 29 日)
1、增加 chkconfig 配置,实现 service 命令。
2、配置文件名从 /etc/config.json 改为 /etc/shadowsocks.json(与官方的命名一致)。
3、配置文件中新增 workers ,值默认为 1(与官方配置同步)。

(2014 年 05 月 27 日)
1、修正开机自启动失效的问题。
2、优化是否后台启动成功的判断逻辑。

(2014 年 05 月 04 日)
1、修正对增加防火墙端口逻辑的判断bug,对于已经放行 8989 端口的情况下,则无需再次增加。
2、修正获取服务器 IP 的判断bug,对于多 IP 的 VPS 或服务器,默认只取第一个公网 IP 写到配置文件(/etc/config.json)里。
3、加入开机自启动。

转载请注明:秋水逸冰 » Shadowsocks Python版一键安装脚本

发表我的评论
取消评论

请输入正确答案后提交评论 *超出时限。 请再次填写验证码。

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (1333)

  1. 你好~我刚才想安装SS,但提示说命令未找到 或者文件路径 都没有 是为什么?还是你的脚本都关闭了?谢谢 login as: root [email protected]'s password: Last login: Mon Jan 15 17:39:26 2018 from 39.168.142.34 [root@huzi ~]# wget --no-check-certificate -O shadowsocks.sh https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks.sh -bash: wget: command not found [root@huzi ~]# chmod +x shadowsocks.sh chmod: cannot access `shadowsocks.sh': No such file or directory [root@huzi ~]# ./shadowsocks.sh 2>&1 | tee shadowsocks.log -bash: ./shadowsocks.sh: No such file or directory [root@huzi ~]#
    虎子6年前(2018-01-15)回复
    • 出现 -bash: wget: command not found 这样的提示,如果你稍微去搜索一下的话,就会明白是系统缺少 wget 命令导致的。 手动安装一下即可。
      秋水逸冰6年前(2018-01-16)回复
  2. 请问shadowsocks服务端如何自定义dns?我改了/etc/resolv.conf文件,但是ss好像不遵循这个dns啊,始终是使用8.8.8.8
    Alex6年前(2018-01-14)回复
  3. 你好,我想问下ubuntu下的脚本能否支持脚本携带参数呢,.比如 /shadowsocks.sh 2>&1 | tee shadowsocks.log -pwd password -port 8888 -加密方式 19 -安装配置 1(shadowsockR)这种结构
    ccc6年前(2018-01-06)回复
    • 这是安装脚本,不是Shadowsocks可执行文件,因此并不支持这么做。
      秋水逸冰6年前(2018-01-06)回复
  4. root@debian:~# cat /etc/shadowsocks.json { "server":"0.0.0.0", "local_address":"127.0.0.1", "local_port":1080, "port_password":{ "27":"FuckCN666***", "666":"crossgfw666" }, "timeout":300, "method":"aes-256-cfb", "fast_open":false } 大神求解为何666端口没用啊,,,访问不了外网。防火墙我看了,没开启,甚至我开启放行端口也没用!
    6666年前(2018-01-04)回复
    • 有些 VPS 比如 GCE,AWS,Azure,阿里云等,有默认安全规则,需要把相应的端口流量放行。
      秋水逸冰6年前(2018-01-04)回复
  5. 你好博主!请问里面的ss配置文件路径/etc/shadowsocks.json怎么打开呀?是在VPS里开吗?我该输入什么命令,谢谢解答!
    bluestar6年前(2018-01-03)回复
    • 在终端里可以用 vim 或者 nano 打开。 vi /etc/shadowsocks.json 或者 nano /etc/shadowsocks.json
      秋水逸冰6年前(2018-01-04)回复
  6. 不好意思,我自己配置改错了,已经解决了
    僵了僵了6年前(2017-12-27)回复
  7. Starting Shadowsocks success root@VM-0-9-debian:~# /etc/init.d/shadowsocks start INFO: loading config from /etc/shadowsocks.json 2017-12-27 10:45:39 INFO loading libcrypto from libcrypto.so.1.1 started Starting Shadowsocks success root@VM-0-9-debian:~# /etc/init.d/shadowsocks start INFO: loading config from /etc/shadowsocks.json 2017-12-27 10:47:15 INFO loading libcrypto from libcrypto.so.1.1 started Starting Shadowsocks success root@VM-0-9-debian:~# /etc/init.d/shadowsocks start INFO: loading config from /etc/shadowsocks.json 2017-12-27 10:47:18 INFO loading libcrypto from libcrypto.so.1.1 started Starting Shadowsocks success 请问启动不了怎么办啊,每次卸载重装了能启动,重启以后就一直无法启动。
    僵了僵了6年前(2017-12-27)回复
  8. 您好,请问连接不上,是什么原因? [root@ssr1 linux1]# /etc/shadowsocks.json /etc/shadowsocks.json: line 2: server:0.0.0.0,: command not found /etc/shadowsocks.json: line 3: server_port:3659,: command not found /etc/shadowsocks.json: line 4: local_address:127.0.0.1,: command not found /etc/shadowsocks.json: line 5: local_port:1080,: command not found /etc/shadowsocks.json: line 6: password:123,: command not found /etc/shadowsocks.json: line 7: timeout:300,: command not found /etc/shadowsocks.json: line 8: method:aes-256-cfb,: command not found /etc/shadowsocks.json: line 9: fast_open:false: command not found [root@ssr1 etc]# iptables -L -n Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:3659 ACCEPT all -- 127.0.0.1 127.0.0.1 ACCEPT all -- 127.0.0.1 127.0.0.1 ACCEPT all -- 127.0.0.1 127.0.0.1 ACCEPT all -- 127.0.0.1 127.0.0.1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT) target prot opt source destination REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT) target prot opt source destination [root@ssr1 etc]# iptables -I OUTPUT -p tcp --sport 3659 -j ACCEPT [root@ssr1 linux1]# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1509/master tcp 0 0 0.0.0.0:3659 0.0.0.0:* LISTEN 1186/python tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 990/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 991/cupsd tcp6 0 0 ::1:25 :::* LISTEN 1509/master tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::22 :::* LISTEN 990/sshd tcp6 0 0 ::1:631 :::* LISTEN 991/cupsd 2017-12-24 08:29:29 INFO starting server at 0.0.0.0:3659 2017-12-24 08:31:24 INFO connecting www.google.com.hk:443 from 110.88.113.146:3061 2017-12-24 08:31:24 ERROR [Errno 32] Broken pipe 2017-12-24 08:31:25 INFO connecting www.google.com.hk:443 from 110.88.113.146:3065 2017-12-24 08:31:25 ERROR [Errno 32] Broken pipe 2017-12-24 08:31:25 INFO connecting twitter.com:443 from 110.88.113.146:3069 2017-12-24 08:31:25 ERROR [Errno 104] Connection reset by peer 2017-12-24 08:31:26 INFO connecting twitter.com:443 from 110.88.113.146:3075 2017-12-24 08:31:26 ERROR [Errno 104] Connection reset by peer 2017-12-24 08:31:55 INFO connecting twitter.com:443 from 110.88.113.146:3091 2017-12-24 08:31:55 ERROR [Errno 104] Connection reset by peer 2017-12-24 08:31:56 INFO connecting twitter.com:443 from 110.88.113.146:3095 2017-12-24 08:31:56 ERROR [Errno 104] Connection reset by peer 2017-12-24 08:32:25 INFO connecting twitter.com:443 from 110.88.113.146:3118 2017-12-24 08:32:25 ERROR [Errno 104] Connection reset by peer 2017-12-24 08:32:55 INFO connecting twitter.com:443 from 110.88.113.146:3142 2017-12-24 08:32:55 ERROR [Errno 104] Connection reset by peer 2017-12-24 08:32:55 INFO connecting twitter.com:443 from 110.88.113.146:3146 2017-12-24 08:32:55 ERROR [Errno 104] Connection reset by peer 2017-12-24 08:32:56 INFO connecting twitter.com:443 from 110.88.113.146:3150 2017-12-24 08:32:56 ERROR [Errno 104] Connection reset by peer started 2017-12-24 08:32:59 INFO starting server at 0.0.0.0:3659 2017-12-24 08:33:25 INFO connecting twitter.com:443 from 110.88.113.146:3170 2017-12-24 08:33:25 ERROR [Errno 104] Connection reset by peer [root@ssr1 linux1]# ping google.com PING google.com (172.217.9.238) 56(84) bytes of data. 64 bytes from lga34s11-in-f14.1e100.net (172.217.9.238): icmp_seq=1 ttl=54 time=3.95 ms 64 bytes from lga34s11-in-f14.1e100.net (172.217.9.238): icmp_seq=2 ttl=54 time=4.04 ms 64 bytes from lga34s11-in-f14.1e100.net (172.217.9.238): icmp_seq=3 ttl=54 time=3.83 ms 64 bytes from lga34s11-in-f14.1e100.net (172.217.9.238): icmp_seq=4 ttl=54 time=3.73 ms 64 bytes from lga34s11-in-f14.1e100.net (172.217.9.238): icmp_seq=5 ttl=54 time=4.05 ms ^C --- google.com ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4005ms rtt min/avg/max/mdev = 3.733/3.922/4.050/0.134 ms [root@ssr1 linux1]# ping twitter.com PING twitter.com (104.244.42.129) 56(84) bytes of data. 64 bytes from 104.244.42.129 (104.244.42.129): icmp_seq=1 ttl=54 time=21.2 ms 64 bytes from 104.244.42.129 (104.244.42.129): icmp_seq=2 ttl=54 time=20.2 ms 64 bytes from 104.244.42.129 (104.244.42.129): icmp_seq=3 ttl=54 time=20.6 ms 64 bytes from 104.244.42.129 (104.244.42.129): icmp_seq=4 ttl=54 time=20.3 ms 64 bytes from 104.244.42.129 (104.244.42.129): icmp_seq=5 ttl=54 time=20.9 ms
    xes6年前(2017-12-24)回复
  9. 请问如何设置一个端口密码只允许一个用户连接?谢谢。
    Brian6年前(2017-12-22)回复
  10. [2017-12-09 23:53:48] Shadowsocks started [2017-12-09 23:53:57] Shadowsocks started [2017-12-09 23:54:02] System.Reflection.TargetInvocationException: 操作过程中出现异常,结果无效。 有关异常的详细信息,请查看 InnerException。 ---> System.Net.WebException: 请求被中止: 未能创建 SSL/TLS 安全通道。 在 System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 在 System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result) 在 System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result) --- 内部异常堆栈跟踪的结尾 --- 在 System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary() 在 Shadowsocks.Controller.UpdateChecker.http_DownloadStringCompleted(Object sender, DownloadStringCompletedEventArgs e) [2017-12-09 23:54:03] Shadowsocks started 大神求解
    blackwings7年前(2017-12-09)回复
  11. 为啥一直建立不了TCP连接呢,试了好久了。。。
    te7年前(2017-12-08)回复
  12. 在Ubuntu 16.04 LTS下装了这个脚本,系统一旦重启之后ss客户端就不能用了,但是在Ubuntu里shadowsocks进程是正常运行的,在Ubuntu里执行/etc/init.d/shadowsocks restart问题还是一样,有人遇到同样的问题吗?
    wilson7年前(2017-12-08)回复
  13. 请问安装时总停在了‘Press any key to start...or Press Ctrl+C to cancel’按任何键都没反应,只能强制结束时怎么回事?我的操作系统 Ubuntu 14.04 LTS (GNU/Linux 3.13.0-24-generic x86_64)
    tg7年前(2017-12-07)回复
  14. 非常感谢大佬!我希望设置监控和限制同时登陆,貌似通过设置多个端口也不能实现。
    Alex7年前(2017-12-01)回复
  15. [Error] Failed to download libsodium-1.0.15.tar.gz! 这是咋回事
    a7年前(2017-11-28)回复
    • 我也是,[Error] Failed to download libsodium-1.0.15.tar.gz!,然后我装那个SS-R版本,提示也是失败
      小沙弥7年前(2017-11-30)回复
    • 找到原因了,是东京的服务器网络故障,换其他地区的就没问题了,装的SSR版本
      小沙弥7年前(2017-11-30)回复