How to Increase Open Files Limit in Ubuntu?

You may receive a message on Linux system like "Too many open files". This mean server has reached the limit of max open files.

In Linux, there are two types of limits

(A) Hard limit: maximum limit allowed to a user which could be set by the superuser/root.

(B) Soft limit: Current limit allowed to a user which can be increased by the user up to the hard limit.

Check for Current Limits :

You can check the currently allowed limit to a user with the ulimit command. Following are the command to check the Hard and Soft limit.

ulimit -Sn   # Check soft limit
ulimit -Hn # Check hard limit

Increase limit for Current Session :

If you want to increase the limit of any session, you can use the below command.

ulimit -n 250000


Increase per-user Limit :

  1. We can provide a per-user limit for an open file. Edit the limits.conf using the below command.

    sudo nano /etc/security/limits.conf
  2. modify the value for your user as per your requirement and save the files.

  3. Once you are done with limit modification, enable the pam_limits using the below command.

    sudo nano /etc/pam.d/common-session
  4. Add the following line:

    session required

Increase system-wide Limit :

Increasing the system-wide limit will allow you to open files system-wide. Please note that a specific user limit can’t be higher than the system-wide limit.

  1. We can also increase system-wide Limit. To do this, edit sysctl configuration file.

    # nano /etc/sysctl.conf 
  2. Now, add the below line

    # fs.file-max = 3000000 
  3. Run below command to save the changes.

    # sysctl -p

Related Articles

How to redirect http to https using .htaccess?

If you have installed SSL Certificate on your website and want to redirect your website traffic...

How to Install LEMP Stack (Nginx, MariaDB, PHP7.2) on Ubuntu 18.04 LTS?

Nginx, MariaDB and PHP7.2 are called (LEMP). Following are the steps to install LEMP on Ubuntu...

How to Hide Your NGINX Server Version.

Sometimes hackers target your server with a technic called banner grabbing. Usually, banner...

How to upgrade Debian 7 (Wheezy) to 10 (Buster) version?

It is always recommended to upgrade the version to prevent any security vulnerability. You can...

How to Compress and Extract Files Using the tar Command on Linux?

It is a very easy step to create archive files with .tar.gz or .tgz files. It is also called...

  • 0 Users Found This Useful

Was this answer helpful?