Hello folks, In this article, We will discuss how to change the open file limit in Linux.
What Is The Open File Limit?
The open file limit is the maximum number of files a user can open in the current active session. Mostly, sysadmins, developers, or users working with MySQL or other database management systems (DBMS). For Example, In MySQL, The default open file limit is 1024, but it automatically sets its limit to the system’s open file limit. There are two types of open file limits:
- Hard limit: It is the maximum value a soft limit can be altered. It can only be changed by the root user.
- Soft limit: It is the open file limit that can be altered by any user or process. It is changed temporarily at each active session.
Check Open File Limit in Linux
We can check the hard limit and soft limit using the ulimit command. To check the hard limit, We will use the
-H parameter for the hard limit. Execute the following command:
To check the soft file limit, We will use the
-S parameter for soft limit. Execute the following command:
To check the maximum number of open files that can be opened in the current active session, Execute the following command:
Here, The maximum open file limit is set to 100000. The hard limit is 1048576 and soft limit is 1024. Let’s see how to change these limits.
Change Open File Limit in Linux
To change the system-wide maximum open file limit, Execute the following command and set the value as required:
sysctl -w fs.file-max=500000
To change the hard limit, Execute the following command:
ulimit -Hn 10000
To change the soft limit, Execute the following command:
ulimit -Sn 5000
However, The hard limit and soft limit values changed using the ulimit command remain temporary till the active session. To change these values permanently can be done as follows:
Execute the following command in a terminal window to open the /etc/security/limits.conf file:
sudo vi /etc/security/limits.conf
Here, You can change the values for a particular user or all users by adding the following lines:
* hard nofile 10000
* soft nofile 5000
* means all users, To set the limits for a particular user, Replace the
* by the username. The
nofile means number of files that can be opened in a particular session. To save the file, press the Esc key followed by
:wq and press Enter. So, The hard limit and soft limit have been set permanently.
So, We learned how to change the open file limit temporarily and permanently. Whenever you open the system files, It requires root permission, Use the sudo command and enter the password when prompted as we did while opening the /etc/security/limits.conf.