UbuntuUbuntu Based

How To Install Shadowsocks on Ubuntu 24.04 LTS

Install Shadowsocks on Ubuntu 24.04

Shadowsocks is an open-source encrypted proxy project that creates a SOCKS5 proxy to circumvent internet censorship. It’s designed to be fast, reliable, and secure, making it an excellent choice for users who need to access restricted content or maintain their privacy online. Ubuntu 24.04, with its stability and extensive software repository, serves as an ideal platform for hosting a Shadowsocks server.

In this guide, we’ll cover everything from updating your system and installing dependencies to configuring the Shadowsocks server and client. We’ll also touch on important aspects such as security considerations, performance optimization, and troubleshooting common issues.

Prerequisites

Before we dive into the installation process, ensure that you have the following:

  • A server or VPS running Ubuntu 24.04
  • Root or sudo access to the server
  • Basic familiarity with Linux command-line operations
  • An SSH client for remote server access
  • A text editor (such as nano or vim) for configuration file editing

With these prerequisites in place, let’s begin the installation process.

Step 1: Update and Prepare the System

The first step in any software installation on Ubuntu is to ensure your system is up-to-date. This not only provides you with the latest security patches but also ensures compatibility with the software we’re about to install.

Open your terminal and run the following commands:

sudo apt update
sudo apt upgrade -y

The update command refreshes the package lists, while upgrade installs the latest versions of all installed packages. The -y flag automatically answers “yes” to any prompts during the upgrade process.

Next, we’ll install the necessary dependencies for Shadowsocks:

sudo apt install build-essential libevent-dev libssl-dev libsodium-dev -y

These packages provide essential build tools and libraries required for compiling and running Shadowsocks.

Step 2: Install Shadowsocks-libev

There are two primary methods to install Shadowsocks on Ubuntu 24.04: using the package manager or compiling from source. We’ll cover both options, allowing you to choose the one that best suits your needs.

Option A: Install from Ubuntu Repository

The simplest method is to install Shadowsocks-libev directly from the Ubuntu repository. This approach ensures you receive automatic updates and simplifies the installation process.

Run the following command:

sudo apt install shadowsocks-libev -y

This command will download and install the latest version of Shadowsocks-libev available in the Ubuntu repositories.

Option B: Compile from Source

For users who prefer the latest features or need custom configurations, compiling Shadowsocks-libev from source is the way to go. This method requires more steps but offers greater control over the installation.

First, clone the Shadowsocks-libev repository from GitHub:

git clone https://github.com/shadowsocks/shadowsocks-libev.git
cd shadowsocks-libev

Next, configure and compile the source code:

./configure --prefix=/usr/local/shadowsocks-libev --with-libevent --with-openssl --with-libsodium
make && sudo make install

This process may take a few minutes, depending on your system’s performance.

Step 3: Configure Shadowsocks Server

After installation, the next crucial step is configuring your Shadowsocks server. This involves creating and editing a configuration file that specifies various parameters such as the server address, port, password, and encryption method.

Create and Edit Configuration File

Create a new configuration file using your preferred text editor. We’ll use nano in this example:

sudo nano /etc/shadowsocks-libev/config.json

Now, paste the following configuration template into the file:


{
  "server": "0.0.0.0",
  "server_port": 8388,
  "local_port": 1080,
  "password": "your_strong_password",
  "timeout": 300,
  "method": "aes-256-gcm"
}

Let’s break down each parameter:

  • server: Set to “0.0.0.0” to listen on all available network interfaces.
  • server_port: The port on which Shadowsocks will listen. You can change this to any unused port.
  • local_port: The port used by the local Shadowsocks client.
  • password: Replace with a strong, unique password.
  • timeout: Connection timeout in seconds.
  • method: The encryption method. AES-256-GCM is recommended for its security and performance.

Save the file and exit the text editor.

Enable Plugins for Enhanced Security

To further improve security and obfuscation, you can enable plugins like simple-obfs or Cloak. These plugins help disguise Shadowsocks traffic, making it harder to detect and block.

To install simple-obfs, run:

sudo apt install simple-obfs

Then, add the following lines to your Shadowsocks configuration file:

"plugin": "obfs-server",
"plugin_opts": "obfs=http"

This configuration will obfuscate your Shadowsocks traffic to appear as regular HTTP traffic.

Step 4: Start and Enable Shadowsocks Service

With the configuration in place, it’s time to start the Shadowsocks service and ensure it runs automatically on system boot.

Start the Service

To start the Shadowsocks service, use the following command:

sudo systemctl start shadowsocks-libev

Enable Service at Boot

To ensure Shadowsocks starts automatically when your server reboots, enable the service:

sudo systemctl enable shadowsocks-libev

Verify Service Status

Check if the service is running correctly:

sudo systemctl status shadowsocks-libev

You should see output indicating that the service is active and running.

Step 5: Configure Firewall

To allow incoming connections to your Shadowsocks server, you need to configure your firewall. Ubuntu 24.04 uses UFW (Uncomplicated Firewall) by default, which we’ll use for this setup.

Allow Required Ports

Open the port you specified in the Shadowsocks configuration (8388 in our example):

sudo ufw allow 8388/tcp
sudo ufw allow 8388/udp

Enable Firewall

If UFW is not already active, enable it with:

sudo ufw enable

Remember to allow SSH access (port 22) if you haven’t already, to prevent locking yourself out of the server.

Step 6: Install and Configure Client

To use your Shadowsocks server, you’ll need to set up a client on your local machine or device.

Install Client Software

For Ubuntu desktop users, you can install the Shadowsocks client with:

sudo apt install shadowsocks-libev

Configure Client

Create a client configuration file:

sudo nano /etc/shadowsocks-libev/client.json

Add the following content, replacing the server IP and other details with your own:

{
  "server": "your_server_ip",
  "server_port": 8388,
  "local_address": "127.0.0.1",
  "local_port": 1080,
  "password": "your_strong_password",
  "timeout": 300,
  "method": "aes-256-gcm"
}

Connect Using Client

To start the Shadowsocks client, use:

ss-local -c /etc/shadowsocks-libev/client.json

For other operating systems, download the appropriate client software and configure it using the server details you set up.

Step 7: Test Connection

After setting up both the server and client, it’s crucial to test your connection to ensure everything is working correctly.

Verify Proxy Functionality

You can use the curl command to test your proxy connection:

curl --socks5 localhost:1080 http://example.com

If successful, you should see the HTML content of example.com.

DNS Leak Test

To ensure your DNS queries are not leaking, visit a DNS leak test website through your Shadowsocks proxy. If the test shows DNS servers from your proxy location rather than your actual location, your setup is working correctly.

Troubleshooting Common Issues

Even with careful setup, you might encounter some issues. Here are solutions to common problems:

Service Fails to Start

If Shadowsocks fails to start, check the logs for errors:

journalctl -u shadowsocks-libev.service

Common issues include configuration errors or port conflicts.

Connection Issues

If you can’t connect to your Shadowsocks server:

  • Verify that the firewall is correctly configured
  • Check if the server is listening on the specified port using netstat -tuln | grep 8388
  • Ensure your client configuration matches the server settings

Performance Optimization

To improve performance:

  • Try different encryption methods (e.g., chacha20-ietf-poly1305 for better performance on older CPUs)
  • Adjust the timeout setting in your configuration
  • Enable TCP Fast Open if your kernel supports it

Congratulations! You have successfully installed Shadowsocks. Thanks for using this tutorial for installing the Shadowsocks on Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the official Shadowsocks website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button