Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Deploys ShadowSocks on an Amazon EC2 instance
#!/bin/bash
#
# Deploys ShadowSocks on an Amazon EC2 instance
# Probably works on other cloud providers (not tested)
#
# Only tested on Ubuntu 16.04 LTS
#
## Note : To allow multiple clients, duplicate the configuration,
# specify different server_port (and password if required),
# and launch the new processes in the background
# Ex:
# ssserver -c /etc/shadowsocks/config_8082.json &
# Modifiable vars
SS_CONFIG_DIR="/etc/shadowsocks/"
SS_CONFIG_PATH="$SS_CONFIG_DIR/config.json"
SS_PORT="8081" # Don't forget to open the port
SS_PASSWORD="barfoo!" # <= Change this !
LIBSODIUM_VERSION="1.0.3"
# check if the script is run by root
if [[ $EUID -ne 0 ]]; then
echo "Error: This script must be run as root" 1>&2
exit 1
fi
# Install dependencies and nice to have packages
apt-get install -y fail2ban python-pip python-m2crypto build-essential curl
# Install ShadowSocks (Python implementation)
pip install shadowsocks
# Download, compile and install libsodium in order to be able to use the
# ChaCha20 stream cipher
pushd /tmp
curl -L -O https://github.com/jedisct1/libsodium/releases/download/$LIBSODIUM_VERSION/libsodium-$LIBSODIUM_VERSION.tar.gz
tar xf libsodium-$LIBSODIUM_VERSION.tar.gz && cd libsodium-$LIBSODIUM_VERSION
./configure
make && make install
ldconfig
popd
# Generate config file
mkdir -p $SS_CONFIG_DIR
cat > $SS_CONFIG_PATH <<EOF
{
"server":"0.0.0.0",
"server_port":$SS_PORT,
"local_port":1080,
"password":"$SS_PASSWORD",
"timeout":600,
"method":"chacha20"
}
EOF
# Start Shadowsocks
ssserver -c /etc/shadowsocks/config.json -d start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment