当/etc/security/limits.conf中的nofile设置为unlimited时,无法login

我在/etc/security/limits.conf 6.2)中设置了以下值(-1将parsing为无限制,我想)

根nofile软-1

根nofile硬-1

我现在无法用root用户login。 类似于这里描述的问题。 设置值将解决问题。

任何人都可以帮助解释这个?

更新:

多谢你们。 我错误地记住了我的设置。 这些值应该是

 root soft nofile -1 root hard nofile -1 

正如@迈克尔汉普顿告诉你,你的语法是错误的,但无论如何,我不认为是好主意,将文件限制设置为无限

您可以阅读这篇文章的更多信息https://stackoverflow.com/questions/1212925/on-linux-set-maximum-open-files-to-unlimited-possible

我下载了内核版本linux-2.6.32.61,我从kernel / sys.c中看到了这个:

  SYSCALL_DEFINE2(setrlimit, unsigned int, resource, struct rlimit __user *, rlim) { struct rlimit new_rlim, *old_rlim; int retval; if (resource >= RLIM_NLIMITS) return -EINVAL; if (copy_from_user(&new_rlim, rlim, sizeof(*rlim))) return -EFAULT; if (new_rlim.rlim_cur > new_rlim.rlim_max) return -EINVAL; old_rlim = current->signal->rlim + resource; if ((new_rlim.rlim_max > old_rlim->rlim_max) && !capable(CAP_SYS_RESOURCE)) return -EPERM; if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open) return -EPERM; 

从人类proc

 The kernel constant NR_OPEN imposes an upper limit on the value that may be placed in file-max. 

来自./fs/file.c:

 ./fs/file.c:30:int sysctl_nr_open __read_mostly = 1024*1024; echo $((1024*1024)) 1048576 

为什么你需要比nr_open更多的文件?

我做了一个使用你的limits.conf设置的testing:

/etc/pam.d/su中:

  egrep -v "^#|^$" /etc/pam.d/su auth sufficient pam_rootok.so session required pam_env.so readenv=1 session required pam_env.so readenv=1 envfile=/etc/default/locale session optional pam_mail.so nopen session required pam_limits.so @include common-auth @include common-account @include common-session 

现在我将使用su命令切换到用户root:

 root@ubuntu:~# strace -e setrlimit su - root setrlimit(RLIMIT_NOFILE, {rlim_cur=RLIM64_INFINITY, rlim_max=RLIM64_INFINITY}) = -1 EPERM (Operationnot permitted) 

你扭转了第二和第三个领域。

它应该改为:

 root soft nofile -1 root hard nofile -1 

您在nofile (打开的文件数)中设置的数字不能大于/proc/sys/fs/nr_open 。 检查该文件并使用该值。

[root]# cat /proc/sys/fs/nr_open 1048576 [root]# cat /etc/security/limits.d/biguser.conf biguser - nofile 1048576