Maximum number of opened files on Ubuntu
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:
limits.conf
Step 1: Edit Update the system-wide limit in /etc/security/limits.d/90-nproc.conf
(or similar) by adding:
* soft nofile 65535
* hard nofile 65535
/etc/systemd
Configuration
Step 2: Update 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.
.