v2fly / v2ray-step-by-step

This repo is a fork of ToutyRater/v2ray-guide, we aim to provide a new step-by-step guide of v2ray
https://guide.v2fly.org
Creative Commons Attribution 4.0 International
753 stars 426 forks source link

关于“TCP + TLS 分流器”章节中Domain Socket部分的一些修正意见 #153

Closed djunhao closed 4 years ago

djunhao commented 4 years ago

本人使用的服务器系统是debian 10,所以以下意见基于该系统。 对/etc/systemd/system/v2ray.service有以下修正意见: 1、该sevice单元使用了用户v2ray,建议增加创建用于运行v2ray的用户的步骤,以便更加直观的step-by-step。 至于是useradd v2ray -s /usr/sbin/nologin,还是useradd --sytem --shell /usr/sbin/nologin v2ray,这两者哪个命令更合适,请大家商榷。 2、将service单元中的所有/usr/bin/{rm,mkdir,sleep,chmod}等命令,修改为/bin/{rm,mkdir,sleep,chmod}。 非debian 10系统的朋友,建议根据whereis命令显示的路径进行修改。 3、我注意到v2ray.sock文件的读写属性是777,也就是说该文件可读可写可执行。执行权限是否真的必要?更安全的权限应该如何设置?

kslr commented 4 years ago

如果这些固定命令的话,直接使用也没有什么区别的吧

ghost commented 4 years ago
  1. 使用 v2ray 用戶的話:
    # useradd -s /usr/sbin/nologin v2ray

    即可,也可直接使用 nobody 用戶。

  2. 這個沒有問題。
  3. 修改為 644 或許可行,使用者擁有讀寫權限,群組和非本群組外的其它人擁有只讀權限。
djunhao commented 4 years ago
  1. 使用 v2ray 用戶的話:

    # useradd -s /usr/sbin/nologin v2ray

    即可,也可直接使用 nobody 用戶。

  2. 這個沒有問題。
  3. 修改為 644 或許可行,使用者擁有讀寫權限,群組和非本群組外的其它人擁有只讀權限。

nobody是系统用户,等同于使用--system创建的用户,是吧?

ghost commented 4 years ago
  1. 使用 v2ray 用戶的話:

    # useradd -s /usr/sbin/nologin v2ray

    即可,也可直接使用 nobody 用戶。

  2. 這個沒有問題。
  3. 修改為 644 或許可行,使用者擁有讀寫權限,群組和非本群組外的其它人擁有只讀權限。

nobody是系统用户,等同于使用--system创建的用户,是吧?

nobody 不是系統賬戶。無需在意是否為系統賬戶,使用 -r, --system,僅會造成 uid、gid 和 groups 的區別。

https://unix.stackexchange.com/questions/80277/whats-the-difference-between-a-normal-user-and-a-system-user

djunhao commented 4 years ago
  1. 使用 v2ray 用戶的話:

    # useradd -s /usr/sbin/nologin v2ray

    即可,也可直接使用 nobody 用戶。

  2. 這個沒有問題。
  3. 修改為 644 或許可行,使用者擁有讀寫權限,群組和非本群組外的其它人擁有只讀權限。

nobody是系统用户,等同于使用--system创建的用户,是吧?

nobody 不是系統賬戶。無需在意是否為系統賬戶,使用 -r, --system,僅會造成 uid、gid 和 groups 的區別。

https://unix.stackexchange.com/questions/80277/whats-the-difference-between-a-normal-user-and-a-system-user

了解了,谢谢!

phlinhng commented 4 years ago
  1. 使用腳本生成v2ray.service,可以自動適配不同OS版本的路徑。
    
    ds_service=$(mktemp)
    cat > ${ds_service} <<-EOF
    [Unit]
    Description=V2Ray - A unified platform for anti-censorship
    Documentation=https://v2ray.com https://guide.v2fly.org
    After=network.target nss-lookup.target
    Wants=network-online.target

[Service]

If the version of systemd is 240 or above, then uncommenting Type=exec and commenting out Type=simple

Type=exec

Type=simple

Runs as root or add CAP_NET_BIND_SERVICE ability can bind 1 to 1024 port.

This service runs as root. You may consider to run it as another user for security concerns.

By uncommenting User=v2ray and commenting out User=root, the service will run as user v2ray.

More discussion at https://github.com/v2ray/v2ray-core/issues/1011

User=root

User=v2ray CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_NET_RAW NoNewPrivileges=yes

ExecStartPre=$(which mkdir) -p /tmp/v2ray-ds ExecStartPre=$(which rm) -rf /tmp/v2ray-ds/*.sock

ExecStart=/usr/bin/v2ray/v2ray -config /etc/v2ray/config.json

ExecStartPost=$(which sleep) 1 ExecStartPost=$(which chmod) 777 /tmp/v2ray-ds/v2ray.sock

Restart=on-failure

Don't restart in the case of configuration error

RestartPreventExitStatus=23

[Install] WantedBy=multi-user.target EOF

add new user and overwrite v2ray.service

https://github.com/v2ray/v2ray-core/issues/1011

useradd -d /etc/v2ray/ -M -s /sbin/nologin v2ray mv ${ds_service} /etc/systemd/system/v2ray.service chown -R v2ray:v2ray /var/log/v2ray


2. 試過將權限改成644,會導致TLS分流器沒有辦法讀寫`/tmp/v2ray-ds/v2ray.sock`。