如何在 Debian Stretch 中为普通用户永久更改打开的文件(ulimit -n)?

How to change open files (ulimit -n) permanently for normal user in Debian Stretch?

我想永久更改系统打开文件设置,但它不起作用。

我的登录用户是普通用户,不是root。我做了以下操作:

文件 /etc/sysctl.conf

$ grep 'fs.file-max' /etc/sysctl.conf
fs.file-max = 800000

文件 /etc/security/limits.conf

$ grep nofile /etc/security/limits.conf
#        - nofile - max number of open files
* soft nofile 655360
* hard nofile 655360

设置 /etc/security/limits.conf 适用于 CentOS/OpenSUSE,但不适用于 Debian。

添加

session    required   pam_limits.so

进入文件/etc/pam.d/common-session{,-noninteractive},文件/etc/pam.d/login已经有了。绝对路径是

/lib/x86_64-linux-gnu/security/pam_limits.so

reboot后,执行ulimit -n,输出还是默认值1024.

$ ulimit -n
1024

我应该怎么做才能生效?

这在 Debian 中不是问题。 这是 systemd + gnome 中的问题。 systemd 选择不读取或使用 limits.conf,gdm 选择让 systemd 设置它的限制。 ssh sudo su tty 将照常使用 /etc/seecurity/limits.conf。 在 Fedora 中查看此错误 systmd --user does not load limits from /etc/security/limits.d/ 。在讨论中这个解决方案对我有用。

创建文件 /etc/systemd/system/user@1000.service.d/limit.conf,将 1000 替换为您的用户 ID,在该文件中像在 systemd 服务中一样设置限制:

[Service]
LimitNOFILE=655360