centos – 在/etc/security/limits.conf中将nofile设置为无限时无法登录

前端之家收集整理的这篇文章主要介绍了centos – 在/etc/security/limits.conf中将nofile设置为无限时无法登录前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在/etc/security/limits.conf(CentOS 6.2)中设置了以下值(-1将被解析为无限制,我猜)

root nofile soft -1

root nofile hard -1

我现在无法使用root用户登录.与here中描述的问题类似.将值设置回来可以解决问题.

任何人都可以帮忙解释一下吗?

更新:

多谢你们.我错误地记住了我的设置.那些价值观应该是

  1. root soft nofile -1
  2. root hard nofile -1
正如@Michael Hampton告诉你的那样,你的语法是错误的,但无论如何我认为将文件限制设置为无限制是不错的主意.

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

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

  1. SYSCALL_DEFINE2(setrlimit,unsigned int,resource,struct rlimit __user *,rlim)
  2. {
  3. struct rlimit new_rlim,*old_rlim;
  4. int retval;
  5.  
  6. if (resource >= RLIM_NLIMITS)
  7. return -EINVAL;
  8. if (copy_from_user(&new_rlim,rlim,sizeof(*rlim)))
  9. return -EFAULT;
  10. if (new_rlim.rlim_cur > new_rlim.rlim_max)
  11. return -EINVAL;
  12. old_rlim = current->signal->rlim + resource;
  13. if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
  14. !capable(CAP_SYS_RESOURCE))
  15. return -EPERM;
  16. if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
  17. return -EPERM;

来自man proc

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

来自./fs/file.c:

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

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

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

/etc/pam.d/su中:

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

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

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

猜你在找的CentOS相关文章