Skip to content
Snippets Groups Projects

Maximum number of opened files on Ubuntu

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by František Řezníček

    To increase the maximum number of opened files on Ubuntu, follow these steps:

    1. Check the Current Limit

    You can check the current limit for the maximum number of open files using:

    ulimit -n

    2. Temporary Change (Session Only)

    To temporarily change the limit for the current session:

    ulimit -n <new_limit>

    For example:

    ulimit -n 65535

    This change lasts only for the duration of the shell session.


    3. Permanent Change for a User

    To make the change permanent for a specific user:

    Step 1: Edit Limits Configuration

    Edit the limits configuration file:

    sudo nano /etc/security/limits.conf

    Add or modify the following lines at the end of the file:

    <username> soft nofile 65535
    <username> hard nofile 65535

    Replace <username> with the actual username.

    Step 2: Apply Limits to All Sessions

    Ensure PAM modules apply the limits. Check or add the following line in /etc/pam.d/common-session and /etc/pam.d/common-session-noninteractive:

    session required pam_limits.so

    4. Change System-Wide Limit

    To increase the limit system-wide:

    Step 1: Edit limits.conf

    Update the system-wide limit in /etc/security/limits.d/90-nproc.conf (or similar) by adding:

    * soft nofile 65535
    * hard nofile 65535

    Step 2: Update /etc/systemd Configuration

    For services managed by systemd, update its configuration. For example, edit the default limits in:

    sudo nano /etc/systemd/system.conf
    sudo nano /etc/systemd/user.conf

    Add or modify these lines:

    DefaultLimitNOFILE=65535

    Step 3: Restart System Services

    Reload systemd to apply changes:

    sudo systemctl daemon-reexec

    5. Verify Changes

    Restart your system or session and verify the new limits using:

    ulimit -n

    Or check limits for systemd services with:

    cat /proc/$(pgrep -o <service_name>)/limits

    Replace <service_name> with the name of the service you're checking.

    Edited
    snippetfile1.txt 1 B
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment