在 Debian(以及大多数 Linux 发行版)中,是否需要 root 取决于你要修改的 ulimit 类型和操作范围:
不需要 root
普通用户可以直接运行:
ulimit -a
查看当前 shell 的限制。
不需要 root
普通用户可以对自己已有的 soft limit 调高,但不能超过 hard limit:
ulimit -n 4096
需要 root
普通用户不能提高 hard limit,只能 root 修改。
例如:
# 作为 root
ulimit -Hn 65536
需要 root
编辑:
/etc/security/limits.conf
示例:
* soft nofile 65536
* hard nofile 65536
修改后对用户重新登录生效。
需要 root
如果服务由 systemd 管理,需在 service 文件中设置:
[Service]
LimitNOFILE=65536
然后:
systemctl daemon-reload
systemctl restart xxx
| 操作 | 是否需要 root |
|---|---|
| 查看 ulimit | 否 |
| 调高 soft limit(≤ hard) | 否 |
| 修改 hard limit | 是 |
| 修改系统级 limits.conf | 是 |
| 修改 systemd 服务限制 | 是 |
如果你有具体场景(比如“普通用户想调大文件描述符”),我可以给你更精确的做法。