What are the limits types in Ubuntu
Limits in an Ubuntu system are of two types:
- Soft limit: This type of limit indicates the current value of the session or user.. An Ubuntu user has the option to increase its value to the hard limit.
- Hard Limit: The superuser/root sets the maximum allowable limit for a user or session, known as the hard limit.
Now, we will explain the procedure to increase the open file limits on Ubuntu. So let’s start!
How to increase the open file limits on Ubuntu
First of all, open your Ubuntu terminal by pressing “CTRL+ALT+T”. Now, we will check out the current limits of the resources. For this, we will execute the “unlimit” command.
What is unlimit command in Ubuntu
The “unlimit” is a Linux shell command utilized to set, view, or limit the current user’s resources. It also extracts information about how many open file descriptors each process has. Many Ubuntu users execute this command to limit the resources which are in the use of a process.
How to check current limits in Ubuntu
To view the current limits set, add the “-a” option in the “unlimit” command:
Execution of the above-given command will show you the following output:
How to check the soft and hard open file limits in Ubuntu
To view the current soft limit, execute the unlimit command with the “-Sn” option:
From the below-given output, you can see that “1024” is the soft limits of the open files in our Ubuntu system:
The “-Hn” option is added to the “unlimit” command for retrieving the hard limit of the open files:
How to increase the open file limits for the current session in Ubuntu
As mentioned earlier, you can utilize the “unlimit” command for setting the current session limits. If you want to increase the open file limits for your current Ubuntu session, choose a value between the soft and hard limits and add that specific numerical value with the “-n” option. Adding the “-n” option to the “unlimit” command lets you increase the open file limits:
How to increase per-user open file limits in Ubuntu
You can also increase the open file limits for a specific user. To do so, open the limits configuration file “/etc/security/limits.conf” in the “nano” editor:
In the “nano” editor, the limit configuration file will look like this:
Now, add the following content in the “/etc/security/limits.conf” file:
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
linuxhint soft nproc 100000
linuxhint hard nproc 100000
linuxhint soft nofile 100000
linuxhint hard nofile 100000
Here:
- “*” denotes the rest of the system users excluding “linuxhint”
- “linuxhint” is our domain
- “soft” or “hard” is the limit type
- “nofile” item is utilized for limiting the number of the file descriptor
- “nproc” item defines the maximum user processes limit
- “100000” or “65535” are the limit values
Press “CTRL+O” and save the changes we made in the “/etc/security/limits.conf”:
In the next step, we will restrict the number of system resources a user can get in a single session by enabling the pam_limits. For this, you have to edit the “/etc/pam.d/common-session” file in your “nano” editor:
Now, add this line to enable the pam_limits for the current session:
Press “CTRL+O” to save the added content of “ /etc/pam.d/common-session” file:
How to increase system-wide open file limits in Ubuntu
Ubuntu also provides you the option to increase system-wide open file limits. For this purpose, we will edit the “/etc/sysctl.conf” file:
You can set the maximum number of file handles that the Linux kernel will allocate by using the “fs.file-max” parameter. Now, add the below-given line in the “sysctl.conf” file:
Setting the value “2097152” for “fs.file-max” parameter will set this value as maximum number of file handles:
Again, press “CTRL+O” to save the “sysctl.conf” file:
The “sysctl” command with the “-p” option will load the kernel settings from the “sysctl.conf” file. For applying the changes we have made, execute the below-given “sysctl” command in your terminal:
The execution of the above-given command will increase the maximum number of open files across the entire system:
Conclusion
In Ubuntu, many applications, such as the Apache web server or the Oracle databases, require a higher open file limit, resulting in an excessive number of open files, file descriptors, etc. If the number of open files exceeds the default limit, file opening difficulties and access control issues may arise. This article showed you how you can increase the open file limits in your Ubuntu system. Moreover, you have also seen how to check and increase the system-wide and per-user limits of opened files.