使用sudo ulimit时找不到命令

时间:2021-08-25 02:39:47

I was using ubuntu 12.04 ,on which I run ulimit -n ,it is showing 1024, I want to increase my open file limit from 1024 to 65535,so I tried the following command:

我在使用ubuntu 12.04,在上面运行ulimit -n,它显示1024,我想把打开的文件限制从1024增加到65535,所以我尝试了以下命令:

sudo ulimit -n 65535

but i get the following error:

但是我得到了以下错误:

sudo: ulimit: command not found

How to increase the file limit from 1024 to 65535? Any help will be appreciated.

如何将文件限制从1024增加到65535?如有任何帮助,我们将不胜感激。

2 个解决方案

#1


95  

ulimit is a shell builtin like cd, not a separate program. sudo looks for a binary to run, but there is no ulimit binary, which is why you get the error message. You need to run it in a shell.

ulimit是一个shell内置的cd,而不是一个单独的程序。sudo寻找要运行的二进制文件,但是没有ulimit二进制文件,这就是为什么您会得到错误消息。你需要在shell中运行它。

However, while you do need to be root to raise the limit to 65535, you probably don’t want to run your program as root. So after you raise the limit you should switch back to the current user.

然而,虽然您确实需要root用户才能将限制提高到65535,但是您可能不希望以root用户身份运行程序。因此,当你提高限制后,你应该切换回当前用户。

To do this, run:

要做到这一点,运行:

sudo sh -c "ulimit -n 65535 && exec su $LOGNAME"

and you will get a new shell, without root privileges, but with the raised limit. The exec causes the new shell to replace the process with sudo privileges, so after you exit that shell, you won’t accidentally end up as root again.

您将得到一个新的shell,没有root特权,但是有增加的限制。exec使新shell用sudo特权替换进程,因此在您退出该shell之后,您不会意外地再次以root身份结束。

#2


0  

I've had to deal with issues like this in the past. Since there is no setuid mechanism for shell scripts (because it's insecure), I've found writing a simple C wrapper with a setuid is suffice and then using a system call to modify the ulimits of the running process before dropping privileges and executing your shell script.

过去我不得不处理这样的问题。由于shell脚本没有setuid机制(因为它没有安全性),所以我发现编写一个带有setuid的简单的C包装器就足够了,然后在删除特权和执行shell脚本之前,使用一个系统调用来修改运行过程的u限制。

#1


95  

ulimit is a shell builtin like cd, not a separate program. sudo looks for a binary to run, but there is no ulimit binary, which is why you get the error message. You need to run it in a shell.

ulimit是一个shell内置的cd,而不是一个单独的程序。sudo寻找要运行的二进制文件,但是没有ulimit二进制文件,这就是为什么您会得到错误消息。你需要在shell中运行它。

However, while you do need to be root to raise the limit to 65535, you probably don’t want to run your program as root. So after you raise the limit you should switch back to the current user.

然而,虽然您确实需要root用户才能将限制提高到65535,但是您可能不希望以root用户身份运行程序。因此,当你提高限制后,你应该切换回当前用户。

To do this, run:

要做到这一点,运行:

sudo sh -c "ulimit -n 65535 && exec su $LOGNAME"

and you will get a new shell, without root privileges, but with the raised limit. The exec causes the new shell to replace the process with sudo privileges, so after you exit that shell, you won’t accidentally end up as root again.

您将得到一个新的shell,没有root特权,但是有增加的限制。exec使新shell用sudo特权替换进程,因此在您退出该shell之后,您不会意外地再次以root身份结束。

#2


0  

I've had to deal with issues like this in the past. Since there is no setuid mechanism for shell scripts (because it's insecure), I've found writing a simple C wrapper with a setuid is suffice and then using a system call to modify the ulimits of the running process before dropping privileges and executing your shell script.

过去我不得不处理这样的问题。由于shell脚本没有setuid机制(因为它没有安全性),所以我发现编写一个带有setuid的简单的C包装器就足够了,然后在删除特权和执行shell脚本之前,使用一个系统调用来修改运行过程的u限制。