Shadowsocks-rust 是目前活跃维护的 Shadowsocks 实现,以性能和内存安全见长。下面按安装、配置、启动、开机自启、本地测试、远程测试六个环节,梳理一份可直接落地的操作流程。

一 安装,推荐通过 Rust 的包管理器 Cargo 安装,这是最直接的方式:

apt update && apt install -y build-essential
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
cargo install shadowsocks-rust

二 配置 Shadowsocks-rust 本身不生成配置文件,需要手动创建

创建 /etc/shadowsocks-rust/config.json:

cat > /etc/shadowsocks-rust/config.json << 'EOF'
{
    "server": "0.0.0.0", # 监听所有网卡
    "server_port": 8383,
    "password": "你的强密码",
    "method": "aes-256-gcm",
    "timeout": 300
}
EOF
# 更改 权限
chmod 600 /etc/shadowsocks-rust/config.json

 三 启动,分2种 一种是直接启动服务,可以测试用,一种是配置为系统服务。

# 测试服务
ssserver -c /etc/shadowsocks-rust/config.json
# 配置系统服务,创建 /etc/systemd/system/shadowsocks-rust.service
cat > /etc/systemd/system/shadowsocks-rust.service << 'EOF'
[Unit]
Description=Shadowsocks-Rust Server
After=network.target

[Service]
Type=simple
User=root
ExecStart=/root/.cargo/bin/ssserver -c /etc/shadowsocks-rust/config.json
Restart=on-failure
RestartSec=5
LimitNOFILE=51200

[Install]
WantedBy=multi-user.target
EOF
#  下面是常用命令
sudo systemctl daemon-reload # 重启服务
sudo systemctl enable shadowsocks-rust # 开机启动
sudo systemctl start shadowsocks-rust # 启动服务
sudo systemctl status shadowsocks-rust # 查看服务状态
sudo systemctl stop shadowsocks-rust # 启动服务

 四 本地测试,创建一个本地的监听,然后由本地发起代理请求测试服务。

# 创建本地测试客户端配置
cat > /etc/shadowsocks-rust/client.json << 'EOF'
{
    "server": "你的服务器公网IP",
    "server_port": 8383,
    "local_address": "127.0.0.1",
    "local_port": 1081,
    "password": "你的强密码",
    "method": "aes-256-gcm",
    "timeout": 300
}
EOF
# 启动一个客户端服务
sslocal -c /etc/shadowsocks-rust/client.json

 再启动一个ssh 远程连接,测试

curl --socks5-hostname 127.0.0.1:1081 http://httpbin.org/ip
#返回的 origin 字段应该是你服务器的公网 IP。

 五 远程测试

  1. 需要打开服务器对应ip。和ufw 相关配置。
  2. 用其他客户端请求即可。