Atlantic.Net Blog

How to Change Open File Limit in Linux

Hitesh Jethva
by Atlantic.Net (395 posts) under Tutorials, VPS Hosting
0 Comments

If you are a Linux user and work with many files at a time, then you may often face the error “Too many open files” on Linux. This is because you have reached the maximum open file limit set by Linux operating system. In this case, you can use the ulimit command to change the default limit set by the operating system.

The max open file limit is very useful to prevent your system from sudden crashes. There are two types of open file limits in Linux.

  • Hard Limit: This limit can only be modified by the root user.
  • Soft Limit: This limit can be modified by any normal user. It indicates the current value of the session or user.

In this post, we will show you how to change the open file limit on Linux.

Prerequisites

  • A server running Linux on the Atlantic.Net Cloud Platform
  • A root password configured on your server

Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing any Linux operating system with at least 1GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Check Open File Limits in Linux

To check the number of files that a user can have opened per login session, run the following command:

cat /proc/sys/fs/file-max

You will get the following output:

752300

The above result may be different based on the operating system.

To check the hard limit, run the following command:

ulimit -Hn

You will get the following output:

4096

To check the soft limit, run the following command:

ulimit -Sn

You will get the following output:

1024

To check all limits set by the operating system, run the following command:

ulimit -a

You will get the following output:

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 29405
max locked memory       (kbytes, -l) 65536
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 29405
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Change Open File Limits in Linux Temporarily

In this section, we will show you how to change the open file limits temporarily.

To set the hard limit to 10000 temporarily, run the following command:

ulimit -Hn 10000

To set the soft limit to 10000 temporary, run the following command:

ulimit -Sn 10000

The above limits remain modified temporarily till the current session.

Change Open File Limits in Linux Permanently

You can edit the /etc/security/limits.conf file to set the open file limits permanently.

Edit the /etc/security/limits.conf file as shown below:

nano /etc/security/limits.conf

Change the hard limits to 10000 for all users, add the following line:

* hard nofile 10000

Change the soft limits to 10000 for all users, add the following line:

* soft nofile 10000

If you want to set the limit only for a specific user, add the following line:

user1 hard nofile 8000

Save and close the fil,e then log out and log back again to apply the changes.

You can now check the new limits using the following command:

ulimit

Conclusion

In this guide, we explained how to see and set the open file limits on Linux. If you are running the Apache webserver or Oracle database server then you may require a higher open file limit. In this case, you can increase the open file limit to prevent your application from crashing. Try it on VPS hosting from Atlantic.Net!

Get A Free To Use Cloud VPS

Free Tier Includes:
G3.2GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

How to Install Apache Solr on Oracle Linux 8
How to Install Apache Cassandra on Oracle Linux 8
How to Install Yarn NPM Package Manager on Oracle Linux 8
How to Install Apache Spark on Oracle Linux 8
How to Install Docker and Docker Compose on Oracle Linux 8

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2008 Lookout Dr,

Dallas, Texas 75044

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources