Professional Documents
Culture Documents
Error "Too Many Files Open"
Error "Too Many Files Open"
If you are encountering Error messages during login with “Too many open files” and the session gets
terminated automatically, it is because the open file limit for a user or system exceeds the default
setting and you may wish to change it
@ System Levels
To see the settings for maximum open files,
# cat /proc/sys/fs/file-max
55494980
This value means that the maximum number of files all processes running on the system can open.
By default this number will automatically vary according to the amount of RAM in the system. As a
rough guideline it will be about 100,000 files per GB of RAM.
# vim /etc/sysctl.conf
fs.file-max = 80000000
# sysctl -p
@ User Level
To see the setting for maximum open files for a user
# su - user1
$ ulimit -n
1024
$ vim /etc/security/limits.conf
* - nofile 2048
This set the maximum open files for ALL users to 2048 files. These settings will require a reboot to
activate.
In this short tutorial we will show you how to check your current limit of open files and
files descriptions, but to do so, you will need to have root access to your system.
First, Lets see how we can find out the maximum number of opened file descriptors on
your Linux system.
# cat /proc/sys/fs/file-max
818354
The number you will see, shows the number of files that a user can have opened per
login session. The result might be different depending on your system.
For example on a CentOS server of mine, the limit was set to 818354, while
on Ubuntu server that I run at home the default limit was set to 176772.
If you want to see the hard and soft limits, you can use the following commands:
4096
1024
To see the hard and soft values for different users, you can simply switch user
with “su” to the user which limits you want to check.
For example:
# su marin
$ ulimit -Sn
1024
$ ulimit -Hn
4096
You can increase the limit of opened files in Linux by editing the kernel
directive fs.file-max. For that purpose, you can use the sysctl utility.
For example, to increase open file limit to 500000, you can use the following command
as root:
# sysctl -w fs.file-max=500000
You can check the current value for opened files with the following command:
$ cat /proc/sys/fs/file-max
With the above command the changes you have made will only remain active until the
next reboot. If you wish to apply them permanently, you will have to edit the following
file:
# vi /etc/sysctl.conf
fs.file-max=500000
Of course, you can change the number per your needs. To verify the changes again
use:
# cat /proc/sys/fs/file-max
Users will need to logout and login again for the changes to take effect. If you want to
apply the limit immediately, you can use the following command:
# sysctl -p
Set User Level Open File limits in Linux
The above examples, showed how to set global limits, but you may want to apply limits
per user basis. For that purpose, as user root, you will need to edit the following file:
# vi /etc/security/limits.conf
If you are a Linux administrator, I suggest you that you become very familiar with that
file and what you can do to it. Read all of the comments in it as it provides great
flexibility in terms of managing system resources by limiting users/groups on different
levels.
The lines that you should add take the following parameters:
Final thoughts
This brief article showed you a basic example of how you can check and configure
global and user level limits for maximum number of opened files.
While we just scratched the surface, I highly encourage you to have a more detailed
look and read regarding /etc/sysctl.conf and /etc/security/limits.conf and learn how
to use them. They will be of great help for you one day.