Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Linux Commands»How to Increase Open Files Limit in Ubuntu & Debian

    How to Increase Open Files Limit in Ubuntu & Debian

    By RahulOctober 8, 20192 Mins ReadUpdated:October 18, 2019

    Some times we faced issues like “Too many open files” on a Linux system. It means our server has hit the max open file limit. This happens due to resource limits set by the system for any user or session. For example, the max size of files created, the maximum size that may be locked into memory, maximum CPU time used, the maximum number of processes allowed, the maximum size of virtual memory available.

    Advertisement

    Basically there are two types of limits:

    • A hard limit is the maximum allowed limit to a user or session, which is set by the superuser/root.
    • A soft limit is the current effective value for the user or session. Which can increase by the user up to the hard limit.

    Check for Current Limits

    The ulimit command provides control over resources available to each user via a shell. You can use below command to
    to get the current settings.

    ulimit -a
    

    To view the current hard limit or soft limit use the following command.

    ulimit -Sn       # Check soft limit
    ulimit -Hn       # Check hard limit
    

    Increase Limit for Current Session

    Most operating systems can change the open-files limit for the current shell session using the ulimit -n command:

    ulimit -n 200000
    

    Increase per-user Limit

    You can define per-user open file limit on a Debian based Linux system. To set per-user limit, edit /etc/security/limits.conf file in a text editor.

    sudo vim /etc/security/limits.conf
    

    Add the following values in file:

    * 	 soft     nproc          65535
    * 	 hard     nproc          65535
    * 	 soft     nofile         65535
    * 	 hard     nofile         65535
    jack 	 soft     nproc          200000
    jack 	 hard     nproc          200000
    jack 	 soft     nofile         200000
    jack 	 hard     nofile         200000
    

    Here we specifying separate limits which are 200000 for the user “jack” and 65535 will be applied for the rest of the users. You can change these values per your requirements.

    After that enable the pam_limits as followings:

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

    Add the following line:

    session required pam_limits.so
    

    Increase system-wide Limit

    You can also set the limits system-wide by editing the sysctl configuration file. Edit sysctl.conf file:

    vim /etc/sysctl.conf 
    

    Add the following line:

    fs.file-max = 2097152
    

    Then run the following command to apply the above changes:

    sysctl -p
    

    The above changes will increase the maximum number of files that can remain open system-wide. The specific user limit can’t be higher than the system-wide limit.

    linux command ulimit
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Sed Command to Delete Lines in a File

    Sed Command to Delete Lines in a File

    Sort Command in Linux with Practical Examples

    15 Practical Examples of Sed Command

    Sed Command in Linux with 15 Practical Examples

    View 3 Comments

    3 Comments

    1. shmuel on November 23, 2020 7:11 pm

      Thanks a lot.
      Saved me here 🙂

      Reply
    2. Paul Benedict on November 20, 2020 4:00 pm

      Hello,

      This ALMOST worked for me, using Ubuntu.

      I found that I also had to edit this file: /etc/systemd/system.conf

      And add the line:

      DefaultLimitNOFILE=65536

      Thanks!

      Reply
      • sbaumg2s on September 2, 2022 12:07 pm

        On Ubuntu 20 DefaultLimitNOFILE via /etc/systemd/system.conf doesnt work. And, where can i find all options that can be set for system-wide limits? And stay set after system restart…

        Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Error: EACCES: permission denied, scandir (Resolved)
    • How To Install Python 3.11 on Ubuntu 22.04 / 20.04
    • How to Install Python 3.11 on Amazon Linux 2
    • An Introduction to the “./configure” Command: Compiling Source Code in Linux
    • How to Install PHP 8.x on Pop!_OS
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.