Set ulimit parameters on ubuntu

By default the number of open files  pro user in Ubuntu 8.04   is 1024. In my case this number was  too small so I have to increase it.This is done with the  ulimit command:

$ulimit -a   # see all the kernel parameters
$ulimit -n   #see the number of open files
$ulimit -n 9000  #  set the number open files to 9000

The problem with this way is that the ulimit parameter is only set currently  for this command terminal and user.If you open a new tab and type again ulimit -a you will see that the number of open files is 1024.This means that after a reboot you’ll need to set the parameter again.

First, in order to set this options automatically  you have to edit the etc/security/limits.conf file.

$sudo gedit /etc/security/limits.conf    #open the file in gedit

The # means that this part is commented.The wildcard * means  for all users.We need to set the nofile option meaning maximum number of open files.If you want to change the number of files of user, you should add this line in the limits.conf:

user  soft  nofile 9000

user  hard  nofile 65000

If  you want to set the nofile only for superuser you just write root instead of user.

root soft  nofile 9000

root hard  nofile 65000

Second you have to add a line in the /etc/pam.d/common-session file:

$ sudo gedit /etc/pam.d/common-session #open the file in gedit

Then add the line:

session required

Now after rebooting you can see in the terminal with ulimit -a the change.

The option with wildcard *didn’t work for me , because I used root accout to run my programms and wildcard option doesn’t affect the superuser.

Remark: Using the same steps you should be able to set and change other parameters ( core file size, max user processes, stack size ….) from the ulimit options.


13 thoughts on “Set ulimit parameters on ubuntu

  1. Pingback: set maximum number

  2. Pingback: MongoDB “Too Many Open Files”? Raise the limit « Andrew Rollins

  3. Pingback:

  4. Pingback: ulimit values not being remembered (Ubuntu 11.10) - The UNIX and Linux Forums

  5. Pingback: setting memlock with limits.conf

  6. Mahesh Kumar PatilNo Gravatar

    How to change the value of ulimit without using root account?
    ( i.e using a normal user account)

  7. Pingback: NodeJS setup tips for DevOps | Knowledge Base

  8. Jonathan CraneNo Gravatar

    This process no longer works as far as I can tell. I see the article is about 5 years old. I’m using Ubuntu 12.04 LTS Now.

  9. Pingback: ???? » operational_redis

  10. Pingback: Too many open files - how to find the culprit

  11. JasonNo Gravatar

    I’m using Ubuntu 15.04. The wildcard doesn’t do anything for me; only referencing by username does.

Leave a Reply

Your email address will not be published. Required fields are marked *