Deploy and configure Xray proxy servers. Use when a user asks to set up VLESS, VMess, Trojan, or Shadowsocks proxies, configure Reality or TLS transport, deploy Xray with XTLS, set up fallback routing, manage multi-user access, configure traffic routing rules, set up CDN-based tunneling, build subscription links for client apps, monitor Xray traffic, or bypass network restrictions. Covers all major Xray protocols, transports, and deployment patterns.
155 stars
0 votes
0 copies
20 views
Added September 6, 2026
devopsgoshellbashgitapidevopssecurity
Works with
terminal
cli
api
Security analysis
B84/100
mediumUses curl or wget to download content
criticalModifies startup scripts or system services for persistence
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Xray?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/terminalskills-xray)
---
name: xray
description: >-
Deploy and configure Xray proxy servers. Use when a user asks to set up VLESS,
VMess, Trojan, or Shadowsocks proxies, configure Reality or TLS transport,
deploy Xray with XTLS, set up fallback routing, manage multi-user access,
configure traffic routing rules, set up CDN-based tunneling, build
subscription links for client apps, monitor Xray traffic, or bypass network
restrictions. Covers all major Xray protocols, transports, and deployment
patterns.
license: Apache-2.0
compatibility: 'Linux with systemd, Xray-core 26.x (releases use year.month.day numbering since 2025)'
metadata:
author: terminal-skills
version: 1.1.0
category: devops
tags: "xray, vless, vmess, trojan, proxy"
repository: https://github.com/XTLS/Xray-core
---
# Xray
## Overview
Deploy and configure Xray-core — the advanced proxy platform supporting VLESS, VMess, Trojan, and Shadowsocks protocols with modern transports like Reality, XTLS-Vision, WebSocket, gRPC, and HTTP/2. This skill covers server deployment, protocol selection, TLS/Reality configuration, traffic routing, multi-user management, CDN integration, client configuration, and monitoring.
## Instructions
### Step 1: Installation
Download the release archive and verify it against the published digest before installing (replace the version with the latest from the Xray-core releases page; the digest file sits next to each archive):
```bash
V=v26.10.21
cd /tmp && curl -fLO https://github.com/XTLS/Xray-core/releases/download/$V/Xray-linux-64.zip
curl -fL https://github.com/XTLS/Xray-core/releases/download/$V/Xray-linux-64.zip.dgst | grep SHA2-256
sha256sum Xray-linux-64.zip # must match the SHA2-256 line above
unzip Xray-linux-64.zip xray geoip.dat geosite.dat
sudo install -m 755 xray /usr/local/bin/xray
sudo install -d /usr/local/share/xray /usr/local/etc/xray
sudo install -m 644 geoip.dat geosite.dat /usr/local/share/xray/
xray version
```
`geoip:` and `geosite:` rules in the examples below need those two `.dat` files next to the binary or in `/usr/local/share/xray/`; without them the config fails to load. The project's `Xray-install` script (systemd unit, dedicated `xray` user, `update-geodata`) is an alternative: download `install-release.sh` from the XTLS/Xray-install repository, read it, then run it. Since October 2026 it runs the service as the `xray` user, so config files must be readable by that user (`root:xray`, mode 0640).
Generate identifiers:
```bash
xray uuid # client id
xray x25519 # PrivateKey goes into the server config, "Password (PublicKey)" into client links as pbk
```
### Step 2: VLESS + Reality (Recommended)
The most secure setup. Reality mimics a real HTTPS website's TLS handshake, eliminating the need for a domain or TLS certificate.
**Server config (`/usr/local/etc/xray/config.json`):**
```json
{
"log": { "loglevel": "warning" },
"inbounds": [{
"tag": "vless-in",
"listen": "0.0.0.0",
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{ "id": "YOUR-UUID", "flow": "xtls-rprx-vision", "email": "user1@proxy" }
],
"decryption": "none"
},
"streamSettings": {
"network": "tcp",
"security": "reality",
"realitySettings": {
"target": "www.microsoft.com:443",
"serverNames": ["www.microsoft.com", "microsoft.com"],
"privateKey": "YOUR-PRIVATE-KEY",
"shortIds": ["0123456789abcdef"]
}
},
"sniffing": { "enabled": true, "destOverride": ["http", "tls", "quic"] }
}],
"outbounds": [
{ "protocol": "freedom", "tag": "direct" },
{ "protocol": "blackhole", "tag": "block" }
],
"routing": {
"rules": [{ "ip": ["geoip:private"], "outboundTag": "block" }]
}
}
```
Check the config before starting: `xray run -test -c /usr/local/etc/xray/config.json` prints `Configuration OK`. Check the camouflage target with `xray tls ping www.microsoft.com` (it must answer TLS 1.3; a target that supports X25519MLKEM768 also gives post-quantum key exchange). Reality forwards unauthenticated traffic to the target, so never choose a site behind a CDN you do not control as a shared forwarder; limit abuse with `limitFallbackUpload`/`limitFallbackDownload` or a filtering proxy in front.
**Client share link:**
```
vless://UUID@SERVER_IP:443?encryption=none&flow=xtls-rprx-vision&security=reality&sni=www.microsoft.com&fp=chrome&pbk=PUBLIC_KEY&sid=0123456789abcdef&type=tcp#MyProxy
```
```bash
sudo systemctl enable --now xray
```
On the client side the Reality block uses `serverName`, `fingerprint`, `password` (the public key from `xray x25519`) and `shortId`; apps that import `vless://` links fill these from the `sni`, `fp`, `pbk` and `sid` parameters. The `mldsa65` commands add optional post-quantum signature verification for Reality.
### Step 3: VLESS + WebSocket + TLS (CDN-Compatible)
For routing through Cloudflare CDN to hide the server IP. Requires a domain with Cloudflare proxying and a TLS certificate. The Xray docs now recommend XHTTP over WebSocket because WebSocket's `http/1.1` ALPN is an easy fingerprint; the WebSocket setup below still loads and works.
```bash
sudo apt install -y certbot
sudo certbot certonly --standalone -d proxy.yourdomain.com
```
```json
{
"inbounds": [
{
"port": 443, "protocol": "vless",
"settings": {
"clients": [{ "id": "YOUR-UUID" }],
"decryption": "none",
"fallbacks": [
{ "dest": 8080 },
{ "path": "/ws-path", "dest": 8443, "xver": 1 }
]
},
"streamSettings": {
"network": "tcp", "security": "tls",
"tlsSettings": {
"certificates": [{
"certificateFile": "/etc/letsencrypt/live/proxy.yourdomain.com/fullchain.pem",
"keyFile": "/etc/letsencrypt/live/proxy.yourdomain.com/privkey.pem"
}]
}
}
},
{
"listen": "127.0.0.1", "port": 8443, "protocol": "vless",
"settings": { "clients": [{ "id": "YOUR-UUID" }], "decryption": "none" },
"streamSettings": { "network": "ws", "wsSettings": { "path": "/ws-path" } }
}
],
"outbounds": [{ "protocol": "freedom", "tag": "direct" }]
}
```
Set up nginx on port 8080 as fallback, and in Cloudflare: SSL/TLS Full (Strict), WebSockets ON.
### Step 4: Trojan & Shadowsocks
**Trojan** (looks like normal HTTPS):
```json
{
"inbounds": [{
"port": 443, "protocol": "trojan",
"settings": {
"clients": [{ "password": "your-strong-password", "email": "user1@trojan" }],
"fallbacks": [{ "dest": 8080 }]
},
"streamSettings": {
"network": "tcp", "security": "tls",
"tlsSettings": { "certificates": [{ "certificateFile": "/etc/letsencrypt/live/proxy.yourdomain.com/fullchain.pem", "keyFile": "/etc/letsencrypt/live/proxy.yourdomain.com/privkey.pem" }] }
}
}]
}
```
**Shadowsocks**: Xray 26.x prints a deprecation warning for the shadowsocks protocol ("might be removed", migrate to VLESS Encryption). Do not use it for new deployments; use VLESS + Reality or Trojan.
### Step 5: Multi-User Management
```jsonc
"clients": [
{ "id": "uuid-1", "email": "alice@proxy", "flow": "xtls-rprx-vision" },
{ "id": "uuid-2", "email": "bob@proxy", "flow": "xtls-rprx-vision" },
{ "id": "uuid-3", "email": "carol@proxy", "flow": "xtls-rprx-vision" }
]
```
**Per-user traffic stats** — enable the stats API:
```json
{
"stats": {},
"policy": {
"levels": { "0": { "statsUserUplink": true, "statsUserDownlink": true } },
"system": { "statsInboundUplink": true, "statsInboundDownlink": true }
},
"api": { "tag": "api", "services": ["StatsService", "HandlerService"] },
"inbounds": [
{ "listen": "127.0.0.1", "port": 10085, "protocol": "dokodemo-door",
"settings": { "address": "127.0.0.1" }, "tag": "api" }
],
"routing": { "rules": [{ "inboundTag": ["api"], "outboundTag": "api" }] }
}
```
**Query and manage users at runtime:**
```bash
xray api stats --server=127.0.0.1:10085 -name "user>>>alice@proxy>>>traffic>>>uplink"
xray api adu --server=127.0.0.1:10085 new-user.json
xray api rmu --server=127.0.0.1:10085 -tag=vless-in olduser@proxy
xray api inboundusercount --server=127.0.0.1:10085 -tag vless-in
```
`new-user.json` names the inbound by tag and carries the client (verified against the 26.10.21 binary; `adi` adds whole inbounds, not users):
```json
{ "inbounds": [{ "tag": "vless-in", "port": 443, "protocol": "vless",
"settings": { "clients": [{ "id": "b1b2c3d4-0000-4000-8000-000000000001", "email": "dave@proxy", "flow": "xtls-rprx-vision" }], "decryption": "none" } }] }
```
A user counter such as `user>>>alice@proxy>>>traffic>>>uplink` exists only after that user has moved traffic; before that `stats` answers `not found`. Users added at runtime are lost on restart, so also add them to `config.json`.
### Step 6: Routing Rules & Monitoring
**Route by domain/IP/geo:**
```json
{
"routing": {
"domainStrategy": "IPIfNonMatch",
"rules": [
{ "domain": ["geosite:category-ads-all"], "outboundTag": "block" },
{ "ip": ["geoip:private"], "outboundTag": "block" },
{ "network": "tcp,udp", "outboundTag": "direct" }
]
}
}
```
**Monitoring:**
```bash
sudo systemctl status xray
sudo journalctl -u xray -f
# access log only exists if "log": {"access": "/var/log/xray/access.log"} is set
sudo grep "accepted" /var/log/xray/access.log | awk '{print $3}' | sort | uniq -c | sort -rn
```
**Firewall:**
```bash
sudo ufw allow 22/tcp && sudo ufw allow 443/tcp && sudo ufw enable
```
## Examples
### Example 1: Deploy a VLESS + Reality proxy server for a small team
**User prompt:** "Set up Xray on our Debian 12 VPS at 198.51.100.30 using VLESS with Reality transport. Create accounts for alice, bob, and carol. Use microsoft.com as the Reality target and give me the share links for v2rayNG."
The agent will install Xray from the digest-verified release archive, generate a UUID for each user and an X25519 key pair, build a `config.json` with a VLESS inbound on port 443 using Reality settings targeting `www.microsoft.com`, add three client entries with `xtls-rprx-vision` flow, add routing rules to block private IPs, enable and start the xray service, open port 443 in the firewall, and output three `vless://` share links with the server IP, public key, short ID, and SNI.
### Example 2: Set up a CDN-fronted VLESS proxy with Cloudflare and a fallback website
**User prompt:** "I have proxy.mysite.com pointing to our server through Cloudflare. Configure Xray with VLESS over WebSocket on /secret-ws so traffic goes through Cloudflare's CDN. Non-proxy visitors should see a normal nginx website."
The agent will obtain a Let's Encrypt certificate with certbot, configure Xray with a main VLESS+TLS inbound on port 443 with a fallback to nginx on port 8080, add a second VLESS+WebSocket inbound on localhost:8443 with path `/secret-ws`, set up nginx to serve a static site on port 8080, verify Cloudflare SSL is set to Full (Strict) with WebSockets enabled, and provide the client connection string with the WebSocket path and Cloudflare SNI.
## Guidelines
- Prefer VLESS + Reality (flow `xtls-rprx-vision`) for new deployments; it needs no domain or certificate. Always run `xray run -test -c config.json` after editing
- Prefer VLESS or Trojan over VMess and Shadowsocks; Xray warns that Shadowsocks may be removed. Keep the API inbound on 127.0.0.1 only, since it can add and remove users
- Never put a script from the network straight into a shell on a proxy server; verify the release digest first
- Block access to private IP ranges (geoip:private) in routing rules to prevent the proxy from being used for SSRF attacks against internal services
- Use `xray api adu` / `rmu` to add and remove users at runtime without restarting the service, which avoids disconnecting active users
- Choose the Reality `target` and `serverNames` from a popular website (microsoft.com, apple.com) hosted on a different IP than your server, and ensure that site supports TLS 1.3 and HTTP/2
- Enable the stats API with per-user tracking (`statsUserUplink`/`statsUserDownlink`) to monitor bandwidth usage and detect abuse