How to Increase Open Files Limit in Ubuntu?

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

In Linux, there are two types of limits

(A) Hard limit: The maximum limit allowed to a user that the superuser/ root can set.

(B) Soft limit: The current limit allowed to a user that the user can increase 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 commands to check the Hard and Soft limits – 

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 command given below – 

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 complete the limit modification, enable the pam_limits using the command given below – 

sudo nano /etc/pam.d/common-session

4. Then add the following line - 

session required pam_limits.so

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 the system-wide limit by editing the sysctl configuration file

# nano /etc/sysctl.conf

2. Now, add this line – 

# fs.file-max = 3000000

3. Run the below command to save the changes – 

# sysctl -p


Was this answer helpful?

« Back

chat