我在/etc/security/limits.conf(CentOS 6.2) 中设置了以下值(-1 将被解析为无限制,我想)
root nofile soft -1
root nofile hard -1
我现在无法使用 root 用户登录。类似于这里描述的问题。将值设置回将解决问题。
谁能帮忙解释一下?
更新:
谢谢你们。我记错了我的设置。这些值应该是
root soft nofile -1
root hard nofile -1
Run Code Online (Sandbox Code Playgroud)
正如@Michael Hampton 告诉你的,你的语法是错误的,但无论如何我认为将文件限制设置为无限制不是个好主意
您可以阅读这篇文章以获取更多信息/sf/ask/84904781/
我下载了内核版本 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;
Run Code Online (Sandbox Code Playgroud)
来自 人进程
The kernel constant NR_OPEN imposes an upper limit on the value that may be placed in
file-max.
Run Code Online (Sandbox Code Playgroud)
来自./fs/file.c:
./fs/file.c:30:int sysctl_nr_open __read_mostly = 1024*1024;
echo $((1024*1024))
1048576
Run Code Online (Sandbox Code Playgroud)
为什么你需要比 nr_open 更多的文件?
我使用您的 limit.conf 设置进行了测试:
/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
Run Code Online (Sandbox Code Playgroud)
现在我将使用 su 命令切换到 root 用户:
root@ubuntu:~# strace -e setrlimit su - root
setrlimit(RLIMIT_NOFILE, {rlim_cur=RLIM64_INFINITY, rlim_max=RLIM64_INFINITY}) = -1 EPERM (Operationnot permitted)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13933 次 |
| 最近记录: |