Summer

Summer

Deploy Sing-box Vless reality

169
2025-02-12
Deploy Sing-box Vless reality

sing-box uses JSON for configuration files

The configuration file structure is as follows:

{
  "log": {},
  "dns": {},
  "ntp": {},
  "endpoints": [],
  "inbounds": [],
  "outbounds": [],
  "route": {},
  "experimental": {}
}

Prepare

Install sing-box

Install sing-box(Debian):

sudo curl -fsSL https://sing-box.app/gpg.key -o /etc/apt/keyrings/sagernet.asc
sudo chmod a+r /etc/apt/keyrings/sagernet.asc
echo "deb [arch=`dpkg --print-architecture` signed-by=/etc/apt/keyrings/sagernet.asc] https://deb.sagernet.org/ * *" | \
  sudo tee /etc/apt/sources.list.d/sagernet.list > /dev/null
sudo apt-get update
sudo apt-get install sing-box # or sing-box-beta

This shell script is designed to streamline the installation process of singbox

#!/bin/bash

KEYRINGS_DIR="/etc/apt/keyrings"


if [ "$(id -u)" -ne 0 ]; then
  echo "This script must be run as root"
  exit 1
fi


if [ -d "$KEYRINGS_DIR" ]; then
    echo "Directory $KEYRINGS_DIR exists, skipping creation"
else
    sudo mkdir -p "$KEYRINGS_DIR"
    if [ $? -eq 0 ]; then
        echo "Directory $KEYRINGS_DIR created successfully"
    else
        echo "[ERROR] Cannot create keyrings directory: $KEYRINGS_DIR (permission denied)" >&2
        exit 1
    fi
fi

curl -fsSL https://sing-box.app/gpg.key -o /etc/apt/keyrings/sagernet.asc

chmod a+r /etc/apt/keyrings/sagernet.asc

echo "deb [arch=`dpkg --print-architecture` signed-by=/etc/apt/keyrings/sagernet.asc] https://deb.sagernet.org/ * *" | \
  sudo tee /etc/apt/sources.list.d/sagernet.list > /dev/null

apt-get update

apt-get install sing-box -y

Now you can verify if singbox is properly installed

sing-box version

If the output resembles the following, the installation was successful:

root@test:~# sing-box version
sing-box version 1.12.0-alpha.5

Environment: go1.23.5 linux/amd64
Tags: with_gvisor,with_quic,with_dhcp,with_wireguard,with_ech,with_utls,with_reality_server,with_acme,with_clash_api
Revision: ebe75d89abdac712cfdd1f1483a470d088c471ea
CGO: disabled

Generate the following cryptographic materials:

Now, let's perform the preliminary setup:

UUID:

sing-box generate uuid

x25519 key:

sing-box generate reality-keypair

You will see output similar to the following:

PrivateKey: MD8ZhWAPwnDoUzbIBOBvZaumfYWcng2ZyUficn6Qf3I
PublicKey: a3QOssU__5oVnagL4fNGwjykSS8hx-j1pSK8-Wd9EQg

Now, let's modify the configuration file located at /etc/sing-box/

nano /etc/sing-box/config.json

Configuration File Example:

{
    "log": {
        "level": "info"
    },
    "inbounds": [
        {
            "type": "vless",
            "tag": "vless-in",
            "listen": "::",
            "listen_port": port,
            "users": [
                {
                    "name": "username",
                    "uuid": "uuid",
                    "flow": "xtls-rprx-vision"
                }
            ],
            "tls": {
                "enabled": true,
                "server_name": "url",
                "reality": {
                    "enabled": true,
                    "handshake": {
                        "server": "url",
                        "server_port": 443
                    },
                    "private_key": "private_key",
                    "short_id": [
                        ""
                    ]
                }
            },
            "multiplex": {
                "enabled": false,
                "padding": true,
                "brutal": {
                    "enabled": false,
                    "up_mbps": 1000,
                    "down_mbps": 1000
                }
            }
        }
    ],
    "outbounds": [
        {
            "type": "direct",
            "tag": "direct"
        }
    ]
}

Replace the following placeholders in the configuration file:
port, username, uuid, url, private_key

Run Sing-Box

Now, let's start and enable the service using systemctl:

Operation	Command

Enable	sudo systemctl enable sing-box

Disable	sudo systemctl disable sing-box

Start	sudo systemctl start sing-box

Stop	sudo systemctl stop sing-box

Kill	sudo systemctl kill sing-box

Restart	sudo systemctl restart sing-box

Logs	sudo journalctl -u sing-box --output cat -e

New Logs	sudo journalctl -u sing-box --output cat -f